.. $Id: classes.rst 4 2011-04-13 16:01:24Z plush $ Geometry classes ================ .. module:: ppygis The different PostGIS geometry object types are modeled by PPyGIS as Python classes. Methods provided by their common base class :class:`ppygis.Geometry` allow Psycopg to transparently translate between the EWKB representation used when communicating with the database and Python objects. :class:`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. .. rubric:: Serialization .. staticmethod:: 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. .. method:: 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. .. method:: 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. .. rubric:: Geometry .. attribute:: srid The SRID of the geometry object if defined. This can be modified, added and deleted. .. rubric:: Convenience properties .. attribute:: has_z Boolean read-only property indicating whether the geometry object has a *z* coordinate. .. attribute:: has_m Boolean read-only property indicating whether the geometry object has an *m* coordinate. .. attribute:: has_srid Boolean read-only property indicating whether the geometry object's SRID is defined. :class:`Point` --- Single point ------------------------------- .. class:: ppygis.Point This class holds a single point. .. method:: __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. .. attribute:: x The *x* coordinate. This coordinate may be modified but not deleted. .. attribute:: y The *y* coordinate. This coordinate may be modified but not deleted. .. attribute:: z The *z* coordinate if the point has one. This coordinate can be modified, added and deleted. .. attribute:: m The *m* coordinate if the point has one. This coordinate can be modified, added and deleted. :class:`LineString` --- Single line ----------------------------------- .. class:: ppygis.LineString This class holds a line consisting of multiple points. .. method:: __init__(points[, srid]) Constructs a line from a sequence of :class:`ppygis.Point` objects with identical dimensions. The line's SRID can be provided or left undefined; those of the points are ignored. .. attribute:: points A :class:`list` of the points in the line. This may be modified, subject to the conditions described for the constructor. :class:`Polygon` --- Single polygon ----------------------------------- .. class:: ppygis.Polygon This class holds a polygon consisting of one or more rings. .. method:: __init__(rings[, srid]) Constructs a polygon from a sequence of :class:`ppygis.LineString` rings with identical dimensions. The polygon's SRID can be provided or left undefined; those of the rings are ignored. .. attribute:: rings A :class:`list` of the rings in the polygon. This may be modified, subject to the conditions described for the constructor. :class:`GeometryCollection` --- Collection of arbitrary geometry objects ------------------------------------------------------------------------ .. class:: ppygis.GeometryCollection This class holds a collection of geometry objects, allowing different types to be mixed. .. method:: __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 :class:`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. .. attribute:: geometries A :class:`list` of the geometry objects in the collection. This may be modified, subject to the conditions described for the constructor. :class:`MultiPoint` --- Collection of points -------------------------------------------- .. class:: ppygis.MultiPoint This class holds a collection of points. .. method:: __init__(points[, srid]) Constructs a collection from a sequence of :class:`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. .. attribute:: points A :class:`list` of the points in the collection. This may be modified, subject to the conditions described for the constructor. :class:`MultiLineString` --- Collection of lines ------------------------------------------------ .. class:: ppygis.MultiLineString This class holds a collection of lines. .. method:: __init__(lines[, srid]) Constructs a collection from a sequence of :class:`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. .. attribute:: lines A :class:`list` of the lines in the collection. This may be modified, subject to the conditions described for the constructor. :class:`MultiPolygon` --- Collection of polygons ------------------------------------------------ .. class:: ppygis.MultiPolygon This class holds a collection of polygons. .. method:: __init__(polygons[, srid]) Constructs a collection from a sequence of :class:`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. .. attribute:: polygons A :class:`list` of the polygons in the collection. This may be modified, subject to the conditions described for the constructor.