-
Notifications
You must be signed in to change notification settings - Fork 10
Open
Description
I'm confident that the present mapbox querying solution will still work out fine; but just for some nerd fun and potential future use I want to work out decentralized alternatives for the core problem statement of this project : If you throw up any lat-long, how to figure out which polygon it is in, from a vast number of polygons with complex and heavy data, with a limit on amount of bytes that can be loaded for the job?
Here's one strategy:
- generate bounding lat-longs for all constituencies. So 4 numbers : min_lat, max_lat, min_lon, max_lon
- make a simple csv table of that along with all metadata per constituency : codes, state, election phase, date (or maybe a separate lookup table for phase > date?)
- load the table up on page load
- When user clicks a location, filter the table and arrive at just the small handful of rows for whom the lat,lon is within their bounds.
- Load up their shapes (stored separately of course) and check using point-in-polygon (there's turf.js but there's others too)
- When a match is found, publish the result (ie the metadata/attributes of the constituency that were stored as CSV)
- If wanted, render the constitudency boundary too on the map as a non-ineractive geojson layer.
To prep up the data for this kind of thing, here's what would be involved:
- if we start with the Parliamentary Constituencies in ESRI shapefile format: https://github.com/datameet/maps/tree/master/parliamentary-constituencies
- Generate 4 metadata values for each item: [min_lat, max_lat, min_lon, max_lon]
- Create a CSV (one PC per row) with the attributes that were, plus these, plus the extra stuff like election dates, hindi names etc if possible.
- Split into individual .geojson's for each shape. (and name them properly, like {state code}_{pc code}.geojson - that's important!)
Depending on how we do this, the splitting could happen first or last.
Benefits of this strategy :
- Avoids having to load up enormous amounts of geo-data. The shortlisted constituencies will be mighty small in number - in many cases there'll be directly just one possible match. In other cases, there many be two, maybe four.. but very small number.
- The calculation will be almost instantaneous and loading won't take very long either (CSV and a couple of geojsons : both gzip well too) - so this might actually perform faster than an API call. It would be fun to pit the two methods against each other and time them.
DaxServer
Metadata
Metadata
Assignees
Labels
No labels