Search code examples
jsonleafletgeojson

geoJSON file structure


I'm working with geoJSON for the first time. I'm using it to display points and polygons on my Leafletjs map.

I have the following: 59 map points (roughly), 5 construction sites (polygon), and 32 buildings (polygon) that I need to have in my geoJSON file.

I'm not sure if I need to create multiple JSON files or can they all live in one file. I need to separate them into 3 groups: map points, construction, and buildings in the single JSON file if that is possible.

I did notice on the documentation (geojson.org) that there is a global type and they use "FeatureCollection". Can this be called someting else so I can make my three groups? I also notice the features collection and the type of feature for each item. Can these be named something as well?


Solution

  • No, you can't use other names for "FeatureCollection" or "Feature." The nearest you can come to groups in GeoJSON is to give the features of each group a common "tag". Like

    "features": [
        {"type": "Feature", "properties": {"group": "group1"}, ...},
        {"type": "Feature", "properties": {"group": "group2"}, ...},
        {"type": "Feature", "properties": {"group": "group3"}, ...}]
    

    Then, using Leaflet you can bind features to popups or style them differently depending on their "group" tag/property. See http://leafletjs.com/reference.html#geojson.