desc
stringlengths
3
26.7k
decl
stringlengths
11
7.89k
bodies
stringlengths
8
553k
'The initialization function may take an OGREnvelope structure, 4-element tuple or list, or 4 individual arguments.'
def __init__(self, *args):
if (len(args) == 1): if isinstance(args[0], OGREnvelope): self._envelope = args[0] elif isinstance(args[0], (tuple, list)): if (len(args[0]) != 4): raise OGRException(('Incorrect number of tuple elements (%d).' % len(args[0]))) else:...
'Returns True if the envelopes are equivalent; can compare against other Envelopes and 4-tuples.'
def __eq__(self, other):
if isinstance(other, Envelope): return ((self.min_x == other.min_x) and (self.min_y == other.min_y) and (self.max_x == other.max_x) and (self.max_y == other.max_y)) elif (isinstance(other, tuple) and (len(other) == 4)): return ((self.min_x == other[0]) and (self.min_y == other[1]) and (self.max_...
'Returns a string representation of the tuple.'
def __str__(self):
return str(self.tuple)
'Initializes the C OGR Envelope structure from the given sequence.'
def _from_sequence(self, seq):
self._envelope = OGREnvelope() self._envelope.MinX = seq[0] self._envelope.MinY = seq[1] self._envelope.MaxX = seq[2] self._envelope.MaxY = seq[3]
'Modifies the envelope to expand to include the boundaries of the passed-in 2-tuple (a point), 4-tuple (an extent) or envelope.'
def expand_to_include(self, *args):
if (len(args) == 1): if isinstance(args[0], Envelope): return self.expand_to_include(args[0].tuple) elif (hasattr(args[0], 'x') and hasattr(args[0], 'y')): return self.expand_to_include(args[0].x, args[0].y, args[0].x, args[0].y) elif isinstance(args[0], (tuple, list)...
'Returns the value of the minimum X coordinate.'
@property def min_x(self):
return self._envelope.MinX
'Returns the value of the minimum Y coordinate.'
@property def min_y(self):
return self._envelope.MinY
'Returns the value of the maximum X coordinate.'
@property def max_x(self):
return self._envelope.MaxX
'Returns the value of the maximum Y coordinate.'
@property def max_y(self):
return self._envelope.MaxY
'Returns the upper-right coordinate.'
@property def ur(self):
return (self.max_x, self.max_y)
'Returns the lower-left coordinate.'
@property def ll(self):
return (self.min_x, self.min_y)
'Returns a tuple representing the envelope.'
@property def tuple(self):
return (self.min_x, self.min_y, self.max_x, self.max_y)
'Returns WKT representing a Polygon for this envelope.'
@property def wkt(self):
return ('POLYGON((%s %s,%s %s,%s %s,%s %s,%s %s))' % (self.min_x, self.min_y, self.min_x, self.max_y, self.max_x, self.max_y, self.max_x, self.min_y, self.min_x, self.min_y))
'Initializes on the feature pointer and the integer index of the field within the feature.'
def __init__(self, feat, index):
self._feat = feat self._index = index fld_ptr = capi.get_feat_field_defn(feat, index) if (not fld_ptr): raise OGRException('Cannot create OGR Field, invalid pointer given.') self.ptr = fld_ptr self.__class__ = OGRFieldTypes[self.type] if (isinstance(self, OFTReal) a...
'Returns the string representation of the Field.'
def __str__(self):
return str(self.value).strip()
'Retrieves the Field\'s value as a double (float).'
def as_double(self):
return capi.get_field_as_double(self._feat, self._index)
'Retrieves the Field\'s value as an integer.'
def as_int(self):
return capi.get_field_as_integer(self._feat, self._index)
'Retrieves the Field\'s value as a string.'
def as_string(self):
return capi.get_field_as_string(self._feat, self._index)
'Retrieves the Field\'s value as a tuple of date & time components.'
def as_datetime(self):
(yy, mm, dd, hh, mn, ss, tz) = [c_int() for i in range(7)] status = capi.get_field_as_datetime(self._feat, self._index, byref(yy), byref(mm), byref(dd), byref(hh), byref(mn), byref(ss), byref(tz)) if status: return (yy, mm, dd, hh, mn, ss, tz) else: raise OGRException('Unable to re...
'Returns the name of this Field.'
@property def name(self):
return capi.get_field_name(self.ptr)
'Returns the precision of this Field.'
@property def precision(self):
return capi.get_field_precision(self.ptr)
'Returns the OGR type of this Field.'
@property def type(self):
return capi.get_field_type(self.ptr)
'Return the OGR field type name for this Field.'
@property def type_name(self):
return capi.get_field_type_name(self.type)
'Returns the value of this Field.'
@property def value(self):
return self.as_string()
'Returns the width of this Field.'
@property def width(self):
return capi.get_field_width(self.ptr)
'Returns an integer contained in this field.'
@property def value(self):
return self.as_int()
'GDAL uses OFTReals to represent OFTIntegers in created shapefiles -- forcing the type here since the underlying field type may actually be OFTReal.'
@property def type(self):
return 0
'Returns a float contained in this field.'
@property def value(self):
return self.as_double()
'Returns a Python `date` object for the OFTDate field.'
@property def value(self):
try: (yy, mm, dd, hh, mn, ss, tz) = self.as_datetime() return date(yy.value, mm.value, dd.value) except (ValueError, OGRException): return None
'Returns a Python `datetime` object for this OFTDateTime field.'
@property def value(self):
try: (yy, mm, dd, hh, mn, ss, tz) = self.as_datetime() return datetime(yy.value, mm.value, dd.value, hh.value, mn.value, ss.value) except (ValueError, OGRException): return None
'Returns a Python `time` object for this OFTTime field.'
@property def value(self):
try: (yy, mm, dd, hh, mn, ss, tz) = self.as_datetime() return time(hh.value, mn.value, ss.value) except (ValueError, OGRException): return None
'Destroys this DataStructure object.'
def __del__(self):
if self._ptr: capi.destroy_ds(self._ptr)
'Allows for iteration over the layers in a data source.'
def __iter__(self):
for i in xrange(self.layer_count): (yield self[i])
'Allows use of the index [] operator to get a layer at the index.'
def __getitem__(self, index):
if isinstance(index, basestring): l = capi.get_layer_by_name(self.ptr, index) if (not l): raise OGRIndexError(('invalid OGR Layer name given: "%s"' % index)) elif isinstance(index, int): if ((index < 0) or (index >= self.layer_count)): raise OGRInde...
'Returns the number of layers within the data source.'
def __len__(self):
return self.layer_count
'Returns OGR GetName and Driver for the Data Source.'
def __str__(self):
return ('%s (%s)' % (self.name, str(self.driver)))
'Returns the number of layers in the data source.'
@property def layer_count(self):
return capi.get_layer_count(self._ptr)
'Returns the name of the data source.'
@property def name(self):
return capi.get_ds_name(self._ptr)
'Initializes on an OGR C pointer to the Layer and the `DataSource` object that owns this layer. The `DataSource` object is required so that a reference to it is kept with this Layer. This prevents garbage collection of the `DataSource` while this Layer is still active.'
def __init__(self, layer_ptr, ds):
if (not layer_ptr): raise OGRException('Cannot create Layer, invalid pointer given') self.ptr = layer_ptr self._ds = ds self._ldefn = capi.get_layer_defn(self._ptr) self._random_read = self.test_capability('RandomRead')
'Gets the Feature at the specified index.'
def __getitem__(self, index):
if isinstance(index, (int, long)): if (index < 0): raise OGRIndexError('Negative indices are not allowed on OGR Layers.') return self._make_feature(index) elif isinstance(index, slice): (start, stop, stride) = index.indices(self.num_feat) return [...
'Iterates over each Feature in the Layer.'
def __iter__(self):
capi.reset_reading(self._ptr) for i in xrange(self.num_feat): (yield Feature(capi.get_next_feature(self._ptr), self._ldefn))
'The length is the number of features.'
def __len__(self):
return self.num_feat
'The string name of the layer.'
def __str__(self):
return self.name
'Helper routine for __getitem__ that constructs a Feature from the given Feature ID. If the OGR Layer does not support random-access reading, then each feature of the layer will be incremented through until the a Feature is found matching the given feature ID.'
def _make_feature(self, feat_id):
if self._random_read: try: return Feature(capi.get_feature(self.ptr, feat_id), self._ldefn) except OGRException: pass else: for feat in self: if (feat.fid == feat_id): return feat raise OGRIndexError(('Invalid feature id: %...
'Returns the extent (an Envelope) of this layer.'
@property def extent(self):
env = OGREnvelope() capi.get_extent(self.ptr, byref(env), 1) return Envelope(env)
'Returns the name of this layer in the Data Source.'
@property def name(self):
return capi.get_fd_name(self._ldefn)
'Returns the number of features in the Layer.'
@property def num_feat(self, force=1):
return capi.get_feature_count(self.ptr, force)
'Returns the number of fields in the Layer.'
@property def num_fields(self):
return capi.get_field_count(self._ldefn)
'Returns the geometry type (OGRGeomType) of the Layer.'
@property def geom_type(self):
return OGRGeomType(capi.get_fd_geom_type(self._ldefn))
'Returns the Spatial Reference used in this Layer.'
@property def srs(self):
try: ptr = capi.get_layer_srs(self.ptr) return SpatialReference(srs_api.clone_srs(ptr)) except SRSException: return None
'Returns a list of string names corresponding to each of the Fields available in this Layer.'
@property def fields(self):
return [capi.get_field_name(capi.get_field_defn(self._ldefn, i)) for i in xrange(self.num_fields)]
'Returns a list of the types of fields in this Layer. For example, the list [OFTInteger, OFTReal, OFTString] would be returned for an OGR layer that had an integer, a floating-point, and string fields.'
@property def field_types(self):
return [OGRFieldTypes[capi.get_field_type(capi.get_field_defn(self._ldefn, i))] for i in xrange(self.num_fields)]
'Returns a list of the maximum field widths for the features.'
@property def field_widths(self):
return [capi.get_field_width(capi.get_field_defn(self._ldefn, i)) for i in xrange(self.num_fields)]
'Returns the field precisions for the features.'
@property def field_precisions(self):
return [capi.get_field_precision(capi.get_field_defn(self._ldefn, i)) for i in xrange(self.num_fields)]
'Returns a list containing the given field name for every Feature in the Layer.'
def get_fields(self, field_name):
if (not (field_name in self.fields)): raise OGRException(('invalid field name: %s' % field_name)) return [feat.get(field_name) for feat in self]
'Returns a list containing the OGRGeometry for every Feature in the Layer.'
def get_geoms(self, geos=False):
if geos: from django.contrib.gis.geos import GEOSGeometry return [GEOSGeometry(feat.geom.wkb) for feat in self] else: return [feat.geom for feat in self]
'Returns a bool indicating whether the this Layer supports the given capability (a string). Valid capability strings include: \'RandomRead\', \'SequentialWrite\', \'RandomWrite\', \'FastSpatialFilter\', \'FastFeatureCount\', \'FastGetExtent\', \'CreateField\', \'Transactions\', \'DeleteFeature\', and \'FastSetNextByIn...
def test_capability(self, capability):
return bool(capi.test_capability(self.ptr, capability))
'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\').'
def __init__(self, srs_input=''):
buf = c_char_p('') srs_type = 'user' if isinstance(srs_input, basestring): if isinstance(srs_input, unicode): srs_input = srs_input.encode('ascii') try: srid = int(srs_input) srs_input = ('EPSG:%d' % srid) except ValueError: pass el...
'Destroys this spatial reference.'
def __del__(self):
if self._ptr: capi.release_srs(self._ptr)
'Returns the value of the given string attribute node, None if the node doesn\'t exist. Can also take a tuple as a parameter, (target, child), where child is the index of the attribute in the WKT. For example: >>> wkt = \'GEOGCS["WGS 84", DATUM["WGS_1984, ... AUTHORITY["EPSG","4326"]]\') >>> srs = SpatialReference(wk...
def __getitem__(self, target):
if isinstance(target, tuple): return self.attr_value(*target) else: return self.attr_value(target)
'The string representation uses \'pretty\' WKT.'
def __str__(self):
return self.pretty_wkt
'The attribute value for the given target node (e.g. \'PROJCS\'). The index keyword specifies an index of the child node to return.'
def attr_value(self, target, index=0):
if ((not isinstance(target, basestring)) or (not isinstance(index, int))): raise TypeError return capi.get_attr_value(self.ptr, target, index)
'Returns the authority name for the given string target node.'
def auth_name(self, target):
return capi.get_auth_name(self.ptr, target)
'Returns the authority code for the given string target node.'
def auth_code(self, target):
return capi.get_auth_code(self.ptr, target)
'Returns a clone of this SpatialReference object.'
def clone(self):
return SpatialReference(capi.clone_srs(self.ptr))
'Morphs this SpatialReference from ESRI\'s format to EPSG.'
def from_esri(self):
capi.morph_from_esri(self.ptr)
'This method inspects the WKT of this SpatialReference, and will add EPSG authority nodes where an EPSG identifier is applicable.'
def identify_epsg(self):
capi.identify_epsg(self.ptr)
'Morphs this SpatialReference to ESRI\'s format.'
def to_esri(self):
capi.morph_to_esri(self.ptr)
'Checks to see if the given spatial reference is valid.'
def validate(self):
capi.srs_validate(self.ptr)
'Returns the name of this Spatial Reference.'
@property def name(self):
if self.projected: return self.attr_value('PROJCS') elif self.geographic: return self.attr_value('GEOGCS') elif self.local: return self.attr_value('LOCAL_CS') else: return None
'Returns the SRID of top-level authority, or None if undefined.'
@property def srid(self):
try: return int(self.attr_value('AUTHORITY', 1)) except (TypeError, ValueError): return None
'Returns the name of the linear units.'
@property def linear_name(self):
(units, name) = capi.linear_units(self.ptr, byref(c_char_p())) return name
'Returns the value of the linear units.'
@property def linear_units(self):
(units, name) = capi.linear_units(self.ptr, byref(c_char_p())) return units
'Returns the name of the angular units.'
@property def angular_name(self):
(units, name) = capi.angular_units(self.ptr, byref(c_char_p())) return name
'Returns the value of the angular units.'
@property def angular_units(self):
(units, name) = capi.angular_units(self.ptr, byref(c_char_p())) return units
'Returns a 2-tuple of the units value and the units name, and will automatically determines whether to return the linear or angular units.'
@property def units(self):
if (self.projected or self.local): return capi.linear_units(self.ptr, byref(c_char_p())) elif self.geographic: return capi.angular_units(self.ptr, byref(c_char_p())) else: return (None, None)
'Returns a tuple of the ellipsoid parameters: (semimajor axis, semiminor axis, and inverse flattening)'
@property def ellipsoid(self):
return (self.semi_major, self.semi_minor, self.inverse_flattening)
'Returns the Semi Major Axis for this Spatial Reference.'
@property def semi_major(self):
return capi.semi_major(self.ptr, byref(c_int()))
'Returns the Semi Minor Axis for this Spatial Reference.'
@property def semi_minor(self):
return capi.semi_minor(self.ptr, byref(c_int()))
'Returns the Inverse Flattening for this Spatial Reference.'
@property def inverse_flattening(self):
return capi.invflattening(self.ptr, byref(c_int()))
'Returns True if this SpatialReference is geographic (root node is GEOGCS).'
@property def geographic(self):
return bool(capi.isgeographic(self.ptr))
'Returns True if this SpatialReference is local (root node is LOCAL_CS).'
@property def local(self):
return bool(capi.islocal(self.ptr))
'Returns True if this SpatialReference is a projected coordinate system (root node is PROJCS).'
@property def projected(self):
return bool(capi.isprojected(self.ptr))
'Imports the Spatial Reference from the EPSG code (an integer).'
def import_epsg(self, epsg):
capi.from_epsg(self.ptr, epsg)
'Imports the Spatial Reference from a PROJ.4 string.'
def import_proj(self, proj):
capi.from_proj(self.ptr, proj)
'Imports the Spatial Reference from the given user input string.'
def import_user_input(self, user_input):
capi.from_user_input(self.ptr, user_input)
'Imports the Spatial Reference from OGC WKT (string)'
def import_wkt(self, wkt):
capi.from_wkt(self.ptr, byref(c_char_p(wkt)))
'Imports the Spatial Reference from an XML string.'
def import_xml(self, xml):
capi.from_xml(self.ptr, xml)
'Returns the WKT representation of this Spatial Reference.'
@property def wkt(self):
return capi.to_wkt(self.ptr, byref(c_char_p()))
'Returns the \'pretty\' representation of the WKT.'
@property def pretty_wkt(self, simplify=0):
return capi.to_pretty_wkt(self.ptr, byref(c_char_p()), simplify)
'Returns the PROJ.4 representation for this Spatial Reference.'
@property def proj(self):
return capi.to_proj(self.ptr, byref(c_char_p()))
'Alias for proj().'
@property def proj4(self):
return self.proj
'Returns the XML representation of this Spatial Reference.'
@property def xml(self, dialect=''):
return capi.to_xml(self.ptr, byref(c_char_p()), dialect)
'Initializes on a source and target SpatialReference objects.'
def __init__(self, source, target):
if ((not isinstance(source, SpatialReference)) or (not isinstance(target, SpatialReference))): raise TypeError('source and target must be of type SpatialReference') self.ptr = capi.new_ct(source._ptr, target._ptr) self._srs1_name = source.name self._srs2_name = target.name
'Deletes this Coordinate Transformation object.'
def __del__(self):
if self._ptr: capi.destroy_ct(self._ptr)
'Initializes the GeoIP object, no parameters are required to use default settings. Keyword arguments may be passed in to customize the locations of the GeoIP data sets. * path: Base directory to where GeoIP data is located or the full path to where the city or country data files (*.dat) are located. Assumes that both ...
def __init__(self, path=None, cache=0, country=None, city=None):
if (cache in self.cache_options): self._cache = self.cache_options[cache] else: raise GeoIPException(('Invalid caching option: %s' % cache)) if (not path): path = GEOIP_SETTINGS.get('GEOIP_PATH', None) if (not path): raise GeoIPException('GeoIP path ...
'Helper routine for checking the query and database availability.'
def _check_query(self, query, country=False, city=False, city_or_country=False):
if (not isinstance(query, basestring)): raise TypeError(('GeoIP query must be a string, not type %s' % type(query).__name__)) if (city_or_country and (not (self._country or self._city))): raise GeoIPException('Invalid GeoIP country and city data files.')...
'Returns a dictionary of city information for the given IP address or Fully Qualified Domain Name (FQDN). Some information in the dictionary may be undefined (None).'
def city(self, query):
self._check_query(query, city=True) if ipregex.match(query): ptr = rec_by_addr(self._city, c_char_p(query)) else: ptr = rec_by_name(self._city, c_char_p(query)) if bool(ptr): record = ptr.contents return dict(((tup[0], getattr(record, tup[0])) for tup in record._fields_))...
'Returns the country code for the given IP Address or FQDN.'
def country_code(self, query):
self._check_query(query, city_or_country=True) if self._country: if ipregex.match(query): return cntry_code_by_addr(self._country, query) else: return cntry_code_by_name(self._country, query) else: return self.city(query)['country_code']
'Returns the country name for the given IP Address or FQDN.'
def country_name(self, query):
self._check_query(query, city_or_country=True) if self._country: if ipregex.match(query): return cntry_name_by_addr(self._country, query) else: return cntry_name_by_name(self._country, query) else: return self.city(query)['country_name']