Last active
May 11, 2021 06:26
-
-
Save john-science/eb70f8ae47876b09ae2c to your computer and use it in GitHub Desktop.
Converting Proj4 String to Well-Known Text
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
from osgeo.osr import SpatialReference | |
""" | |
A quick script to get the Well-Known Text from a proj4 string. | |
""" | |
# build a spatial reference | |
sr = SpatialReference() | |
# enter the proj4 string | |
valid_code = sr.ImportFromProj4('+proj=lcc +lat_1=25 +lat_2=25 +lat_0=25.0 +lon_0=-95.0 +R=6371229.0') | |
# perform various exports | |
print sr.ExportToProj4() | |
# '+proj=lcc +lat_1=25 +lat_0=25 +lon_0=-95 +k_0=1 +x_0=0 +y_0=0 +a=6371229 +b=6371229 +units=m +no_defs ' | |
print sr.ExportToWkt() | |
""" | |
'PROJCS["unnamed",GEOGCS["unnamed ellipse",DATUM["unknown",SPHEROID["unnamed",6371229,0]], | |
PRIMEM["Greenwich",0],UNIT["degree",0.0174532925199433]],PROJECTION["Lambert_Conformal_Conic_1SP"], | |
PARAMETER["latitude_of_origin",25],PARAMETER["central_meridian",-95],PARAMETER["scale_factor",1], | |
PARAMETER["false_easting",0],PARAMETER["false_northing",0]]' | |
""" | |
print sr.ExportToPrettyWkt() | |
""" | |
PROJCS["unnamed", | |
GEOGCS["unnamed ellipse", | |
DATUM["unknown", | |
SPHEROID["unnamed",6371229,0]], | |
PRIMEM["Greenwich",0], | |
UNIT["degree",0.0174532925199433]], | |
PROJECTION["Lambert_Conformal_Conic_1SP"], | |
PARAMETER["latitude_of_origin",25], | |
PARAMETER["central_meridian",-95], | |
PARAMETER["scale_factor",1], | |
PARAMETER["false_easting",0], | |
PARAMETER["false_northing",0]]' | |
""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment