plpygis package¶
- class plpygis.geometry.Geometry(wkb, srid=None, dimz=False, dimm=False)¶
Bases:
objectA representation of a PostGIS geometry.
PostGIS geometries are either an OpenGIS Consortium Simple Features for SQL specification type or a PostGIS extended type. The object’s canonical form is stored in WKB or EWKB format along with an SRID and flags indicating whether the coordinates are 3DZ, 3DM or 4D.
Geometryobjects can be created in a number of ways. In all cases, a subclass for the particular geometry type will be instantiated.From an (E)WKB:
>>> Geometry(b'\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00') <Point: 'geometry(Point)'>
From the hexadecimal string representation of an (E)WKB:
>>> Geometry("0101000080000000000000000000000000000000000000000000000000") <Point: 'geometry(PointZ)'>
The response above indicates an instance of the
Pointclass has been created and that it represents a PostGISgeometry(PointZ)type.From a GeoJSON:
>>> Geometry.from_geojson({'type': 'Point', 'coordinates': (0.0, 0.0)}) <Point: 'geometry(Point,4326)'>
From a Shapely object:
>>> from shapely import Point >>> point = Point(0, 0) >>> Geometry.from_shapely(point, 3857) <Point: 'geometry(Point,3857)'>
From any object supporting
__geo_interface__:>>> from shapefile import Reader >>> feature = Reader("test/multipoint.shp").shape(0) >>> Geometry.shape(feature) <MultiPoint: 'geometry(MultiPoint)'>
A
Geometrycan be read as long as it is one of the following types:Point,LineString,Polygon,MultiPoint,MultiLineString,MultiPolygonorGeometryCollection. The M dimension will be preserved.- static from_geojson(geojson, srid=4326)¶
Create a Geometry from a GeoJSON. The SRID can be overridden from the expected 4326.
- static from_wkt(wkt, srid=None)¶
Create a Geometry from a WKT or EWKT.
- static from_shapely(sgeom, srid=None)¶
Create a Geometry from a Shapely geometry and the specified SRID.
The Shapely geometry will not be modified.
- static shape(shape, srid=None)¶
Create a Geometry using
__geo_interface__and the specified SRID.
- property type¶
The geometry type.
- property srid¶
The geometry SRID.
- property coordinates¶
Get the geometry’s coordinates.
- property geojson¶
Get the geometry as a GeoJSON dict. There is no check that the GeoJSON is using an SRID of 4326.
- property wkb¶
Get the geometry as an WKB.
- property wkt¶
Get the geometry as an WKT.
- property ewkb¶
Get the geometry as an EWKB.
- property ewkt¶
Get the geometry as an EWKT.
- property shapely¶
Get the geometry as a Shapely geometry. If the geometry has an SRID, the Shapely object will be created with it set.
- property bounds¶
Get the minimum and maximum extents of the geometry: (minx, miny, maxx, maxy).
- property postgis_type¶
Get the type of the geometry in PostGIS format, including additional dimensions and SRID if they exist.
- class plpygis.geometry.Point(wkb, srid=None, dimz=False, dimm=False)¶
Bases:
GeometryA representation of a PostGIS Point.
Pointobjects can be created directly.>>> Point((0, -52, 5), dimm=True, srid=4326) <Point: 'geometry(PointM,4326)'>
The
dimzanddimmparameters will indicate how to interpret the coordinates that have been passed as the first argument. By default, the third coordinate will be interpreted as representing the Z dimension.- property x¶
X coordinate.
- property y¶
M coordinate.
- property z¶
Z coordinate.
- property m¶
M coordinate.
- property dimz¶
Whether the geometry has a Z dimension.
- Getter:
Trueif the geometry has a Z dimension.- Setter:
Add or remove the Z dimension.
- Return type:
bool
- property dimm¶
Whether the geometry has an M dimension.
- Getter:
Trueif the geometry has an M dimension.- Setter:
Add or remove the M dimension.
- Return type:
bool
- property bounds¶
Get the minimum and maximum extents of the geometry: (minx, miny, maxx, maxy).
- property coordinates¶
Get the geometry’s coordinates.
- property ewkb¶
Get the geometry as an EWKB.
- property ewkt¶
Get the geometry as an EWKT.
- static from_geojson(geojson, srid=4326)¶
Create a Geometry from a GeoJSON. The SRID can be overridden from the expected 4326.
- static from_shapely(sgeom, srid=None)¶
Create a Geometry from a Shapely geometry and the specified SRID.
The Shapely geometry will not be modified.
- static from_wkt(wkt, srid=None)¶
Create a Geometry from a WKT or EWKT.
- property geojson¶
Get the geometry as a GeoJSON dict. There is no check that the GeoJSON is using an SRID of 4326.
- property postgis_type¶
Get the type of the geometry in PostGIS format, including additional dimensions and SRID if they exist.
- static shape(shape, srid=None)¶
Create a Geometry using
__geo_interface__and the specified SRID.
- property shapely¶
Get the geometry as a Shapely geometry. If the geometry has an SRID, the Shapely object will be created with it set.
- property srid¶
The geometry SRID.
- property type¶
The geometry type.
- property wkb¶
Get the geometry as an WKB.
- property wkt¶
Get the geometry as an WKT.
- class plpygis.geometry.LineString(wkb, srid=None, dimz=False, dimm=False)¶
Bases:
GeometryA representation of a PostGIS Line.
LineStringobjects can be created directly.>>> LineString([(0, 0, 0, 0), (1, 1, 0, 0), (2, 2, 0, 0)]) <LineString: 'geometry(LineStringZM)'>
The
dimzanddimmparameters will indicate how to interpret the coordinates that have been passed as the first argument. By default, the third coordinate will be interpreted as representing the Z dimension.- property vertices¶
List of vertices that comprise the line.
- property dimz¶
Whether the geometry has a Z dimension.
- Getter:
Trueif the geometry has a Z dimension.- Setter:
Add or remove the Z dimension from this and all vertices in the line.
- Return type:
bool
- property dimm¶
Whether the geometry has a M dimension.
- Getter:
Trueif the geometry has a M dimension.- Setter:
Add or remove the M dimension from this and all vertices in the line.
- Return type:
bool
- property bounds¶
Get the minimum and maximum extents of the geometry: (minx, miny, maxx, maxy).
- property coordinates¶
Get the geometry’s coordinates.
- property ewkb¶
Get the geometry as an EWKB.
- property ewkt¶
Get the geometry as an EWKT.
- static from_geojson(geojson, srid=4326)¶
Create a Geometry from a GeoJSON. The SRID can be overridden from the expected 4326.
- static from_shapely(sgeom, srid=None)¶
Create a Geometry from a Shapely geometry and the specified SRID.
The Shapely geometry will not be modified.
- static from_wkt(wkt, srid=None)¶
Create a Geometry from a WKT or EWKT.
- property geojson¶
Get the geometry as a GeoJSON dict. There is no check that the GeoJSON is using an SRID of 4326.
- property postgis_type¶
Get the type of the geometry in PostGIS format, including additional dimensions and SRID if they exist.
- static shape(shape, srid=None)¶
Create a Geometry using
__geo_interface__and the specified SRID.
- property shapely¶
Get the geometry as a Shapely geometry. If the geometry has an SRID, the Shapely object will be created with it set.
- property srid¶
The geometry SRID.
- property type¶
The geometry type.
- property wkb¶
Get the geometry as an WKB.
- property wkt¶
Get the geometry as an WKT.
- class plpygis.geometry.Polygon(wkb, srid=None, dimz=False, dimm=False)¶
Bases:
GeometryA representation of a PostGIS Polygon.
Polygonobjects can be created directly.>>> Polygon([[(0, 0, 0), (1, 0, 0), (1, 1, 0), (0, 1, 0), (0, 0, 0)]]) <Polygon: 'geometry(PolygonZ)'>
The first polygon in the list of linear rings is the exterior ring, while any subsequent rings are interior boundaries.
The
dimzanddimmparameters will indicate how to interpret the coordinates that have been passed as the first argument. By default, the third coordinate will be interpreted as representing the Z dimension.- property rings¶
List of linearrings that comprise the polygon.
- property exterior¶
The exterior ring of the polygon.
- property interior¶
A list of interior rings of the polygon.
- property bounds¶
Get the minimum and maximum extents of the geometry: (minx, miny, maxx, maxy).
- property coordinates¶
Get the geometry’s coordinates.
- property ewkb¶
Get the geometry as an EWKB.
- property ewkt¶
Get the geometry as an EWKT.
- static from_geojson(geojson, srid=4326)¶
Create a Geometry from a GeoJSON. The SRID can be overridden from the expected 4326.
- static from_shapely(sgeom, srid=None)¶
Create a Geometry from a Shapely geometry and the specified SRID.
The Shapely geometry will not be modified.
- static from_wkt(wkt, srid=None)¶
Create a Geometry from a WKT or EWKT.
- property geojson¶
Get the geometry as a GeoJSON dict. There is no check that the GeoJSON is using an SRID of 4326.
- property postgis_type¶
Get the type of the geometry in PostGIS format, including additional dimensions and SRID if they exist.
- static shape(shape, srid=None)¶
Create a Geometry using
__geo_interface__and the specified SRID.
- property shapely¶
Get the geometry as a Shapely geometry. If the geometry has an SRID, the Shapely object will be created with it set.
- property srid¶
The geometry SRID.
- property type¶
The geometry type.
- property wkb¶
Get the geometry as an WKB.
- property wkt¶
Get the geometry as an WKT.
- property dimz¶
Whether the geometry has a Z dimension.
- Getter:
Trueif the geometry has a Z dimension.- Setter:
Add or remove the Z dimension from this and all linear rings in the polygon.
- Return type:
bool
- property dimm¶
LineString([(0, 0, 0, 0), (1, 1, 0, 0), (2, 2, 0, 0)]) Whether the geometry has a M dimension.
- Getter:
Trueif the geometry has a M dimension.- Setter:
Add or remove the M dimension from this and all linear rings in the polygon.
- Return type:
bool
- class plpygis.geometry.MultiPoint(wkb, srid=None, dimz=False, dimm=False)¶
Bases:
_MultiGeometryA representation of a PostGIS MultiPoint.
MultiPointobjects can be created directly from a list ofPointobjects.>>> p1 = Point((0, 0, 0)) >>> p2 = Point((1, 1, 0)) >>> MultiPoint([p1, p2]) <MultiPoint: 'geometry(MultiPointZ)'>
The SRID and dimensionality of all geometries in the collection must be identical.
- property bounds¶
Get the minimum and maximum extents of the geometry: (minx, miny, maxx, maxy).
- property coordinates¶
Get the geometry’s coordinates.
- property dimm¶
Whether the geometry has an M dimension.
- Getter:
Trueif the geometry has an M dimension.- Setter:
Add or remove the M dimension from this and all geometries in the collection.
- Return type:
bool
- property dimz¶
Whether the geometry has a Z dimension.
- Getter:
Trueif the geometry has a Z dimension.- Setter:
Add or remove the Z dimension from this and all geometries in the collection.
- Return type:
bool
- property ewkb¶
Get the geometry as an EWKB.
- property ewkt¶
Get the geometry as an EWKT.
- static from_geojson(geojson, srid=4326)¶
Create a Geometry from a GeoJSON. The SRID can be overridden from the expected 4326.
- static from_shapely(sgeom, srid=None)¶
Create a Geometry from a Shapely geometry and the specified SRID.
The Shapely geometry will not be modified.
- static from_wkt(wkt, srid=None)¶
Create a Geometry from a WKT or EWKT.
- property geojson¶
Get the geometry as a GeoJSON dict. There is no check that the GeoJSON is using an SRID of 4326.
- property geometries¶
List of all component geometries.
- pop(index=-1)¶
Remove a geometry from the multigeometry.
- property postgis_type¶
Get the type of the geometry in PostGIS format, including additional dimensions and SRID if they exist.
- static shape(shape, srid=None)¶
Create a Geometry using
__geo_interface__and the specified SRID.
- property shapely¶
Get the geometry as a Shapely geometry. If the geometry has an SRID, the Shapely object will be created with it set.
- property srid¶
The geometry SRID.
- property type¶
The geometry type.
- property wkb¶
Get the geometry as an WKB.
- property wkt¶
Get the geometry as an WKT.
- property points¶
List of all component points.
- class plpygis.geometry.MultiLineString(wkb, srid=None, dimz=False, dimm=False)¶
Bases:
_MultiGeometryA representation of a PostGIS MultiLineString
MultiLineStringobjects can be created directly from a list ofLineStringobjects.>>> l1 = LineString([(1, 1, 0), (2, 2, 0)], dimm=True) >>> l2 = LineString([(0, 0, 0), (0, 1, 0)], dimm=True) >>> MultiLineString([l1, l2]) <MultiLineString: 'geometry(MultiLineStringM)'>
The SRID and dimensionality of all geometries in the collection must be identical.
- property bounds¶
Get the minimum and maximum extents of the geometry: (minx, miny, maxx, maxy).
- property coordinates¶
Get the geometry’s coordinates.
- property dimm¶
Whether the geometry has an M dimension.
- Getter:
Trueif the geometry has an M dimension.- Setter:
Add or remove the M dimension from this and all geometries in the collection.
- Return type:
bool
- property dimz¶
Whether the geometry has a Z dimension.
- Getter:
Trueif the geometry has a Z dimension.- Setter:
Add or remove the Z dimension from this and all geometries in the collection.
- Return type:
bool
- property ewkb¶
Get the geometry as an EWKB.
- property ewkt¶
Get the geometry as an EWKT.
- static from_geojson(geojson, srid=4326)¶
Create a Geometry from a GeoJSON. The SRID can be overridden from the expected 4326.
- static from_shapely(sgeom, srid=None)¶
Create a Geometry from a Shapely geometry and the specified SRID.
The Shapely geometry will not be modified.
- static from_wkt(wkt, srid=None)¶
Create a Geometry from a WKT or EWKT.
- property geojson¶
Get the geometry as a GeoJSON dict. There is no check that the GeoJSON is using an SRID of 4326.
- property geometries¶
List of all component geometries.
- pop(index=-1)¶
Remove a geometry from the multigeometry.
- property postgis_type¶
Get the type of the geometry in PostGIS format, including additional dimensions and SRID if they exist.
- static shape(shape, srid=None)¶
Create a Geometry using
__geo_interface__and the specified SRID.
- property shapely¶
Get the geometry as a Shapely geometry. If the geometry has an SRID, the Shapely object will be created with it set.
- property srid¶
The geometry SRID.
- property type¶
The geometry type.
- property wkb¶
Get the geometry as an WKB.
- property wkt¶
Get the geometry as an WKT.
- MULTITYPE¶
alias of
LineString
- property linestrings¶
List of all component lines.
- class plpygis.geometry.MultiPolygon(wkb, srid=None, dimz=False, dimm=False)¶
Bases:
_MultiGeometryA representation of a PostGIS MultiPolygon.
MultiPolygonobjects can be created directly from a list ofPolygonobjects.>>> p1 = Polygon([[(0, 0), (1, 0), (1, 1), (0, 1), (0, 0)]]) >>> p2 = Polygon([[(2, 2), (3, 2), (3, 3), (2, 3), (2, 2)]]) >>> MultiPolygon([p1, p2], srid=4326) <MultiPolygon: 'geometry(MultiPolygon,4326)'>
The SRID and dimensionality of all geometries in the collection must be identical.
- property bounds¶
Get the minimum and maximum extents of the geometry: (minx, miny, maxx, maxy).
- property coordinates¶
Get the geometry’s coordinates.
- property dimm¶
Whether the geometry has an M dimension.
- Getter:
Trueif the geometry has an M dimension.- Setter:
Add or remove the M dimension from this and all geometries in the collection.
- Return type:
bool
- property dimz¶
Whether the geometry has a Z dimension.
- Getter:
Trueif the geometry has a Z dimension.- Setter:
Add or remove the Z dimension from this and all geometries in the collection.
- Return type:
bool
- property ewkb¶
Get the geometry as an EWKB.
- property ewkt¶
Get the geometry as an EWKT.
- static from_geojson(geojson, srid=4326)¶
Create a Geometry from a GeoJSON. The SRID can be overridden from the expected 4326.
- static from_shapely(sgeom, srid=None)¶
Create a Geometry from a Shapely geometry and the specified SRID.
The Shapely geometry will not be modified.
- static from_wkt(wkt, srid=None)¶
Create a Geometry from a WKT or EWKT.
- property geojson¶
Get the geometry as a GeoJSON dict. There is no check that the GeoJSON is using an SRID of 4326.
- property geometries¶
List of all component geometries.
- pop(index=-1)¶
Remove a geometry from the multigeometry.
- property postgis_type¶
Get the type of the geometry in PostGIS format, including additional dimensions and SRID if they exist.
- static shape(shape, srid=None)¶
Create a Geometry using
__geo_interface__and the specified SRID.
- property shapely¶
Get the geometry as a Shapely geometry. If the geometry has an SRID, the Shapely object will be created with it set.
- property srid¶
The geometry SRID.
- property type¶
The geometry type.
- property wkb¶
Get the geometry as an WKB.
- property wkt¶
Get the geometry as an WKT.
- property polygons¶
List of all component polygons.
- class plpygis.geometry.GeometryCollection(wkb, srid=None, dimz=False, dimm=False)¶
Bases:
_MultiGeometryA representation of a PostGIS GeometryCollection.
GeometryCollectionobjects can be created directly from a list of geometries, including other collections.>>> p = Point((0, 0, 0)) >>> l = LineString([(1, 1, 0), (2, 2, 0)]) >>> GeometryCollection([p, l]) <GeometryCollection: 'geometry(GeometryCollectionZ)'>
The SRID and dimensionality of all geometries in the collection must be identical.
- property bounds¶
Get the minimum and maximum extents of the geometry: (minx, miny, maxx, maxy).
- property coordinates¶
Get the geometry’s coordinates.
- property dimm¶
Whether the geometry has an M dimension.
- Getter:
Trueif the geometry has an M dimension.- Setter:
Add or remove the M dimension from this and all geometries in the collection.
- Return type:
bool
- property dimz¶
Whether the geometry has a Z dimension.
- Getter:
Trueif the geometry has a Z dimension.- Setter:
Add or remove the Z dimension from this and all geometries in the collection.
- Return type:
bool
- property ewkb¶
Get the geometry as an EWKB.
- property ewkt¶
Get the geometry as an EWKT.
- static from_geojson(geojson, srid=4326)¶
Create a Geometry from a GeoJSON. The SRID can be overridden from the expected 4326.
- static from_shapely(sgeom, srid=None)¶
Create a Geometry from a Shapely geometry and the specified SRID.
The Shapely geometry will not be modified.
- static from_wkt(wkt, srid=None)¶
Create a Geometry from a WKT or EWKT.
- property geojson¶
Get the geometry as a GeoJSON dict. There is no check that the GeoJSON is using an SRID of 4326.
- property geometries¶
List of all component geometries.
- pop(index=-1)¶
Remove a geometry from the multigeometry.
- property postgis_type¶
Get the type of the geometry in PostGIS format, including additional dimensions and SRID if they exist.
- static shape(shape, srid=None)¶
Create a Geometry using
__geo_interface__and the specified SRID.
- property shapely¶
Get the geometry as a Shapely geometry. If the geometry has an SRID, the Shapely object will be created with it set.
- property srid¶
The geometry SRID.
- property type¶
The geometry type.
- property wkb¶
Get the geometry as an WKB.
- property wkt¶
Get the geometry as an WKT.
- exception plpygis.exceptions.PlpygisError(msg)¶
Bases:
ExceptionBasic exception for
plpygis.
- exception plpygis.exceptions.CoordinateError(geom, msg=None)¶
Bases:
PlpygisErrorException for problems in the coordinates of geometries.
- exception plpygis.exceptions.CollectionError(msg=None)¶
Bases:
PlpygisErrorException for problems with geometries in collection types.
- exception plpygis.exceptions.DependencyError(dep)¶
Bases:
PlpygisError,ImportErrorException for a missing dependency.
- exception plpygis.exceptions.WkbError(msg=None)¶
Bases:
PlpygisErrorException for problems in parsing WKBs.
- exception plpygis.exceptions.WktError(reader, msg=None, expected=None)¶
Bases:
PlpygisErrorException for problems in parsing WKTs.
- exception plpygis.exceptions.DimensionalityError(msg=None)¶
Bases:
PlpygisErrorException for problems in dimensionality of geometries.
- exception plpygis.exceptions.SridError(msg=None)¶
Bases:
PlpygisErrorException for problems in dimensionality of geometries.
- exception plpygis.exceptions.GeojsonError(msg=None)¶
Bases:
PlpygisErrorException for problems in GeoJSONs.