pacificclimate / scip-backend

Backend that serves salmon population data to the scip webpage
GNU Affero General Public License v3.0
0 stars 0 forks source link

Include region area #5

Open corviday opened 1 year ago

corviday commented 1 year ago

We are replacing geoserver with this backend, which allows more sophisticated geographic queries. One thing geoserver did that the backend does not yet do is provide the area of a region, which was previously displayed in the front end.

Is this actually useful? Previously we included it because it was there without any effort on our part, and we might as well. It would be easy to add to the region query, if we wanted. (Or the population query.)

Alternately, we could supply the drainage area (frequently larger than the watershed) as determined by the watershed PCEX query, but this requires a defined outlet, which not all regions have.

corviday commented 1 year ago

@mschnorb has confirmed this would be nice to have, if it was easy, which I think it is.

corviday commented 1 year ago

This is not easy, as the geometries are in degrees, so getting an area in kilometers or something else useful requires a coordinate transform. Tabling for now.

corviday commented 1 year ago

Also, the current region geometries are not in any particular projection. I converted them to degrees with QGIS, which probably told me what projection it was using, or let me pick one, but that information did not register as important to me at the time and I did not save it.

The easy way out is to assume all the current geometries are in 4326 or something, then you can do the area calculation like this, by first assigning the geometry an SRID (4326), and then translating it to BC Albers (3005), which is in meters:

func.ST_Area(func.ST_Transform(func.ST_SetSRID(Region.boundary, 4326), 3005)).label("area")

But since we're looking at re-uploading all the geometries at higher resolution, I wonder if it would be worth it migrating the database to include an SRID and doing it right. I am sure our source shapefiles from the BC government have them.

corviday commented 1 year ago

Added an issue.