Added almost all params, made front API usable, and added crs transform draw testing.

Next step figure out more stable proj4 parsing of datums and proj etc,
with adding more specific names.
Then consistently make to_esriwkt work.
This commit is contained in:
Karim Bahgat
2015-06-30 04:14:12 +02:00
parent fcc463fa76
commit a8aad24a13
15 changed files with 365 additions and 124 deletions
+77 -25
View File
@@ -25,6 +25,7 @@
from . import directions
# ONLY PURE VALUES INSIDE ELLIPSOID...
##+a Semimajor radius of the ellipsoid axis
class SemiMajorRadius:
@@ -32,24 +33,37 @@ class SemiMajorRadius:
def __init__(self, value):
pass
##+alpha ? Used with Oblique Mercator and possibly a few others
class Azimuth:
proj4 = "+alpha"
esri_wkt = "azimuth"
ogc_wkt = "azimuth"
geotiff = "AzimuthAngle"
def __init__(self, value):
pass
##+b Semiminor radius of the ellipsoid axis
class SemiMinorRadius:
proj4 = "+b"
def __init__(self, value):
pass
#################
##+alpha ? Used with Oblique Mercator and possibly a few others
class Azimuth:
proj4 = "+alpha"
esri_wkt = "azimuth"
ogc_wkt = "azimuth"
geotiff = "AzimuthAngle"
def __init__(self, value):
self.value = value
def to_proj4(self):
return "+alpha=%s" % self.value
def to_ogc_wkt(self):
return 'PARAMETER["Azimuth",%s]' % self.value
def to_esri_wkt(self):
return self.to_ogc_wkt()
##+datum Datum name (see `proj -ld`)
class Datum:
def __init__(self, name, ellipsoid):
def __init__(self, name, ellipsoid, datumshift=None):
"""
Arguments:
@@ -58,12 +72,19 @@ class Datum:
"""
self.name = name
self.ellips = ellipsoid
self.datumshift = datumshift
def to_proj4(self):
return "+datum=%s %s" % (self.name.proj4, self.ellips.to_proj4())
if self.datumshift:
return "%s %s" % (self.ellips.to_proj4(), self.datumshift.to_proj4())
else:
return "+datum=%s %s" % (self.name.proj4, self.ellips.to_proj4())
def to_ogc_wkt(self):
return 'DATUM["%s", %s]' % (self.name.ogc_wkt, self.ellips.to_ogc_wkt())
if self.datumshift:
return 'DATUM["%s", %s, %s]' % (self.name.ogc_wkt, self.ellips.to_ogc_wkt(), self.datumshift.to_ogc_wkt())
else:
return 'DATUM["%s", %s]' % (self.name.ogc_wkt, self.ellips.to_ogc_wkt())
def to_esri_wkt(self):
return self.to_ogc_wkt()
@@ -122,7 +143,6 @@ class GeogCS:
self.twin_ax = twin_ax
def to_proj4(self):
# axis excluded because not sure if should be set from geogcs or projcs
return "%s %s %s" % (self.datum.to_proj4(), self.prime_mer.to_proj4(), self.angunit.to_proj4() ) #+axis= AND #, self.twin_ax[0].proj4, self.twin_ax[1].proj4 )
def to_ogc_wkt(self):
@@ -151,8 +171,8 @@ class ProjCS:
def to_proj4(self):
string = "%s %s " % (self.proj.to_proj4(), self.geogcs.to_proj4())
string += " ".join(param.to_proj4() for param in self.params)
# axis excluded because not sure if should be set from geogcs or projcs
#string += " +axis=" + self.twin_ax[0].proj4 + self.twin_ax[1].proj4 + "u" # up set as default because only proj4 can set it I think...
# in proj4, axis only applies to the cs, ie the projcs (not the geogcs, where wkt can specify with axis)
string += " +axis=" + self.twin_ax[0].proj4 + self.twin_ax[1].proj4 + "u" # up set as default because only proj4 can set it I think...
return string
def to_ogc_wkt(self):
@@ -164,7 +184,6 @@ class ProjCS:
def to_esri_wkt(self):
return self.to_ogc_wkt()
##+k Scaling factor (old name)
##+k_0 Scaling factor (new name)
class ScalingFactor:
@@ -193,6 +212,7 @@ class LatitudeOrigin:
return "+lat_0=%s" %self.value
def to_ogc_wkt(self):
# SAME AS LATITUDE OF CENTER???
return 'PARAMETER["latitude_of_origin", %s]' %self.value
def to_esri_wkt(self):
@@ -204,15 +224,39 @@ class LatitudeOrigin:
##+lat_1 Latitude of first standard parallel
class LatitudeFirstStndParallel:
proj4 = "+lat_1"
def __init__(self, value):
self.value = value
def to_proj4(self):
return "+lat_1=%s" %self.value
def to_ogc_wkt(self):
return 'PARAMETER["standard_parallel_1", %s]' %self.value
def to_esri_wkt(self):
return self.to_ogc_wkt()
def to_geotiff(self):
pass
#return "StdParallel1"
##+lat_2 Latitude of second standard parallel
class LatitudeSecondStndParallel:
proj4 = "+lat_2"
def __init__(self, value):
self.value = value
def to_proj4(self):
return "+lat_2=%s" %self.value
def to_ogc_wkt(self):
return 'PARAMETER["standard_parallel_2", %s]' %self.value
def to_esri_wkt(self):
return self.to_ogc_wkt()
def to_geotiff(self):
pass
#return "StdParallel2"
##+lat_ts Latitude of true scale
class LatitudeTrueScale:
@@ -250,12 +294,20 @@ class CentralMeridian:
pass
#return "ProjCenterLong"
##+lonc ? Longitude used with Oblique Mercator and possibly a few others
class LongitudeSpecial:
class LongitudeCenter:
proj4 = "+lonc"
def __init__(self, value):
pass
self.value = value
def to_proj4(self):
return "+lonc=%s" %self.value
def to_ogc_wkt(self):
return 'PARAMETER["Longitude_Of_Center", %s]' %self.value
def to_esri_wkt(self):
return self.to_ogc_wkt()
##+lon_wrap Center longitude to use for wrapping (see below)
@@ -294,6 +346,7 @@ class Projection:
def to_esri_wkt(self):
return self.to_ogc_wkt()
##+zone UTM zone
##+south Denotes southern hemisphere UTM zone
@@ -303,10 +356,10 @@ class DatumShift:
self.value = value
def to_proj4(self):
return "+towgs84=%s" %"".join((str(val) for val in self.value))
return "+towgs84=%s" %",".join((str(val) for val in self.value))
def to_ogc_wkt(self):
return "TOWGS84[%s]" %"".join((str(val) for val in self.value))
return "TOWGS84[%s]" %",".join((str(val) for val in self.value))
def to_esri_wkt(self):
raise Exception("Paramater not supported by ESRI WKT")
@@ -416,8 +469,7 @@ class FalseNorthing:
def to_esri_wkt(self):
return self.to_ogc_wkt()
# then the final CRS object which is instantiated with all of these?
# remember to use +no_defs when outputting to proj4
# ...