3

I'm writing a converter that produces GeoJSON. My source data has multiple layers of discrete objects over a few square miles. For example:

  • Shuttle Stops: ~25 polygons
  • Shuttle Routes: ~10 line strings
  • Campus Buildings: ~20 polygons
  • Other Buildings: ~50 polygons
  • Sidewalks: ~200 polygons
  • Vegetation: ~400 polygons

I want to bring this data into Mapbox Studio as different layers, for different visual styling of each. Thus, I'm planning on creating one GeoJSON file per layer; one file for each type of object.

I originally thought I would use GeometryCollection.

{ "type"       : "GeometryCollection",
  "geometries" : [{ "type"        : "Polygon",
                    "coordinates" : [[[1,2],
                                      [3,4],
                                      [5,6],
                                      [1,2]]] },
                  { "type"        : "Polygon",
                    "coordinates" : [[[7,8],
                                      [9,10],
                                      [11,12],
                                      [7,8]]] },
                  { "type"        : "Polygon",
                    "coordinates" : [[[13,14],
                                      [15,16],
                                      [17,18],
                                      [13,14]]] }] }

According to RFC 7946:

The word "Collection" in "FeatureCollection" and "GeometryCollection" does not have any significance for the semantics of array members.

However, I get the sense that a GeometryCollection is to be used for a group of related items, like a single logical building made of a few different Geometry primitives. My 200 sidewalk objects are not part of the same logical geometry.

So, I'm currently considering using a FeatureCollection. However, this requires a Feature wrapper for each Geometry, which I don't need. I have no metadata about most polygons or linestrings that would be useful.

{ "type"    : "FeatureCollection",
  "features": [{ "type"    : "Feature",
                 "geometry": { "type"       : "Polygon",
                               "coordinates": [[[1,2],
                                                [3,4],
                                                [5,6],
                                                [1,2]]] } },
               { "type"    : "Feature",
                 "geometry": { "type"       : "Polygon",
                               "coordinates": [[[7,8],
                                                [9,10],
                                                [11,12],
                                                [7,8]]] } },
               { "type"    : "Feature",
                 "geometry": { "type"       : "Polygon",
                               "coordinates": [[[13,14],
                                                [15,16],
                                                [17,18],
                                                [13,14]]] } }] }

What is the appropriate root collection for each file? Is FeatureCollection appropriate, and I should just live with the 'noise' of the Feature wrapper? Or is GeometryCollection appropriate? Or should I be making one file with a FeatureCollection, where each layer is a single Feature and all the objects for that layer are inside a single GeometryCollection?

Your Answer

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

Browse other questions tagged or ask your own question.