desc
stringlengths 3
26.7k
| decl
stringlengths 11
7.89k
| bodies
stringlengths 8
553k
|
---|---|---|
'Returns True if this geometry is within the other.'
| def within(self, other):
| return self._topology(capi.ogr_within, other)
|
'Returns True if this geometry contains the other.'
| def contains(self, other):
| return self._topology(capi.ogr_contains, other)
|
'Returns True if this geometry overlaps the other.'
| def overlaps(self, other):
| return self._topology(capi.ogr_overlaps, other)
|
'A helper routine for the OGR routines that generate geometries.'
| def _geomgen(self, gen_func, other=None):
| if isinstance(other, OGRGeometry):
return OGRGeometry(gen_func(self.ptr, other.ptr), self.srs)
else:
return OGRGeometry(gen_func(self.ptr), self.srs)
|
'Returns the boundary of this geometry.'
| @property
def boundary(self):
| return self._geomgen(capi.get_boundary)
|
'Returns the smallest convex Polygon that contains all the points in
this Geometry.'
| @property
def convex_hull(self):
| return self._geomgen(capi.geom_convex_hull)
|
'Returns a new geometry consisting of the region which is the difference
of this geometry and the other.'
| def difference(self, other):
| return self._geomgen(capi.geom_diff, other)
|
'Returns a new geometry consisting of the region of intersection of this
geometry and the other.'
| def intersection(self, other):
| return self._geomgen(capi.geom_intersection, other)
|
'Returns a new geometry which is the symmetric difference of this
geometry and the other.'
| def sym_difference(self, other):
| return self._geomgen(capi.geom_sym_diff, other)
|
'Returns a new geometry consisting of the region which is the union of
this geometry and the other.'
| def union(self, other):
| return self._geomgen(capi.geom_union, other)
|
'Returns the X coordinate for this Point.'
| @property
def x(self):
| return capi.getx(self.ptr, 0)
|
'Returns the Y coordinate for this Point.'
| @property
def y(self):
| return capi.gety(self.ptr, 0)
|
'Returns the Z coordinate for this Point.'
| @property
def z(self):
| if (self.coord_dim == 3):
return capi.getz(self.ptr, 0)
|
'Returns the tuple of this point.'
| @property
def tuple(self):
| if (self.coord_dim == 2):
return (self.x, self.y)
elif (self.coord_dim == 3):
return (self.x, self.y, self.z)
|
'Returns the Point at the given index.'
| def __getitem__(self, index):
| if ((index >= 0) and (index < self.point_count)):
(x, y, z) = (c_double(), c_double(), c_double())
capi.get_point(self.ptr, index, byref(x), byref(y), byref(z))
dim = self.coord_dim
if (dim == 1):
return (x.value,)
elif (dim == 2):
return (x.value, y.value)
elif (dim == 3):
return (x.value, y.value, z.value)
else:
raise OGRIndexError(('index out of range: %s' % str(index)))
|
'Iterates over each point in the LineString.'
| def __iter__(self):
| for i in xrange(self.point_count):
(yield self[i])
|
'The length returns the number of points in the LineString.'
| def __len__(self):
| return self.point_count
|
'Returns the tuple representation of this LineString.'
| @property
def tuple(self):
| return tuple([self[i] for i in xrange(len(self))])
|
'Internal routine that returns a sequence (list) corresponding with
the given function.'
| def _listarr(self, func):
| return [func(self.ptr, i) for i in xrange(len(self))]
|
'Returns the X coordinates in a list.'
| @property
def x(self):
| return self._listarr(capi.getx)
|
'Returns the Y coordinates in a list.'
| @property
def y(self):
| return self._listarr(capi.gety)
|
'Returns the Z coordinates in a list.'
| @property
def z(self):
| if (self.coord_dim == 3):
return self._listarr(capi.getz)
|
'The number of interior rings in this Polygon.'
| def __len__(self):
| return self.geom_count
|
'Iterates through each ring in the Polygon.'
| def __iter__(self):
| for i in xrange(self.geom_count):
(yield self[i])
|
'Gets the ring at the specified index.'
| def __getitem__(self, index):
| if ((index < 0) or (index >= self.geom_count)):
raise OGRIndexError(('index out of range: %s' % index))
else:
return OGRGeometry(capi.clone_geom(capi.get_geom_ref(self.ptr, index)), self.srs)
|
'Returns the shell of this Polygon.'
| @property
def shell(self):
| return self[0]
|
'Returns a tuple of LinearRing coordinate tuples.'
| @property
def tuple(self):
| return tuple([self[i].tuple for i in xrange(self.geom_count)])
|
'The number of Points in this Polygon.'
| @property
def point_count(self):
| return sum([self[i].point_count for i in xrange(self.geom_count)])
|
'Returns the centroid (a Point) of this Polygon.'
| @property
def centroid(self):
| p = OGRGeometry(OGRGeomType('Point'))
capi.get_centroid(self.ptr, p.ptr)
return p
|
'Gets the Geometry at the specified index.'
| def __getitem__(self, index):
| if ((index < 0) or (index >= self.geom_count)):
raise OGRIndexError(('index out of range: %s' % index))
else:
return OGRGeometry(capi.clone_geom(capi.get_geom_ref(self.ptr, index)), self.srs)
|
'Iterates over each Geometry.'
| def __iter__(self):
| for i in xrange(self.geom_count):
(yield self[i])
|
'The number of geometries in this Geometry Collection.'
| def __len__(self):
| return self.geom_count
|
'Add the geometry to this Geometry Collection.'
| def add(self, geom):
| if isinstance(geom, OGRGeometry):
if isinstance(geom, self.__class__):
for g in geom:
capi.add_geom(self.ptr, g.ptr)
else:
capi.add_geom(self.ptr, geom.ptr)
elif isinstance(geom, six.string_types):
tmp = OGRGeometry(geom)
capi.add_geom(self.ptr, tmp.ptr)
else:
raise OGRException('Must add an OGRGeometry.')
|
'The number of Points in this Geometry Collection.'
| @property
def point_count(self):
| return sum([self[i].point_count for i in xrange(self.geom_count)])
|
'Returns a tuple representation of this Geometry Collection.'
| @property
def tuple(self):
| return tuple([self[i].tuple for i in xrange(self.geom_count)])
|
'Initializes Feature from a pointer and its Layer object.'
| def __init__(self, feat, layer):
| if (not feat):
raise OGRException('Cannot create OGR Feature, invalid pointer given.')
self.ptr = feat
self._layer = layer
|
'Releases a reference to this object.'
| def __del__(self):
| if self._ptr:
capi.destroy_feature(self._ptr)
|
'Gets the Field object at the specified index, which may be either
an integer or the Field\'s string label. Note that the Field object
is not the field\'s _value_ -- use the `get` method instead to
retrieve the value (e.g. an integer) instead of a Field instance.'
| def __getitem__(self, index):
| if isinstance(index, six.string_types):
i = self.index(index)
else:
if ((index < 0) or (index > self.num_fields)):
raise OGRIndexError('index out of range')
i = index
return Field(self, i)
|
'Iterates over each field in the Feature.'
| def __iter__(self):
| for i in xrange(self.num_fields):
(yield self[i])
|
'Returns the count of fields in this feature.'
| def __len__(self):
| return self.num_fields
|
'The string name of the feature.'
| def __str__(self):
| return ('Feature FID %d in Layer<%s>' % (self.fid, self.layer_name))
|
'Does equivalence testing on the features.'
| def __eq__(self, other):
| return bool(capi.feature_equal(self.ptr, other._ptr))
|
'Returns the feature identifier.'
| @property
def fid(self):
| return capi.get_fid(self.ptr)
|
'Returns the name of the layer for the feature.'
| @property
def layer_name(self):
| name = capi.get_feat_name(self._layer._ldefn)
return force_text(name, self.encoding, strings_only=True)
|
'Returns the number of fields in the Feature.'
| @property
def num_fields(self):
| return capi.get_feat_field_count(self.ptr)
|
'Returns a list of fields in the Feature.'
| @property
def fields(self):
| return [capi.get_field_name(capi.get_field_defn(self._layer._ldefn, i)) for i in xrange(self.num_fields)]
|
'Returns the OGR Geometry for this Feature.'
| @property
def geom(self):
| geom_ptr = capi.get_feat_geom_ref(self.ptr)
return OGRGeometry(geom_api.clone_geom(geom_ptr))
|
'Returns the OGR Geometry Type for this Feture.'
| @property
def geom_type(self):
| return OGRGeomType(capi.get_fd_geom_type(self._layer._ldefn))
|
'Returns the value of the field, instead of an instance of the Field
object. May take a string of the field name or a Field object as
parameters.'
| def get(self, field):
| field_name = getattr(field, 'name', field)
return self[field_name].value
|
'Returns the index of the given field name.'
| def index(self, field_name):
| i = capi.get_field_index(self.ptr, force_bytes(field_name))
if (i < 0):
raise OGRIndexError(('invalid OFT field name given: "%s"' % field_name))
return i
|
'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:
self._from_sequence(args[0])
else:
raise TypeError(('Incorrect type of argument: %s' % str(type(args[0]))))
elif (len(args) == 4):
self._from_sequence([float(a) for a in args])
else:
raise OGRException(('Incorrect number (%d) of arguments.' % len(args)))
if (self.min_x > self.max_x):
raise OGRException('Envelope minimum X > maximum X.')
if (self.min_y > self.max_y):
raise OGRException('Envelope minimum Y > maximum Y.')
|
'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_x == other[2]) and (self.max_y == other[3]))
else:
raise OGRException('Equivalence testing only works with other Envelopes.')
|
'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)):
if (len(args[0]) == 2):
return self.expand_to_include((args[0][0], args[0][1], args[0][0], args[0][1]))
elif (len(args[0]) == 4):
(minx, miny, maxx, maxy) = args[0]
if (minx < self._envelope.MinX):
self._envelope.MinX = minx
if (miny < self._envelope.MinY):
self._envelope.MinY = miny
if (maxx > self._envelope.MaxX):
self._envelope.MaxX = maxx
if (maxy > self._envelope.MaxY):
self._envelope.MaxY = maxy
else:
raise OGRException(('Incorrect number of tuple elements (%d).' % len(args[0])))
else:
raise TypeError(('Incorrect type of argument: %s' % str(type(args[0]))))
elif (len(args) == 2):
return self.expand_to_include((args[0], args[1], args[0], args[1]))
elif (len(args) == 4):
return self.expand_to_include(args)
else:
raise OGRException(('Incorrect number (%d) of arguments.' % len(args[0])))
|
'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 object 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.ptr, 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) and (self.precision == 0)):
self.__class__ = OFTInteger
self._double = True
|
'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.ptr, self._index)
|
'Retrieves the Field\'s value as an integer.'
| def as_int(self):
| return capi.get_field_as_integer(self._feat.ptr, self._index)
|
'Retrieves the Field\'s value as a string.'
| def as_string(self):
| string = capi.get_field_as_string(self._feat.ptr, self._index)
return force_text(string, encoding=self._feat.encoding, strings_only=True)
|
'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.ptr, 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 retrieve date & time information from the field.')
|
'Returns the name of this Field.'
| @property
def name(self):
| name = capi.get_field_name(self.ptr)
return force_text(name, encoding=self._feat.encoding, strings_only=True)
|
'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):
| if self._double:
return int(self.as_double())
else:
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, six.string_types):
l = capi.get_layer_by_name(self.ptr, force_bytes(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 OGRIndexError('index out of range')
l = capi.get_layer(self._ptr, index)
else:
raise TypeError(('Invalid index type: %s' % type(index)))
return Layer(l, self)
|
'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):
| name = capi.get_ds_name(self._ptr)
return force_text(name, self.encoding, strings_only=True)
|
'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, six.integer_types):
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 [self._make_feature(fid) for fid in xrange(start, stop, stride)]
else:
raise TypeError('Integers and slices may only be used when indexing OGR Layers.')
|
'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))
|
'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)
except OGRException:
pass
else:
for feat in self:
if (feat.fid == feat_id):
return feat
raise OGRIndexError(('Invalid feature id: %s.' % feat_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):
| name = capi.get_fd_name(self._ldefn)
return force_text(name, self._ds.encoding, strings_only=True)
|
'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
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.