0

I have a single polygon feature (no holes, no overlaps) which is currently defined as a FeatureCollection in GeoJSON, with type Polygon (not MultiPolygon). I am trying to use it with an online mapping tool, and to do so I need to use a regular Feature in GeoJSON:

enter image description here

I have tried a variety of methods to get it to register and work as a Feature, including: (a) Using the multipart to singlepart tool, which helped it become polygon rather than Multipolygon); (b) using both QGIS and ArcGIS to make the conversion from shapefile to GeoJSON, and (c) editing the GeoJSON file by hand to make it reflect this format:

{
  "type": "Feature",
  "geometry": {
    "type": "Polygon",
    "coordinates": [ [0,0],[0,1],[1,1],[1,0] ]
  },
  "properties": {
    "name": "shape name"
  }
}

For (a) and (b) I still end up with FeatureCollection types, and with (c) nothing maps, despite being recognized as valid by QGIS.

I'd prefer to make this work in QGIS, but am open to suggestions.

bumped to the homepage by Community yesterday

This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.

  • @user2856, Edits made - thanks for the suggestion, and hope it helps! I know that website's mapping tools are a bit buggy, but they are certain that a properly formatted GeoJSON object will work correctly. – phalteman May 13 at 15:15
  • Your mapping tool doesn't say you can't import a FeatureCollection, just that if you do, only the first Feature will be used. So try using a FeatureCollection that contains a single Feature. – user2856 May 16 at 2:41
  • That's true. I had assumed that the reason that we weren't seeing anything map was because of the formatting as FeatureCollection rather than a Feature, since I could find nothing wrong with the polygon itself. In the end, there were two compatability issues that weren't identified in the documentation: the tool only took EPSG:4326, and it only took polygons with fewer than 400 vertices. Neither was related to the FeatureCollection status. But your thoughts were helpful, and in particular the coordinate system one. – phalteman May 16 at 20:10
0

Coordinates array in your feature is wrong. It should be:

[ [ [0,0],[0,1],[1,1],[1,0],[0,0] ] ]
  1. An additional pair of square brackets (because polygon can have holes)
  2. The first and the last point must be the same (to close the polyline)

Wikipedia has nice examples: https://en.wikipedia.org/wiki/GeoJSON#Geometries

  • Thanks for the response and the correction on the format of my example. The example array I provided above was just dummy data, and it turns out the real example I'm using has the same starting an ending point and the extra bracket exactly as you suggest - thus the problem isn't solved. Any other ideas? – phalteman May 13 at 19:26
  • 1
    If GeoJSON is well formed it's really hard to say what can be wrong. From your side maybe coordinates? If the mapping tool is based upon Openlayers it accepts only EPSG:3857 not EPSG:4326. If you use 4326 (lat, lon) try to transform these coordinates to 3857. – dmh126 May 13 at 19:40
  • Helpful, thanks. I am using a different coordinate system, so I'll look into that. – phalteman May 15 at 17:28

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.