azavea / temperate

Climate app developed in partnership with ICLEI
Apache License 2.0
0 stars 0 forks source link

Match UserLocation with city ID in associated Climate Change API instance #102

Closed rmartz closed 6 years ago

rmartz commented 6 years ago

For real-world climate data requests like in #79, we need to know what data to ask for. In the Climate Change API, that is mediated through a city_id, which abstracts a specific location in the climate data map cell grid. Multiple cities can share a single map cell, but that's OK for our purposes.

What we want is to associate UserLocation objects with a ID for the city they correspond with in the configured Climate Change API environment, possibly done in conjunction with the creation of the UserLocation object or shortly afterwards in a batch process (So as to ensure the request/response cycle isn't blocked by a anomalously slow API request)

rmartz commented 6 years ago

Plan for the moment is to use GeoDjango's GEOSGeometry.centroid to select the center of the region, and then use /api/city/nearest/ to turn that into a City ID. This isn't perfect, in part since polygons can be convex and have the centroid external to the polygon, but also because each UserLocation has its geometry defined as a MultiPolygonField.

That's super useful for users because it's the most general type of geometry and most likely to fit their needs, but it also means that a user could pick two completely discontinuous blocks (As anything a MultiPolygonField is needed for inherently contains), and the centroid will almost assuredly be some random spot in between. Not great.

However, that'll probably be an acceptable caveat until we have a chance to iron out some more sophisticated logic to use.

rmartz commented 6 years ago

Scratch that, read through the docs some more and GEOSGeometry .point_on_surface seems to solve the problems listed above. There's still the problem with arbitrarily choosing some point in the shape to represent the entire shape, but that seems to be intractable at this moment.

rmartz commented 6 years ago

Closing as nonsensical, this will be handled by the restructuring that is expected to happen in #100