-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
convert between BC Albers database and EPSG 4326 front end
- Loading branch information
Showing
5 changed files
with
150 additions
and
12 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# The postGIS database is in the BC Albers projection. The front end uses no | ||
# particular projection, but we assume it to be EPSG 4326 for convenience | ||
# functions in this file convert between the two systems. | ||
|
||
# use assume_4326 on parameters received from the front end, to add a projection | ||
# use to_4326 on data fetched from the back end, to convert it to EPSG 4236 | ||
|
||
from sqlalchemy import func | ||
import shapely.wkt | ||
import geojson | ||
import json | ||
|
||
|
||
def to_4326(geom): | ||
"""convert a geometry to 4326 to send to the front end""" | ||
return func.ST_Transform(geom, 4326) | ||
|
||
|
||
def assume_4326(wkt): | ||
"""convert a WKT string (no projection) to an equivalent geoJSON string in WPSG 4326""" | ||
shape = shapely.wkt.loads(wkt) | ||
gj = json.loads(geojson.dumps(shape)) | ||
gj["crs"] = {"type": "name", "properties": {"name": "epsg:4326"}} | ||
|
||
return json.dumps(gj) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters