desc
stringlengths
3
26.7k
decl
stringlengths
11
7.89k
bodies
stringlengths
8
553k
'Converts this Geometry to normal form (or canonical form).'
def normalize(self):
return capi.geos_normalize(self.ptr)
'Returns a boolean indicating whether the set of points in this Geometry are empty.'
@property def empty(self):
return capi.geos_isempty(self.ptr)
'Returns whether the geometry has a 3D dimension.'
@property def hasz(self):
return capi.geos_hasz(self.ptr)
'Returns whether or not the geometry is a ring.'
@property def ring(self):
return capi.geos_isring(self.ptr)
'Returns false if the Geometry not simple.'
@property def simple(self):
return capi.geos_issimple(self.ptr)
'This property tests the validity of this Geometry.'
@property def valid(self):
return capi.geos_isvalid(self.ptr)
'Returns true if other.within(this) returns true.'
def contains(self, other):
return capi.geos_contains(self.ptr, other.ptr)
'Returns true if the DE-9IM intersection matrix for the two Geometries is T*T****** (for a point and a curve,a point and an area or a line and an area) 0******** (for two curves).'
def crosses(self, other):
return capi.geos_crosses(self.ptr, other.ptr)
'Returns true if the DE-9IM intersection matrix for the two Geometries is FF*FF****.'
def disjoint(self, other):
return capi.geos_disjoint(self.ptr, other.ptr)
'Returns true if the DE-9IM intersection matrix for the two Geometries is T*F**FFF*.'
def equals(self, other):
return capi.geos_equals(self.ptr, other.ptr)
'Returns true if the two Geometries are exactly equal, up to a specified tolerance.'
def equals_exact(self, other, tolerance=0):
return capi.geos_equalsexact(self.ptr, other.ptr, float(tolerance))
'Returns true if disjoint returns false.'
def intersects(self, other):
return capi.geos_intersects(self.ptr, other.ptr)
'Returns true if the DE-9IM intersection matrix for the two Geometries is T*T***T** (for two points or two surfaces) 1*T***T** (for two curves).'
def overlaps(self, other):
return capi.geos_overlaps(self.ptr, other.ptr)
'Returns true if the elements in the DE-9IM intersection matrix for the two Geometries match the elements in pattern.'
def relate_pattern(self, other, pattern):
if ((not isinstance(pattern, basestring)) or (len(pattern) > 9)): raise GEOSException('invalid intersection matrix pattern') return capi.geos_relatepattern(self.ptr, other.ptr, pattern)
'Returns true if the DE-9IM intersection matrix for the two Geometries is FT*******, F**T***** or F***T****.'
def touches(self, other):
return capi.geos_touches(self.ptr, other.ptr)
'Returns true if the DE-9IM intersection matrix for the two Geometries is T*F**F***.'
def within(self, other):
return capi.geos_within(self.ptr, other.ptr)
'Gets the SRID for the geometry, returns None if no SRID is set.'
def get_srid(self):
s = capi.geos_get_srid(self.ptr) if (s == 0): return None else: return s
'Sets the SRID for the geometry.'
def set_srid(self, srid):
capi.geos_set_srid(self.ptr, srid)
'Returns the EWKT (WKT + SRID) of the Geometry. Note that Z values are *not* included in this representation because GEOS does not yet support serializing them.'
@property def ewkt(self):
if self.get_srid(): return ('SRID=%s;%s' % (self.srid, self.wkt)) else: return self.wkt
'Returns the WKT (Well-Known Text) representation of this Geometry.'
@property def wkt(self):
return wkt_w().write(self)
'Returns the WKB of this Geometry in hexadecimal form. Please note that the SRID and Z values are not included in this representation because it is not a part of the OGC specification (use the `hexewkb` property instead).'
@property def hex(self):
return wkb_w().write_hex(self)
'Returns the EWKB of this Geometry in hexadecimal form. This is an extension of the WKB specification that includes SRID and Z values that are a part of this geometry.'
@property def hexewkb(self):
if self.hasz: if (not GEOS_PREPARE): raise GEOSException('Upgrade GEOS to 3.1 to get valid 3D HEXEWKB.') return ewkb_w3d().write_hex(self) else: return ewkb_w().write_hex(self)
'Returns GeoJSON representation of this Geometry if GDAL 1.5+ is installed.'
@property def json(self):
if gdal.GEOJSON: return self.ogr.json else: raise GEOSException('GeoJSON output only supported on GDAL 1.5+.')
'Returns the WKB (Well-Known Binary) representation of this Geometry as a Python buffer. SRID and Z values are not included, use the `ewkb` property instead.'
@property def wkb(self):
return wkb_w().write(self)
'Return the EWKB representation of this Geometry as a Python buffer. This is an extension of the WKB specification that includes any SRID and Z values that are a part of this geometry.'
@property def ewkb(self):
if self.hasz: if (not GEOS_PREPARE): raise GEOSException('Upgrade GEOS to 3.1 to get valid 3D EWKB.') return ewkb_w3d().write(self) else: return ewkb_w().write(self)
'Returns the KML representation of this Geometry.'
@property def kml(self):
gtype = self.geom_type return ('<%s>%s</%s>' % (gtype, self.coord_seq.kml, gtype))
'Returns a PreparedGeometry corresponding to this geometry -- it is optimized for the contains, intersects, and covers operations.'
@property def prepared(self):
if GEOS_PREPARE: return PreparedGeometry(self) else: raise GEOSException('GEOS 3.1+ required for prepared geometry support.')
'Returns the OGR Geometry for this Geometry.'
@property def ogr(self):
if gdal.HAS_GDAL: if self.srid: return gdal.OGRGeometry(self.wkb, self.srid) else: return gdal.OGRGeometry(self.wkb) else: raise GEOSException('GDAL required to convert to an OGRGeometry.')
'Returns the OSR SpatialReference for SRID of this Geometry.'
@property def srs(self):
if gdal.HAS_GDAL: if self.srid: return gdal.SpatialReference(self.srid) else: return None else: raise GEOSException('GDAL required to return a SpatialReference object.')
'Alias for `srs` property.'
@property def crs(self):
return self.srs
'Requires GDAL. Transforms the geometry according to the given transformation object, which may be an integer SRID, and WKT or PROJ.4 string. By default, the geometry is transformed in-place and nothing is returned. However if the `clone` keyword is set, then this geometry will not be modified and a transformed clone w...
def transform(self, ct, clone=False):
srid = self.srid if (gdal.HAS_GDAL and srid): g = gdal.OGRGeometry(self.wkb, srid) g.transform(ct) ptr = wkb_r().read(g.wkb) if clone: return GEOSGeometry(ptr, srid=g.srid) if ptr: capi.destroy_geom(self.ptr) self.ptr = ptr ...
'Helper routine to return Geometry from the given pointer.'
def _topology(self, gptr):
return GEOSGeometry(gptr, srid=self.srid)
'Returns the boundary as a newly allocated Geometry object.'
@property def boundary(self):
return self._topology(capi.geos_boundary(self.ptr))
'Returns a geometry that represents all points whose distance from this Geometry is less than or equal to distance. Calculations are in the Spatial Reference System of this Geometry. The optional third parameter sets the number of segment used to approximate a quarter circle (defaults to 8). (Text from PostGIS document...
def buffer(self, width, quadsegs=8):
return self._topology(capi.geos_buffer(self.ptr, width, quadsegs))
'The centroid is equal to the centroid of the set of component Geometries of highest dimension (since the lower-dimension geometries contribute zero "weight" to the centroid).'
@property def centroid(self):
return self._topology(capi.geos_centroid(self.ptr))
'Returns the smallest convex Polygon that contains all the points in the Geometry.'
@property def convex_hull(self):
return self._topology(capi.geos_convexhull(self.ptr))
'Returns a Geometry representing the points making up this Geometry that do not make up other.'
def difference(self, other):
return self._topology(capi.geos_difference(self.ptr, other.ptr))
'Return the envelope for this geometry (a polygon).'
@property def envelope(self):
return self._topology(capi.geos_envelope(self.ptr))
'Returns a Geometry representing the points shared by this Geometry and other.'
def intersection(self, other):
return self._topology(capi.geos_intersection(self.ptr, other.ptr))
'Computes an interior point of this Geometry.'
@property def point_on_surface(self):
return self._topology(capi.geos_pointonsurface(self.ptr))
'Returns the DE-9IM intersection matrix for this Geometry and the other.'
def relate(self, other):
return capi.geos_relate(self.ptr, other.ptr)
'Returns the Geometry, simplified using the Douglas-Peucker algorithm to the specified tolerance (higher tolerance => less points). If no tolerance provided, defaults to 0. By default, this function does not preserve topology - e.g. polygons can be split, collapse to lines or disappear holes can be created or disappea...
def simplify(self, tolerance=0.0, preserve_topology=False):
if preserve_topology: return self._topology(capi.geos_preservesimplify(self.ptr, tolerance)) else: return self._topology(capi.geos_simplify(self.ptr, tolerance))
'Returns a set combining the points in this Geometry not in other, and the points in other not in this Geometry.'
def sym_difference(self, other):
return self._topology(capi.geos_symdifference(self.ptr, other.ptr))
'Returns a Geometry representing all the points in this Geometry and other.'
def union(self, other):
return self._topology(capi.geos_union(self.ptr, other.ptr))
'Returns the area of the Geometry.'
@property def area(self):
return capi.geos_area(self.ptr, byref(c_double()))
'Returns the distance between the closest points on this Geometry and the other. Units will be in those of the coordinate system of the Geometry.'
def distance(self, other):
if (not isinstance(other, GEOSGeometry)): raise TypeError('distance() works only on other GEOS Geometries.') return capi.geos_distance(self.ptr, other.ptr, byref(c_double()))
'Returns the extent of this geometry as a 4-tuple, consisting of (xmin, ymin, xmax, ymax).'
@property def extent(self):
env = self.envelope if isinstance(env, Point): (xmin, ymin) = env.tuple (xmax, ymax) = (xmin, ymin) else: (xmin, ymin) = env[0][0] (xmax, ymax) = env[0][2] return (xmin, ymin, xmax, ymax)
'Returns the length of this Geometry (e.g., 0 for point, or the circumfrence of a Polygon).'
@property def length(self):
return capi.geos_length(self.ptr, byref(c_double()))
'Clones this Geometry.'
def clone(self):
return GEOSGeometry(capi.geom_clone(self.ptr), srid=self.srid)
'Returns a _pointer_ to C GEOS Geometry object from the given WKB.'
def read(self, wkb):
if isinstance(wkb, buffer): wkb_s = str(wkb) return wkb_reader_read(self.ptr, wkb_s, len(wkb_s)) elif isinstance(wkb, basestring): return wkb_reader_read_hex(self.ptr, wkb, len(wkb)) else: raise TypeError
'Returns the WKT representation of the given geometry.'
def write(self, geom):
return wkt_writer_write(self.ptr, geom.ptr)
'Returns the WKB representation of the given geometry.'
def write(self, geom):
return buffer(wkb_writer_write(self.ptr, geom.ptr, byref(c_size_t())))
'Returns the HEXEWKB representation of the given geometry.'
def write_hex(self, geom):
return wkb_writer_write_hex(self.ptr, geom.ptr, byref(c_size_t()))
'Initializes a Geometry Collection from a sequence of Geometry objects.'
def __init__(self, *args, **kwargs):
if (not args): raise TypeError(('Must provide at least one Geometry to initialize %s.' % self.__class__.__name__)) if (len(args) == 1): if isinstance(args[0], (tuple, list)): init_geoms = args[0] else: init_geoms = args else: in...
'Iterates over each Geometry in the Collection.'
def __iter__(self):
for i in xrange(len(self)): (yield self[i])
'Returns the number of geometries in this Collection.'
def __len__(self):
return self.num_geom
'Returns the Geometry from this Collection at the given index (0-based).'
def _get_single_external(self, index):
return GEOSGeometry(capi.geom_clone(self._get_single_internal(index)), srid=self.srid)
'Create a new collection, and destroy the contents of the previous pointer.'
def _set_list(self, length, items):
prev_ptr = self.ptr srid = self.srid self.ptr = self._create_collection(length, items) if srid: self.srid = srid capi.destroy_geom(prev_ptr)
'Returns the KML for this Geometry Collection.'
@property def kml(self):
return ('<MultiGeometry>%s</MultiGeometry>' % ''.join([g.kml for g in self]))
'Returns a tuple of all the coordinates in this Geometry Collection'
@property def tuple(self):
return tuple([g.tuple for g in self])
'Returns a LineString representing the line merge of this MultiLineString.'
@property def merged(self):
return self._topology(capi.geos_linemerge(self.ptr))
'Returns a cascaded union of this MultiPolygon.'
@property def cascaded_union(self):
if GEOS_PREPARE: return GEOSGeometry(capi.geos_cascaded_union(self.ptr), self.srid) else: raise GEOSException('The cascaded union operation requires GEOS 3.1+.')
'The Point object may be initialized with either a tuple, or individual parameters. For Example: >>> p = Point((5, 23)) # 2D point, passed in as a tuple >>> p = Point(5, 23, 8) # 3D point, passed in with individual parameters'
def __init__(self, x, y=None, z=None, srid=None):
if isinstance(x, (tuple, list)): ndim = len(x) coords = x elif (isinstance(x, (int, float, long)) and isinstance(y, (int, float, long))): if isinstance(z, (int, float, long)): ndim = 3 coords = [x, y, z] else: ndim = 2 coords = [x, ...
'Create a coordinate sequence, set X, Y, [Z], and create point'
def _create_point(self, ndim, coords):
if ((ndim < 2) or (ndim > 3)): raise TypeError(('Invalid point dimension: %s' % str(ndim))) cs = capi.create_cs(c_uint(1), c_uint(ndim)) i = iter(coords) capi.cs_setx(cs, 0, i.next()) capi.cs_sety(cs, 0, i.next()) if (ndim == 3): capi.cs_setz(cs, 0, i.next()) return ...
'Allows iteration over coordinates of this Point.'
def __iter__(self):
for i in xrange(len(self)): (yield self[i])
'Returns the number of dimensions for this Point (either 0, 2 or 3).'
def __len__(self):
if self.empty: return 0 if self.hasz: return 3 else: return 2
'Returns the X component of the Point.'
def get_x(self):
return self._cs.getOrdinate(0, 0)
'Sets the X component of the Point.'
def set_x(self, value):
self._cs.setOrdinate(0, 0, value)
'Returns the Y component of the Point.'
def get_y(self):
return self._cs.getOrdinate(1, 0)
'Sets the Y component of the Point.'
def set_y(self, value):
self._cs.setOrdinate(1, 0, value)
'Returns the Z component of the Point.'
def get_z(self):
if self.hasz: return self._cs.getOrdinate(2, 0) else: return None
'Sets the Z component of the Point.'
def set_z(self, value):
if self.hasz: self._cs.setOrdinate(2, 0, value) else: raise GEOSException('Cannot set Z on 2D Point.')
'Returns a tuple of the point.'
def get_coords(self):
return self._cs.tuple
'Sets the coordinates of the point with the given tuple.'
def set_coords(self, tup):
self._cs[0] = tup
'Get the item(s) at the specified index/slice.'
def __getitem__(self, index):
if isinstance(index, slice): return [self._get_single_external(i) for i in xrange(*index.indices(len(self)))] else: index = self._checkindex(index) return self._get_single_external(index)
'Delete the item(s) at the specified index/slice.'
def __delitem__(self, index):
if (not isinstance(index, (int, long, slice))): raise TypeError(('%s is not a legal index' % index)) origLen = len(self) if isinstance(index, (int, long)): index = self._checkindex(index) indexRange = [index] else: indexRange = range(*index.indices(origLen)...
'Set the item(s) at the specified index/slice.'
def __setitem__(self, index, val):
if isinstance(index, slice): self._set_slice(index, val) else: index = self._checkindex(index) self._check_allowed((val,)) self._set_single(index, val)
'Iterate over the items in the list'
def __iter__(self):
for i in xrange(len(self)): (yield self[i])
'add another list-like object'
def __add__(self, other):
return self.__class__((list(self) + list(other)))
'add to another list-like object'
def __radd__(self, other):
return other.__class__((list(other) + list(self)))
'add another list-like object to self'
def __iadd__(self, other):
self.extend(list(other)) return self
'multiply'
def __mul__(self, n):
return self.__class__((list(self) * n))
'multiply'
def __rmul__(self, n):
return self.__class__((list(self) * n))
'multiply'
def __imul__(self, n):
if (n <= 0): del self[:] else: cache = list(self) for i in range((n - 1)): self.extend(cache) return self
'cmp'
def __cmp__(self, other):
slen = len(self) for i in range(slen): try: c = cmp(self[i], other[i]) except IndexError: return 1 else: if c: return c return cmp(slen, len(other))
'Standard list count method'
def count(self, val):
count = 0 for i in self: if (val == i): count += 1 return count
'Standard list index method'
def index(self, val):
for i in xrange(0, len(self)): if (self[i] == val): return i raise ValueError(('%s not found in object' % str(val)))
'Standard list append method'
def append(self, val):
self[len(self):] = [val]
'Standard list extend method'
def extend(self, vals):
self[len(self):] = vals
'Standard list insert method'
def insert(self, index, val):
if (not isinstance(index, (int, long))): raise TypeError(('%s is not a legal index' % index)) self[index:index] = [val]
'Standard list pop method'
def pop(self, index=(-1)):
result = self[index] del self[index] return result
'Standard list remove method'
def remove(self, val):
del self[self.index(val)]
'Standard list reverse method'
def reverse(self):
self[:] = self[(-1)::(-1)]
'Standard list sort method'
def sort(self, cmp=cmp, key=None, reverse=False):
if key: temp = [(key(v), v) for v in self] temp.sort(cmp=cmp, key=(lambda x: x[0]), reverse=reverse) self[:] = [v[1] for v in temp] else: temp = list(self) temp.sort(cmp=cmp, reverse=reverse) self[:] = temp
'Assign values to a slice of the object'
def _set_slice(self, index, values):
try: iter(values) except TypeError: raise TypeError('can only assign an iterable to a slice') self._check_allowed(values) origLen = len(self) valueList = list(values) (start, stop, step) = index.indices(origLen) if (index.step is None): self._assi...
'Assign an extended slice by rebuilding entire list'
def _assign_extended_slice_rebuild(self, start, stop, step, valueList):
indexList = range(start, stop, step) if (len(valueList) != len(indexList)): raise ValueError(('attempt to assign sequence of size %d to extended slice of size %d' % (len(valueList), len(indexList)))) newLen = len(self) newVals = dict(zip(indexList, valueList))...
'Assign an extended slice by re-assigning individual items'
def _assign_extended_slice(self, start, stop, step, valueList):
indexList = range(start, stop, step) if (len(valueList) != len(indexList)): raise ValueError(('attempt to assign sequence of size %d to extended slice of size %d' % (len(valueList), len(indexList)))) for (i, val) in zip(indexList, valueList): self._set_sin...
'Assign a simple slice; Can assign slice of any length'
def _assign_simple_slice(self, start, stop, valueList):
origLen = len(self) stop = max(start, stop) newLen = (((origLen - stop) + start) + len(valueList)) def newItems(): for i in xrange((origLen + 1)): if (i == start): for val in valueList: (yield val) if (i < origLen): if (...
'Return the unit value and the default units specified from the given keyword arguments dictionary.'
def default_units(self, kwargs):
val = 0.0 for (unit, value) in kwargs.iteritems(): if (not isinstance(value, float)): value = float(value) if (unit in self.UNITS): val += (self.UNITS[unit] * value) default_unit = unit elif (unit in self.ALIAS): u = self.ALIAS[unit] ...
'Retrieves the unit attribute name for the given unit string. For example, if the given unit string is \'metre\', \'m\' would be returned. An exception is raised if an attribute cannot be found.'
@classmethod def unit_attname(cls, unit_str):
lower = unit_str.lower() if (unit_str in cls.UNITS): return unit_str elif (lower in cls.UNITS): return lower elif (lower in cls.LALIAS): return cls.LALIAS[lower] else: raise Exception(('Could not find a unit keyword associated with "%s"' % unit...