I have two layers in QGIS (basically 2 maps).. I can see both of them separately when I click on each layer and I press the button "zoom to layer(s)".
In the real world, one of the two maps/layers surrounds completely the second map/layer. However, in QGIS, they look very distant from each other...
Why can't I see them together and overlapping (since they are supposed to), and instead, they look very distant from each other ?
Note 1: One map/layer has these features:
Storage
Memory storage
Encoding
Geometry
Line (LineString)
Extent
401473.9136441830196418,5226800.8761361399665475 : 429895.4095911540207453,5249607.0315812798216939
Feature count
4,945
Coordinate Reference System (CRS)
Name
EPSG:4326 - WGS 84
while the other map/layer has these features:
Storage
ESRI Shapefile
Encoding
UTF-8
Geometry
Polygon (MultiPolygon)
Extent
5.9559019550819725,45.8179584859823805 : 10.4921712689682476,47.8084543074145500
Feature count
4,126
Coordinate Reference System (CRS)
Name
EPSG:4326 - WGS 84
Note 2: The second layer was initially in EPSG:2056 - CH1903+ / LV95, and I then converted it to EPSG:4326 - WGS 84 to "match" the first map/layer.
A few more steps to reproduce my problem:
- My small map/layer comes from a list of edges in UTM x- and y- coordinates (WGS84), and I write down here an excerpt of that map for reproducibility (each row is a line/edge in QGIS,
x_start,y_start,x_end,y_end):
>> my_qgis_file.csv
ans =
5244268.06237086 420170.471022784 5244166.4951274 420089.149994671
5244268.06237086 420170.471022784 5244282.8390319 420075.983838177
5244268.06237086 420170.471022784 5244203.40710369 420283.463682657
5239505.2647868 426336.470241881 5239519.18282658 426290.072906479
5239505.2647868 426336.470241881 5239599.74770874 426390.179540636
- I uploaded this small map on QGIS by using this python code in the python console
# specify your csv-file
csvFile = "/Users/.../my_qgis_file.csv"
create an empty memory layer for polylines
layer = QgsVectorLayer('LineString?crs=EPSG:4326', 'Connected', 'memory')
prov = layer.dataProvider()
add layer to the map
QgsMapLayerRegistry.instance().addMapLayer(layer)
QgsProject.instance().addMapLayer(layer)
open the csv-file for reading and skip the header row
lineStrings = open(csvFile, "rU")
next(lineStrings)
start editing
layer.startEditing()
loop over the lines, split them into 4 coordinates, build points from pairs of
them, and connect the pair of points
feats = []
for line in lineStrings:
lineStringAsList = line.split(",")
from_node = QgsPoint(float(lineStringAsList[1]),float(lineStringAsList[0]))
to_node = QgsPoint(float(lineStringAsList[3]),float(lineStringAsList[2]))
feat = QgsFeature()
feat.setGeometry(QgsGeometry.fromPolyline([from_node, to_node]))
feats.append(feat)
finally add all created features and save edits
prov.addFeatures(feats)
layer.addFeatures(feats)
layer.updateExtents()
layer.commitChanges()
I downloaded the file
PLZO_PLZ.shp, which would represent my large map/layer, from the folder Shape LV95I tried to reproject
PLZO_PLZ.shpfrom LV95 to WGS84, in order to overlap this large map/layer with the small one. I followed the instructions here, by using "Export --> Save features as...", and by choosing my desired CRS, i.e. WGS84, but still, I have the same issue.
EPSG:4326 - WGS 84...... So...... why are those two maps/layer still so distant from each other..? In reality, the largest map/layer should completely surround the smaller one... Why this discrepancy ? What mistake could I have potentially made ? A small note: the small map/layer was initially in another CRS and I have changed it, to have the same CRS as the large map/layer... – Ommo Jul 07 '22 at 09:52specify your csv-file
csvFile = "/Users/.../my_qgis_file.csv"
create an empty memory layer for polylines
layer = QgsVectorLayer('LineString?crs=EPSG:32632', 'Connected', 'memory')
prov = layer.dataProvider()
– Hans Erren Jul 07 '22 at 15:12EPSG:4326withEPSG:32632the two maps overlap in the right spot! If you write this simple answer in "Answer Your Question", I will accept it! However, I still got some doubt........ should I open a new question or not ? – Ommo Jul 08 '22 at 07:10[P.S.: for reprojection I can use the instructions from this link (https://gis.stackexchange.com/questions/348521/layer-disappears-when-changing-from-crs-in-degrees-to-crs-in-meters-in-qgis), by using "Export --> Save features as...", and by choosing my desired CRS.]
– Ommo Jul 08 '22 at 07:15EPSG:4326withEPSG:32632and I still want to keepEPSG:4326, what should I do to change the projection of the large map/layerPLZO_PLZ.shpthat is inEPSG:2056 - CH1903+ / LV95(which was my initial attempt) ? – Ommo Jul 08 '22 at 07:23