Geometry classes

The different PostGIS geometry object types are modeled by PPyGIS as Python classes. Methods provided by their common base class ppygis.Geometry allow Psycopg to transparently translate between the EWKB representation used when communicating with the database and Python objects.

Geometry — Base class

class ppygis.Geometry

This is the base class of all geometry objects. It provides common serialization and geometry access methods and must not be instantiated directly.

Serialization

static read_ewkb(value[, cursor])

Converts geometry from its EWKB representation to Python objects.

This method is called by Psycopg to convert geometry retrieved from the database. It can also be used to interpret data obtained using the PostgreSQL COPY TO bulk download command.

write_ewkb()

Converts geometry from Python objects to its EWKB representation.

This method can be used to prepare data for the PostgreSQL COPY FROM bulk upload command.

getquoted()

Converts geometry from Python objects to its EWKB representation and encloses the results in quotes.

This method is called by Psycopg to convert geometry sent to the database.

Geometry

srid

The SRID of the geometry object if defined. This can be modified, added and deleted.

Convenience properties

has_z

Boolean read-only property indicating whether the geometry object has a z coordinate.

has_m

Boolean read-only property indicating whether the geometry object has an m coordinate.

has_srid

Boolean read-only property indicating whether the geometry object’s SRID is defined.

Point — Single point

class ppygis.Point

This class holds a single point.

__init__(x, y[, z, m, srid])

Constructs a point. The point has two, three or four dimensions, depending on whether the optional z and m coordinates are provided. The point’s SRID can be provided or left undefined.

x

The x coordinate. This coordinate may be modified but not deleted.

y

The y coordinate. This coordinate may be modified but not deleted.

z

The z coordinate if the point has one. This coordinate can be modified, added and deleted.

m

The m coordinate if the point has one. This coordinate can be modified, added and deleted.

LineString — Single line

class ppygis.LineString

This class holds a line consisting of multiple points.

__init__(points[, srid])

Constructs a line from a sequence of ppygis.Point objects with identical dimensions. The line’s SRID can be provided or left undefined; those of the points are ignored.

points

A list of the points in the line. This may be modified, subject to the conditions described for the constructor.

Polygon — Single polygon

class ppygis.Polygon

This class holds a polygon consisting of one or more rings.

__init__(rings[, srid])

Constructs a polygon from a sequence of ppygis.LineString rings with identical dimensions. The polygon’s SRID can be provided or left undefined; those of the rings are ignored.

rings

A list of the rings in the polygon. This may be modified, subject to the conditions described for the constructor.

GeometryCollection — Collection of arbitrary geometry objects

class ppygis.GeometryCollection

This class holds a collection of geometry objects, allowing different types to be mixed.

__init__(geometries[, srid])

Constructs a collection from a sequence of geometry objects with identical dimensions. The sequence may contain any combination of object types, including ppygis.GeometryCollection. The collection’s SRID can be provided or left undefined. SRIDs defined for the collection and any of its geometry objects must be identical.

geometries

A list of the geometry objects in the collection. This may be modified, subject to the conditions described for the constructor.

MultiPoint — Collection of points

class ppygis.MultiPoint

This class holds a collection of points.

__init__(points[, srid])

Constructs a collection from a sequence of ppygis.Point objects with identical dimensions. The collection’s SRID can be provided or left undefined. SRIDs defined for the collection and any of its points must be identical.

points

A list of the points in the collection. This may be modified, subject to the conditions described for the constructor.

MultiLineString — Collection of lines

class ppygis.MultiLineString

This class holds a collection of lines.

__init__(lines[, srid])

Constructs a collection from a sequence of ppygis.LineString objects with identical dimensions. The collection’s SRID can be provided or left undefined. SRIDs defined for the collection and any of its lines must be identical.

lines

A list of the lines in the collection. This may be modified, subject to the conditions described for the constructor.

MultiPolygon — Collection of polygons

class ppygis.MultiPolygon

This class holds a collection of polygons.

__init__(polygons[, srid])

Constructs a collection from a sequence of ppygis.Polygon objects with identical dimensions. The collection’s SRID can be provided or left undefined. SRIDs defined for the collection and any of its polygons must be identical.

polygons

A list of the polygons in the collection. This may be modified, subject to the conditions described for the constructor.