0

I'm using Python's GeoJSON package to created a simple LineString, put it in a Feature, and put that in a FeatureCollection I'll call featColl. featColl.errors() returns no errors. Below is the dumped GeoJSON file. When I import it as a vector layer into QGIS, it opens without complaint. but the layer is completely empty, and shows no line segments. Any ideas what I'm missing?

{
 "type": "FeatureCollection",
 "features": [
  {
   "type": "Feature",
   "geometry": {
    "type": "LineString",
    "coordinates": [
     [
      [
       -122.271154,
       37.804348
      ],
      [
       -122.272057,
       37.80295
      ]
     ],
     [
      [
       -122.272057,
       37.80295
      ],
      [
       -122.278011,
       37.805288
      ]
     ],
    ]
   },
   "properties": {}
  }
 ]
}
4
  • Perhaps you made some mistake when copying the GeoJSON into the question. QGIS gives "CRITICAL Invalid Data Source : ...".
    – user30184
    Oct 9, 2021 at 22:09
  • { "type": "FeatureCollection", "features": [ { "type": "Feature", "geometry": { "type": "MultiLineString", "coordinates": [ [ [ -122.271154, 37.804348 ], [ -122.272057, 37.80295 ] ], [ [ -122.272057, 37.80295 ], [ -122.278011, 37.805288 ] ] ] }, "properties": null } ] }
    – user30184
    Oct 9, 2021 at 22:28
  • geojsonlint.com thinks it is invalid as well.
    – geocodezip
    Oct 9, 2021 at 23:42
  • Apologies: cut&paste must have changed my sample somehow because i got different behavior from QGIS and geojsonlint? in any case @user2856 made me aware of an extra set of brackets. thanks al! Oct 10, 2021 at 19:57

1 Answer 1

3

You have 3 levels of nesting in your coordinates which is not right for a simple linestring.

Either make it a MultiLineString

{
  "type": "FeatureCollection", 
  "features": [ 
    {
      "type": "Feature", 
      "geometry": { 
        "type": "MultiLineString", 
        "coordinates": [ 
          [ 
            [ -122.271154, 37.804348 ], 
            [ -122.272057, 37.80295 ] 
          ], 
          [ 
            [ -122.272057, 37.80295 ], 
            [ -122.278011, 37.805288 ] 
          ]  
        ] 
      }, 
      "properties": {} 
    } 
  ] 
} 

Or remove the extra level of nesting

{
  "type": "FeatureCollection",
  "features": [
      {
        "type": "Feature",
        "geometry": {
          "type": "LineString",
          "coordinates": [
            [-122.271154, 37.804348],
            [-122.272057, 37.80295],
            [-122.272057, 37.80295],
            [-122.278011, 37.805288]
          ]
        },
        "properties": {}
      }
  ]
}

enter image description here

1
  • Many thanks @user2856! now i'll check into how/where i got that extra set of brackets. Oct 10, 2021 at 19:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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