1

I have a vector layer of rectangles in QGIS 3 that I export as a .GeoJSON- file.

I want to change those geometries to new polygons with certain dimensions, for which I use Python. I then save those new geometries as first a pandas dataframe and then a .GeoJSON- file again, which I then want to open again in QGIS 3.

The problem is that the new layer is opened, but there is nothing to be seen on screen. The problem, I think, is in the formatting of the python-generated .geojson file. Here is a sample of one feature (the file contains about 2300 features):

{  
  "type": "FeatureCollection",  
  "name": "Test",
  "crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:OGC:1.3:CRS84" }},
  "features": [
    {
      "type": "Feature",
      "properties": {
        "ID": 0
      },
      "geometry": {
        "type": "MultiPolygon",
        "coordinates": [
          [
            6.334986208752899,
            50.62066998876687
          ],
          [
            6.334986208752899,
            50.59616998876687
          ],
          [
            6.2952362087528995,
            50.62066998876687
          ],
          [
            6.2952362087528995,
            50.59616998876687
          ]
        ]
      }
    },

After which the next feature comes, until the remaining blocks are closed with one ] and one }.

I am not too familiar with these types of formatting, is there something wrong with this for a vector layer of rectangles?

7
  • 1
    That looks standard for a geojson. When you say it doesn't appear in QGIS, does it at least show features in the attribute table? If so, what happens if you right click on a feature and select Zoom to feature, do you see anything on the map then? And then if so does it appear where it should (try loading a basemap to check). My first thought was that somehow your python editing didn't recognise the correct CRS or something. Keep in mind that GeoJSON uses CRS84 which is EPSG:4326 but with Long/Lat instead of Lat/Long.
    – she_weeds
    May 8 '20 at 10:44
  • Okay I think the problem is indeed something CRS related, I am working in the Netherlands so the use of Long/Lat is correct there. I can zoom to layer, but then still nothing is visible, and also the coordinates don't correspond with what I'd expect from EPSG:4326. Something else I don't understand, and may be the problem, is that this layer works just fine, shows the correct coordinates, but is in EPSG:3035 and when I change it to EPSG:4326 it also vanishes, again also with zoom to layer. Is this is a known issue?
    – fjdrensen
    May 8 '20 at 11:20
  • What do you mean the coordinates do not correspond with what you expect? Are they in the wrong location altogether or just slightly off? I'm not sure I understand what you mean by how nothing is visible but the same layer "works fine". Anyway, I just suspect something went wrong when you used geopandas to export to geojson. Maybe you were using an old version of gdal that did not correctly interpret CRS84. Would it help to try the Swap X/Y coordinates processing tool and see if that gets you any closer? Also try fix geometries tool and saving as another file
    – she_weeds
    May 8 '20 at 12:02
  • There is some discussion about crs84 and gdal here: github.com/OSGeo/gdal/issues/2035 which is connected to issues in Fiona and geopandas if that helps. Perhaps if you can share what steps you took in python to change the geometries someone here can figure out what might've gone wrong.
    – she_weeds
    May 8 '20 at 12:18
  • After some manipulations, the features are in the right place, meaning when I zoom to their layer, I see the part of the basemap I want to see. However, the polygons themselves are still not displayed. I'll look at that discussion. It's interesting though, because I didn't use Geopandas, just pandas. I dumped the data using the python json package. I have tried working with the geojson package, but I ran into issues with installing Fiona.
    – fjdrensen
    May 8 '20 at 12:28
1

The geometry in the GeoJSON is not valid.

 "type": "MultiPolygon",
        "coordinates": [
          [
            6.334986208752899,
            50.62066998876687
          ],
          [
            6.334986208752899,
            50.59616998876687
          ],
          [
            6.2952362087528995,
            50.62066998876687
          ],
          [
            6.2952362087528995,
            50.59616998876687
          ]
        ]

See the specification https://geojson.org/geojson-spec.html

A LinearRing is closed LineString with 4 or more positions. The first and last positions are equivalent (they represent equivalent points). Though a LinearRing is not explicitly represented as a GeoJSON geometry type, it is referred to in the Polygon geometry type definition.

In your data the first and last positions are not equivalent. In addition the multipolygon is not written according to the GeoJSON specifications - count the brackets. Notice also that the points must wind in correct order and self-intersections are not allowed. Here is valid GeoJSON that presents correctly a one-part multipolygon.

{
"type": "FeatureCollection",

"features": [
{ "type": "Feature", "properties": null, "geometry": 
{"type":"MultiPolygon","coordinates":
[[[[6.29523621,50.62066999],
[6.33498621,50.62066999],
[6.33498621,50.59616999],
[6.29523621,50.59616999],
[6.29523621,50.62066999]]]],
"crs":{"type":"name","properties":{"name":"urn:ogc:def:crs:OGC:1.3:CRS84"}}} }
]

}
1
  • Thank you! This works!
    – fjdrensen
    May 8 '20 at 13:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.