1

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:

  1. 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

  1. 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()

  1. I downloaded the file PLZO_PLZ.shp, which would represent my large map/layer, from the folder Shape LV95

  2. I tried to reproject PLZO_PLZ.shp from 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.

PolyGeo
  • 65,136
  • 29
  • 109
  • 338
Ommo
  • 149
  • 6
  • 1
    Copy one of the layers into another QGIS project. Size your two projects so they appear side by side and zoom each to the layer you want. Alternately you could create a layout in your project, and add two maps to it side by side. Zoom to one layer before adding the first layout map then lock the layers. Zoom to the second layer before creating the second layout map. You could lock that too. – John Jul 06 '22 at 17:07
  • 4
    Not many objects located at 5.2 million degrees north. If you use a correct coordinate reference, you might have an easier time. – Vince Jul 06 '22 at 17:31
  • Thanks a lot to @johns, probably I did not fully understand your comment, but what I was looking for was a button or something where QGIS shows both maps/layers, even though distant from each other in a single window, something like "zoom to layer", but including both layers... a sort of overall view which crops the unnecessary "white space" around both layers and just focuses/zooms on my two. layers.... :-) – Ommo Jul 07 '22 at 09:48
  • Many thanks @Vince! As shown in my question, I have the same CRS for both layers, i.e. 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:52
  • 3
    The metadata might assert that it's 4326, but that data is clearly wrong. If you changed it, you corrupted the dataset, and you should unchange it (or restore from backup/original). This is the most common question on this site (2-3 times per week) -- changing the metadata does not change the geometry; you need to reproject the dataset, not ask it to lie to you about its projection. – Vince Jul 07 '22 at 11:38
  • 3
    Your first map coordinate system states that the unit is in degrees, yet the map extent shows meters, so the coordinate system is wrong, change it back to the original swiss grid which has meter units. – Hans Erren Jul 07 '22 at 11:45
  • 1
    https://gis.stackexchange.com/questions/348521/layer-disappears-when-changing-from-crs-in-degrees-to-crs-in-meters-in-qgis – Vince Jul 07 '22 at 11:53
  • Thanks @Vince! Please see my EDITED question for further details... – Ommo Jul 07 '22 at 14:04
  • Many thanks @HansErren! Please see my EDITED question for further details... – Ommo Jul 07 '22 at 14:04
  • I did not solve my issue yet..... Any other suggestion, by considering my EDITED question ? :-) – Ommo Jul 07 '22 at 15:02
  • 1
    Change your python code to use the utm coordinates of UTM zone 32

    specify 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:12
  • Thanks a lot @HansErren!!! Just replacing EPSG:4326 with EPSG:32632 the 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
  • (FIRST DOUBT - PART 1) Now, my small layer has the following features. (1.a) Extent: [401473.9136441830196418, 5226800.8761361399665475 : 429895.4095911540207453, 5249607.0315812798216939], (1.b) Feature count: [4,945], (1.c) Coordinate Reference System (CRS): [EPSG:32632 - WGS 84 / UTM zone 32N], (1.d) Units: [meters], (1.e) Method: [Universal Transverse Mercator (UTM)], etc... – Ommo Jul 08 '22 at 07:12
  • (FIRST DOUBT - PART 2) Instead, my large layer has the following features: (2.a) Extent: [2485410.2149999998509884, 1075268.1359999999403954 : 2833857.7239999994635582, 1295933.6979999989271164], (2.b) Feature count: [4,026], (2.c) Coordinate Reference System (CRS): [EPSG:2056 - CH1903+ / LV95], (2.d) Units:[meters], (2.e) Method: [Swiss. Obl. Mercator], etc... – Ommo Jul 08 '22 at 07:12
  • (FIRST DOUBT - QUESTION) If the Coordinate Reference System (CRS) for the small map/layer is [EPSG:32632 - WGS 84 / UTM zone 32N] and for the large map/layer is [EPSG:2056 - CH1903+ / LV95], should I now reproject one of these two in order to be both in the same Coordinate Reference System (CRS) ?

    [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:15
  • (SECOND DOUBT - QUESTION) In case, in the python code, I do not want to replace EPSG:4326 with EPSG:32632 and I still want to keep EPSG:4326, what should I do to change the projection of the large map/layer PLZO_PLZ.shp that is in EPSG:2056 - CH1903+ / LV95 (which was my initial attempt) ? – Ommo Jul 08 '22 at 07:23

1 Answers1

2

Change your python code so it uses the UTM meter coordinate system of EPSG:32632 UTM zone 32, instead of degrees EPSG:4326

# specify 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()

Note: Your data in my_qgis_file.csv has metric units, so you have to pass to a GIS package the corresponding coordinate system (CRS). Your code ASSIGNS a coordinate system to the data it does not REPROJECT the data. QGIS can work with mixed coordinate systems, there is no need to create a reprojected dataset.

There is a difference between the layer CRS (the CRS of the data) and the QGIS project CRS (the CRS of the view). You are free to choose your project CRS, usually you would use the National standard, so in your case EPSG:2056. UTM is usually used for international projects. EPSG:4326 uses degree as unit and should not be used on a map that is used to depict metric distances and areas.

Hans Erren
  • 1,170
  • 5
  • 17