zooniverse / classroom-maps-api

Mapping API for the https://classroom.zooniverse.org service. Built using https://datasette.io/ to provide a JSON API over SQLite databases with custom project CSV data.
MIT License
2 stars 0 forks source link

GeoJSON formatter should include "properties" for FeaturesCollections #9

Open shaunanoordin opened 3 years ago

shaunanoordin commented 3 years ago

Map Enhancement

When the Classroom Maps API outputs GeoJSON data (example) with a FeaturesCollection, this data should include the properties of said Features, in addition to the Features' coordinates & geometries.

Context / Use Case

Compare Darien's flat grey overlay... image

...with Gorongosa's colourful biomes. image

WildCam Darien stores its biome layer on the API, and the API isn't returning the "what biome is here? Forest? Desert? Tundra? etc" associated with each shape (Feature). WCGorongosa doesn't have an issue since the GeoJSON is hardcoded into the front end code. (It's old fashioned that way.)

Notes:

Potential Solution

We just need to change the GeoJSON results from this...

{
  "type":"FeatureCollection",
  "features":[
    {
      "type":"MultiPolygon",
      "coordinates":[...]
    },
  ...
  ]
}

...to this.

{
  "type":"FeatureCollection",
  "features":[
    {
      "type":"Feature",
      "geometry":{
        "type":"MultiPolygon",
        "coordinates":[...]
      },
      "properties":{
        "cartodb_id":1,
        "veg_type":"Montane evergreen tropical forest"
      }
    },
  ...
  ]
}

Should be fairly simple(??) to do. In https://github.com/zooniverse/classroom-maps-api/blob/main/plugins/geo_json_renderer.py...

elif 'the_geom' in row.keys():
    # ...this section should be improved so the 'feature' object is a wee bit more complex
    feature = Geometry(row['the_geom'])
    # ...I guess the only challenge is to somehow list all key-value pairs of the 'row' object except for the_geom, then chuck it into a new 'properties' object.
    feature_list.append(feature)

The main things to test:

Status

Low priority, visual fix