-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from mtmail/new-project-module
- Loading branch information
Showing
5 changed files
with
103 additions
and
92 deletions.
There are no files selected for viewing
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,29 @@ | ||
""" | ||
Deal with coordinate system transformations/projections | ||
""" | ||
|
||
try: | ||
from osgeo import osr | ||
except: | ||
import osr | ||
|
||
# Same as the contents of the *_edges.prj files | ||
PROJCS_WKT = \ | ||
"""GEOGCS["GCS_North_American_1983", | ||
DATUM["D_North_American_1983", | ||
SPHEROID["GRS_1980",6378137,298.257222101]], | ||
PRIMEM["Greenwich",0], | ||
UNIT["Degree",0.017453292519943295]]""" | ||
|
||
from_proj = osr.SpatialReference() | ||
from_proj.ImportFromWkt(PROJCS_WKT) | ||
|
||
# output to WGS84 | ||
to_proj = osr.SpatialReference() | ||
to_proj.SetWellKnownGeogCS("EPSG:4326") | ||
|
||
transformer = osr.CoordinateTransformation(from_proj, to_proj) | ||
|
||
def unproject(point): | ||
projected = transformer.TransformPoint(point[0], point[1]) | ||
return (projected[0], projected[1]) |
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,6 @@ | ||
import pytest | ||
|
||
from lib.project import unproject | ||
|
||
def test_unproject(): | ||
assert(unproject([-76.521714, 36.330247])) == (36.330247, -76.521714) |
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