Permalink
Browse files

gdal.py: Datasets deal with ESRI Web Mercator projections properly.

If the Dataset's projection isn't recognisable by OSR, try to determine its
EPSG code, try to identify an equivalent ESRI code instead. If it succeeds,
the SpatialReference returned will be based on a EPSG one.
  • Loading branch information...
1 parent 961b753 commit d7031a0268e4552c46ffe24ea635473a7a7f2182 Maxime Dupuis committed Jan 29, 2014
Showing with 13 additions and 1 deletion.
  1. +13 −1 gdal2mbtiles/gdal.py
View
@@ -434,7 +434,19 @@ def GetRasterBand(self, i):
dataset=self)
def GetSpatialReference(self):
- return SpatialReference(self.GetProjection())
+ try:
+ sr = SpatialReference(self.GetProjection())
+ sr.AutoIdentifyEPSG()
+ return sr
+ except RuntimeError as re:
+ if 'Unsupported SRS' in re.message:
+ projcs_name = sr.GetAttrValue(str('PROJCS'))
+ # Returning equivalent EPSG code
+ if projcs_name == ESRI_102100_PROJ:
+ return SpatialReference.FromEPSG(3857)
+ elif projcs_name == ESRI_102113_PROJ:
+ return SpatialReference.FromEPSG(3785)
+ raise GdalError(re.message)
def GetCoordinateTransformation(self, dst_ref):
return CoordinateTransformation(src_ref=self.GetSpatialReference(),

0 comments on commit d7031a0

Please sign in to comment.