def transform(self, obj, dest): """ Transforms an object from this projection to a specified destination projection. *obj* is a :class:`Geometry <geoscript.geom.Geometry>` object to transform. *dest* is the destination :class:`Projection` to transform to. >>> proj = Projection('epsg:4326') >>> dest = Projection('epsg:3005') >>> import geom >>> p1 = geom.Point(-125, 50) >>> p2 = proj.transform(p1, dest) >>> p2.round() POINT (1071693 554290) *obj* may also be specified as a single coordinate ``list`` or ``tuple``. *dest* may also be specified as a string identifying the destination projection. >>> proj = Projection('epsg:4326') >>> p1 = (-125, 50) >>> p2 = proj.transform(p1, 'epsg:3005') >>> [round(x) for x in p2] [1071693.0, 554290.0] """ fromcrs = self._crs tocrs = Projection(dest)._crs tx = crs.findMathTransform(fromcrs,tocrs) if isinstance(obj, (list,tuple)): # tuple or list import jarray transformed = jarray.zeros(len(obj), 'd') tx.transform(obj, 0, transformed, 0, 1) l = [transformed[x] for x in range(len(obj))] return l if isinstance(obj, list) else tuple(l) else: # geometry gt = GeometryTX() gt.mathTransform = tx return core.map(gt.transform(obj))
def transform(self, obj, dest): """ Transforms an object from this projection to a specified destination projection. *obj* is a :class:`Geometry <geoscript.geom.Geometry>` object to transform. *dest* is the destination :class:`Projection` to transform to. >>> proj = Projection('epsg:4326') >>> dest = Projection('epsg:3005') >>> import geom >>> p1 = geom.Point(-125, 50) >>> p2 = proj.transform(p1, dest) >>> p2.round() POINT (1071693 554290) *obj* may also be specified as a single coordinate ``list`` or ``tuple``. *dest* may also be specified as a string identifying the destination projection. >>> proj = Projection('epsg:4326') >>> p1 = (-125, 50) >>> p2 = proj.transform(p1, 'epsg:3005') >>> [round(x) for x in p2] [1071693.0, 554290.0] """ fromcrs = self._crs tocrs = Projection(dest)._crs tx = crs.findMathTransform(fromcrs, tocrs) if isinstance(obj, (list, tuple)): # tuple or list import jarray transformed = jarray.zeros(len(obj), 'd') tx.transform(obj, 0, transformed, 0, 1) l = [transformed[x] for x in range(len(obj))] return l if isinstance(obj, list) else tuple(l) else: # geometry gt = GeometryTX() gt.mathTransform = tx return core.map(gt.transform(obj))
def get_transform(clz, crs1, crs2): crs1 = clz.get_crs(crs1) crs2 = clz.get_crs(crs2) return CRS.findMathTransform(crs1, crs2, True)