def __call__(self, *args, **kw): #,lon,lat,inverse=False,radians=False,errcheck=False): """ Calling a Proj class instance with the arguments lon, lat will convert lon/lat (in degrees) to x/y native map projection coordinates (in meters). If optional keyword 'inverse' is True (default is False), the inverse transformation from x/y to lon/lat is performed. If optional keyword 'radians' is True (default is False) the units of lon/lat are radians instead of degrees. If optional keyword 'errcheck' is True (default is False) an exception is raised if the transformation is invalid. If errcheck=False and the transformation is invalid, no exception is raised and 1.e30 is returned. Instead of calling with lon, lat, a single ndarray of shape n,2 may be used, and one of the same shape will be returned; this is more efficient. Inputs should be doubles (they will be cast to doubles if they are not, causing a slight performance hit). Works with numpy and regular python array objects, python sequences and scalars, but is fastest for array objects. """ inverse = kw.get('inverse', False) radians = kw.get('radians', False) errcheck = kw.get('errcheck', False) if len(args) == 1: latlon = np.array(args[0], copy=True, order='C', dtype=float, ndmin=2) if inverse: _Proj._invn(self, latlon, radians=radians, errcheck=errcheck) else: _Proj._fwdn(self, latlon, radians=radians, errcheck=errcheck) return latlon lon, lat = args # process inputs, making copies that support buffer API. inx, xisfloat, xislist, xistuple = _copytobuffer(lon) iny, yisfloat, yislist, yistuple = _copytobuffer(lat) # call proj4 functions. inx and iny modified in place. if inverse: _Proj._inv(self, inx, iny, radians=radians, errcheck=errcheck) else: _Proj._fwd(self, inx, iny, radians=radians, errcheck=errcheck) # if inputs were lists, tuples or floats, convert back. outx = _convertback(xisfloat, xislist, xistuple, inx) outy = _convertback(yisfloat, yislist, xistuple, iny) return outx, outy
def __call__(self, *args, **kw): #,lon,lat,inverse=False,radians=False,errcheck=False): """ Calling a Proj class instance with the arguments lon, lat will convert lon/lat (in degrees) to x/y native map projection coordinates (in meters). If optional keyword 'inverse' is True (default is False), the inverse transformation from x/y to lon/lat is performed. If optional keyword 'radians' is True (default is False) the units of lon/lat are radians instead of degrees. If optional keyword 'errcheck' is True (default is False) an exception is raised if the transformation is invalid. If errcheck=False and the transformation is invalid, no exception is raised and 1.e30 is returned. Instead of calling with lon, lat, a single ndarray of shape n,2 may be used, and one of the same shape will be returned; this is more efficient. Inputs should be doubles (they will be cast to doubles if they are not, causing a slight performance hit). Works with numpy and regular python array objects, python sequences and scalars, but is fastest for array objects. """ inverse = kw.get('inverse', False) radians = kw.get('radians', False) errcheck = kw.get('errcheck', False) if len(args) == 1: latlon = npy.array(args[0], copy=True, order='C', dtype=float, ndmin=2) if inverse: _Proj._invn(self, latlon, radians=radians, errcheck=errcheck) else: _Proj._fwdn(self, latlon, radians=radians, errcheck=errcheck) return latlon lon, lat = args # process inputs, making copies that support buffer API. inx, xisfloat, xislist, xistuple = _copytobuffer(lon) iny, yisfloat, yislist, yistuple = _copytobuffer(lat) # call proj4 functions. inx and iny modified in place. if inverse: _Proj._inv(self, inx, iny, radians=radians, errcheck=errcheck) else: _Proj._fwd(self, inx, iny, radians=radians, errcheck=errcheck) # if inputs were lists, tuples or floats, convert back. outx = _convertback(xisfloat,xislist,xistuple,inx) outy = _convertback(yisfloat,yislist,xistuple,iny) return outx, outy
def __new__(self, projparams=None, **kwargs): """ initialize a Proj class instance. Proj4 projection control parameters must either be given in a dictionary 'projparams' or as keyword arguments. See the proj documentation (http://proj.maptools.org) for more information about specifying projection parameters. Example usage: >>> from pyproj import Proj >>> p = Proj(proj='utm',zone=10,ellps='WGS84') >>> x,y = p(-120.108, 34.36116666) >>> print 'x=%9.3f y=%11.3f' % (x,y) x=765975.641 y=3805993.134 >>> print 'lon=%8.3f lat=%5.3f' % p(x,y,inverse=True) lon=-120.108 lat=34.361 >>> # do 3 cities at a time in a tuple (Fresno, LA, SF) >>> lons = (-119.72,-118.40,-122.38) >>> lats = (36.77, 33.93, 37.62 ) >>> x,y = p(lons, lats) >>> print 'x: %9.3f %9.3f %9.3f' % x x: 792763.863 925321.537 554714.301 >>> print 'y: %9.3f %9.3f %9.3f' % y y: 4074377.617 3763936.941 4163835.303 >>> lons, lats = p(x, y, inverse=True) # inverse transform >>> print 'lons: %8.3f %8.3f %8.3f' % lons lons: -119.720 -118.400 -122.380 >>> print 'lats: %8.3f %8.3f %8.3f' % lats lats: 36.770 33.930 37.620 """ # if projparams is None, use kwargs. if projparams is None: if len(kwargs) == 0: raise RuntimeError('no projection control parameters specified') else: projparams = kwargs # set units to meters. if not projparams.has_key('units'): projparams['units']='m' elif projparams['units'] != 'm': print 'resetting units to meters ...' projparams['units']='m' return _Proj.__new__(self, projparams)
def is_geocent(self): """returns True if projection in geocentric (x/y) coordinates""" return _Proj.is_geocent(self)
def is_latlong(self): """returns True if projection in geographic (lon/lat) coordinates""" return _Proj.is_latlong(self)
def __new__(self, projparams=None, preserve_units=False, **kwargs): """ initialize a Proj class instance. Proj4 projection control parameters must either be given in a dictionary 'projparams' or as keyword arguments. See the proj documentation (http://proj.maptools.org) for more information about specifying projection parameters. Example usage: >>> from pyproj import Proj >>> p = Proj(proj='utm',zone=10,ellps='WGS84') # use kwargs >>> x,y = p(-120.108, 34.36116666) >>> print 'x=%9.3f y=%11.3f' % (x,y) x=765975.641 y=3805993.134 >>> print 'lon=%8.3f lat=%5.3f' % p(x,y,inverse=True) lon=-120.108 lat=34.361 >>> # do 3 cities at a time in a tuple (Fresno, LA, SF) >>> lons = (-119.72,-118.40,-122.38) >>> lats = (36.77, 33.93, 37.62 ) >>> x,y = p(lons, lats) >>> print 'x: %9.3f %9.3f %9.3f' % x x: 792763.863 925321.537 554714.301 >>> print 'y: %9.3f %9.3f %9.3f' % y y: 4074377.617 3763936.941 4163835.303 >>> lons, lats = p(x, y, inverse=True) # inverse transform >>> print 'lons: %8.3f %8.3f %8.3f' % lons lons: -119.720 -118.400 -122.380 >>> print 'lats: %8.3f %8.3f %8.3f' % lats lats: 36.770 33.930 37.620 >>> p2 = Proj('+proj=utm +zone=10 +ellps=WGS84') # use proj4 string >>> x,y = p2(-120.108, 34.36116666) >>> print 'x=%9.3f y=%11.3f' % (x,y) x=765975.641 y=3805993.134 >>> p = Proj(init="epsg:32667") >>> print 'x=%12.3f y=%12.3f (meters)' % p(-114.057222, 51.045) x=-1783486.760 y= 6193833.196 (meters) >>> p = Proj("+init=epsg:32667",preserve_units=True) >>> print 'x=%12.3f y=%12.3f (feet)' % p(-114.057222, 51.045) x=-5851322.810 y=20320934.409 (feet) """ # if projparams is None, use kwargs. if projparams is None: if len(kwargs) == 0: raise RuntimeError( 'no projection control parameters specified') else: projstring = _dict2string(kwargs) elif type(projparams) == str: # if projparams is a string, interpret as a proj4 init string. projstring = projparams else: # projparams a dict projstring = _dict2string(projparams) # make sure units are meters if preserve_units is False. if not projstring.count('+units=') and not preserve_units: projstring = '+units=m ' + projstring else: kvpairs = [] for kvpair in projstring.split(): if kvpair.startswith('+units') and not preserve_units: k, v = kvpair.split('=') kvpairs.append(k + '=m ') else: kvpairs.append(kvpair + ' ') projstring = ''.join(kvpairs) return _Proj.__new__(self, projstring)
def __new__(self, projparams=None, preserve_units=False, **kwargs): """ initialize a Proj class instance. Proj4 projection control parameters must either be given in a dictionary 'projparams' or as keyword arguments. See the proj documentation (http://proj.maptools.org) for more information about specifying projection parameters. Example usage: >>> from pyproj import Proj >>> p = Proj(proj='utm',zone=10,ellps='WGS84') # use kwargs >>> x,y = p(-120.108, 34.36116666) >>> print 'x=%9.3f y=%11.3f' % (x,y) x=765975.641 y=3805993.134 >>> print 'lon=%8.3f lat=%5.3f' % p(x,y,inverse=True) lon=-120.108 lat=34.361 >>> # do 3 cities at a time in a tuple (Fresno, LA, SF) >>> lons = (-119.72,-118.40,-122.38) >>> lats = (36.77, 33.93, 37.62 ) >>> x,y = p(lons, lats) >>> print 'x: %9.3f %9.3f %9.3f' % x x: 792763.863 925321.537 554714.301 >>> print 'y: %9.3f %9.3f %9.3f' % y y: 4074377.617 3763936.941 4163835.303 >>> lons, lats = p(x, y, inverse=True) # inverse transform >>> print 'lons: %8.3f %8.3f %8.3f' % lons lons: -119.720 -118.400 -122.380 >>> print 'lats: %8.3f %8.3f %8.3f' % lats lats: 36.770 33.930 37.620 >>> p2 = Proj('+proj=utm +zone=10 +ellps=WGS84') # use proj4 string >>> x,y = p2(-120.108, 34.36116666) >>> print 'x=%9.3f y=%11.3f' % (x,y) x=765975.641 y=3805993.134 >>> p = Proj(init="epsg:32667") >>> print 'x=%12.3f y=%12.3f (meters)' % p(-114.057222, 51.045) x=-1783486.760 y= 6193833.196 (meters) >>> p = Proj("+init=epsg:32667",preserve_units=True) >>> print 'x=%12.3f y=%12.3f (feet)' % p(-114.057222, 51.045) x=-5851322.810 y=20320934.409 (feet) """ # if projparams is None, use kwargs. if projparams is None: if len(kwargs) == 0: raise RuntimeError('no projection control parameters specified') else: projstring = _dict2string(kwargs) elif type(projparams) == str: # if projparams is a string, interpret as a proj4 init string. projstring = projparams else: # projparams a dict projstring = _dict2string(projparams) # make sure units are meters if preserve_units is False. if not projstring.count('+units=') and not preserve_units: projstring = '+units=m '+projstring else: kvpairs = [] for kvpair in projstring.split(): if kvpair.startswith('+units') and not preserve_units: k,v = kvpair.split('=') kvpairs.append(k+'=m ') else: kvpairs.append(kvpair+' ') projstring = ''.join(kvpairs) return _Proj.__new__(self, projstring)