def __init__(self, source, target): "Initializes on a source and target SpatialReference objects." self._ptr = None # Initially NULL if not isinstance(source, SpatialReference) or not isinstance(target, SpatialReference): raise SRSException('source and target must be of type SpatialReference') self._ptr = new_ct(source._ptr, target._ptr) if not self._ptr: raise SRSException('could not intialize CoordTransform object') self._srs1_name = source.name self._srs2_name = target.name
def check_srs(result, func, cargs): if isinstance(result, int): result = c_void_p(result) if not result: raise SRSException( 'Invalid spatial reference pointer returned from "%s".' % func.__name__) return result
def __init__(self, srs_input='', srs_type='wkt'): """ Creates a GDAL OSR Spatial Reference object from the given input. The input may be string of OGC Well Known Text (WKT), an integer EPSG code, a PROJ.4 string, and/or a projection "well known" shorthand string (one of 'WGS84', 'WGS72', 'NAD27', 'NAD83'). """ # Intializing pointer and string buffer. self._ptr = None buf = c_char_p('') if isinstance(srs_input, basestring): # Encoding to ASCII if unicode passed in. if isinstance(srs_input, UnicodeType): srs_input = srs_input.encode('ascii') epsg_m = self._epsg_regex.match(srs_input) proj_m = self._proj_regex.match(srs_input) if epsg_m: # Is this an EPSG well known name? srs_type = 'epsg' srs_input = int(epsg_m.group('epsg')) elif proj_m: # Is the string a PROJ.4 string? srs_type = 'proj' elif srs_input in self._well_known: # Is this a short-hand well known name? srs_type = 'epsg' srs_input = self._well_known[srs_input] elif srs_type == 'proj': pass else: # Setting the buffer with WKT, PROJ.4 string, etc. buf = c_char_p(srs_input) elif isinstance(srs_input, int): # EPSG integer code was input. if srs_type != 'epsg': srs_type = 'epsg' elif isinstance(srs_input, c_void_p): srs_type = 'ogr' else: raise TypeError('Invalid SRS type "%s"' % srs_type) if srs_type == 'ogr': # SRS input is OGR pointer srs = srs_input else: # Creating a new pointer, using the string buffer. srs = new_srs(buf) # If the pointer is NULL, throw an exception. if not srs: raise SRSException('Could not create spatial reference from: %s' % srs_input) else: self._ptr = srs # Post-processing if in PROJ.4 or EPSG formats. if srs_type == 'proj': self.import_proj(srs_input) elif srs_type == 'epsg': self.import_epsg(srs_input)
def __init__(self, srs_input='', srs_type='user'): """ Creates a GDAL OSR Spatial Reference object from the given input. The input may be string of OGC Well Known Text (WKT), an integer EPSG code, a PROJ.4 string, and/or a projection "well known" shorthand string (one of 'WGS84', 'WGS72', 'NAD27', 'NAD83'). """ if srs_type == 'wkt': self.ptr = capi.new_srs(c_char_p(b'')) self.import_wkt(srs_input) return elif isinstance(srs_input, six.string_types): # Encoding to ASCII if unicode passed in. if isinstance(srs_input, six.text_type): srs_input = srs_input.encode('ascii') try: # If SRID is a string, e.g., '4326', then make acceptable # as user input. srid = int(srs_input) srs_input = 'EPSG:%d' % srid except ValueError: pass elif isinstance(srs_input, six.integer_types): # EPSG integer code was input. srs_type = 'epsg' elif isinstance(srs_input, self.ptr_type): srs = srs_input srs_type = 'ogr' else: raise TypeError('Invalid SRS type "%s"' % srs_type) if srs_type == 'ogr': # Input is already an SRS pointer. srs = srs_input else: # Creating a new SRS pointer, using the string buffer. buf = c_char_p(b'') srs = capi.new_srs(buf) # If the pointer is NULL, throw an exception. if not srs: raise SRSException('Could not create spatial reference from: %s' % srs_input) else: self.ptr = srs # Importing from either the user input string or an integer SRID. if srs_type == 'user': self.import_user_input(srs_input) elif srs_type == 'epsg': self.import_epsg(srs_input)
def __init__(self, srs_input="", srs_type="user"): """ Create a GDAL OSR Spatial Reference object from the given input. The input may be string of OGC Well Known Text (WKT), an integer EPSG code, a PROJ.4 string, and/or a projection "well known" shorthand string (one of 'WGS84', 'WGS72', 'NAD27', 'NAD83'). """ if srs_type == "wkt": self.ptr = capi.new_srs(c_char_p(b"")) self.import_wkt(srs_input) return elif isinstance(srs_input, str): try: # If SRID is a string, e.g., '4326', then make acceptable # as user input. srid = int(srs_input) srs_input = "EPSG:%d" % srid except ValueError: pass elif isinstance(srs_input, int): # EPSG integer code was input. srs_type = "epsg" elif isinstance(srs_input, self.ptr_type): srs = srs_input srs_type = "ogr" else: raise TypeError('Invalid SRS type "%s"' % srs_type) if srs_type == "ogr": # Input is already an SRS pointer. srs = srs_input else: # Creating a new SRS pointer, using the string buffer. buf = c_char_p(b"") srs = capi.new_srs(buf) # If the pointer is NULL, throw an exception. if not srs: raise SRSException( "Could not create spatial reference from: %s" % srs_input ) else: self.ptr = srs # Importing from either the user input string or an integer SRID. if srs_type == "user": self.import_user_input(srs_input) elif srs_type == "epsg": self.import_epsg(srs_input)
>>>>>>> 37c99181c9a6b95433d60f8c8ef9af5731096435 check_err(result) geom = ptr_byref(cargs, offset=offset) return check_geom(geom, func, cargs) # ### Spatial Reference error-checking routines ### def check_srs(result, func, cargs): <<<<<<< HEAD if isinstance(result, six.integer_types): ======= if isinstance(result, int): >>>>>>> 37c99181c9a6b95433d60f8c8ef9af5731096435 result = c_void_p(result) if not result: raise SRSException('Invalid spatial reference pointer returned from "%s".' % func.__name__) return result # ### Other error-checking routines ### def check_arg_errcode(result, func, cargs, cpl=False): """ The error code is returned in the last argument, by reference. Check its value with `check_err` before returning the result. """ check_err(arg_byref(cargs), cpl=cpl) return result def check_errcode(result, func, cargs, cpl=False): """
def __init__(self, srs_input="", srs_type="user", axis_order=None): """ Create a GDAL OSR Spatial Reference object from the given input. The input may be string of OGC Well Known Text (WKT), an integer EPSG code, a PROJ string, and/or a projection "well known" shorthand string (one of 'WGS84', 'WGS72', 'NAD27', 'NAD83'). """ if not isinstance(axis_order, (type(None), AxisOrder)): raise ValueError( "SpatialReference.axis_order must be an AxisOrder instance." ) self.axis_order = axis_order or AxisOrder.TRADITIONAL if srs_type == "wkt": self.ptr = capi.new_srs(c_char_p(b"")) self.import_wkt(srs_input) if self.axis_order == AxisOrder.TRADITIONAL and GDAL_VERSION >= (3, 0): capi.set_axis_strategy(self.ptr, self.axis_order) elif self.axis_order != AxisOrder.TRADITIONAL and GDAL_VERSION < (3, 0): raise ValueError("%s is not supported in GDAL < 3.0." % self.axis_order) return elif isinstance(srs_input, str): try: # If SRID is a string, e.g., '4326', then make acceptable # as user input. srid = int(srs_input) srs_input = "EPSG:%d" % srid except ValueError: pass elif isinstance(srs_input, int): # EPSG integer code was input. srs_type = "epsg" elif isinstance(srs_input, self.ptr_type): srs = srs_input srs_type = "ogr" else: raise TypeError('Invalid SRS type "%s"' % srs_type) if srs_type == "ogr": # Input is already an SRS pointer. srs = srs_input else: # Creating a new SRS pointer, using the string buffer. buf = c_char_p(b"") srs = capi.new_srs(buf) # If the pointer is NULL, throw an exception. if not srs: raise SRSException( "Could not create spatial reference from: %s" % srs_input ) else: self.ptr = srs if self.axis_order == AxisOrder.TRADITIONAL and GDAL_VERSION >= (3, 0): capi.set_axis_strategy(self.ptr, self.axis_order) elif self.axis_order != AxisOrder.TRADITIONAL and GDAL_VERSION < (3, 0): raise ValueError("%s is not supported in GDAL < 3.0." % self.axis_order) # Importing from either the user input string or an integer SRID. if srs_type == "user": self.import_user_input(srs_input) elif srs_type == "epsg": self.import_epsg(srs_input)
srs = srs_input srs_type = 'ogr' else: raise TypeError('Invalid SRS type "%s"' % srs_type) if srs_type == 'ogr': # Input is already an SRS pointer. srs = srs_input else: # Creating a new SRS pointer, using the string buffer. buf = c_char_p(b'') srs = capi.new_srs(buf) # If the pointer is NULL, throw an exception. if not srs: raise SRSException('Could not create spatial reference from: %s' % srs_input) else: self.ptr = srs # Importing from either the user input string or an integer SRID. if srs_type == 'user': self.import_user_input(srs_input) elif srs_type == 'epsg': self.import_epsg(srs_input) def __getitem__(self, target): """ <<<<<<< HEAD Returns the value of the given string attribute node, None if the node ======= Return the value of the given string attribute node, None if the node