:tocdepth: 3 :py:mod:`gws.base.shape` ======================== .. py:module:: gws.base.shape .. autoapi-nested-parse:: Shape object. The Shape object implements the IShape protocol (georefenced geometry). Internally, it holds a pointer to a Shapely geometry object and a Crs object. **Source code:** :source:`gws.base.shape` Package Contents ---------------- .. py:exception:: Error Bases: :py:obj:`gws.Error` GWS error. .. py:function:: from_bounds(bounds: gws.Bounds) -> gws.Shape Creates a polygon Shape from a Bounds object. :param bounds: A Bounds object. :returns: A Shape object. .. py:function:: from_dict(d: dict) -> gws.Shape Creates a Shape from a dictionary. :param d: A dictionary with the keys 'crs' and 'geometry'. :returns: A Shape object. .. py:function:: from_extent(extent: gws.Extent, crs: gws.Crs, always_xy=False) -> gws.Shape Creates a polygon Shape from an extent. :param extent: A hex-encoded WKB byte string. :param crs: A Crs object. :param always_xy: If ``True``, coordinates are assumed to be in the XY (lon/lat) order :returns: A Shape object. .. py:function:: from_geojson(geojson: dict, crs: gws.Crs, always_xy=False) -> gws.Shape Creates a shape object from a GeoJSON geometry dict. Parses a dict as a GeoJSON geometry object (https://www.rfc-editor.org/rfc/rfc7946#section-3.1). The coordinates are assumed to be in the projection order, unless ``always_xy`` is ``True``. :param geojson: A GeoJSON geometry dict :param crs: A Crs object. :param always_xy: If ``True``, coordinates are assumed to be in the XY (lon/lat) order :returns: A Shape object. .. py:function:: from_props(props: gws.Props) -> gws.Shape Creates a Shape from a properties object. :param props: A properties object. :returns: A Shape object. .. py:function:: from_wkb(wkb: bytes, default_crs: gws.Crs = None) -> gws.Shape Creates a shape object from a WKB byte string. :param wkb: A WKB or EWKB byte string. :param default_crs: Default Crs. :returns: A Shape object. .. py:function:: from_wkb_element(element: gws.lib.sa.geo.WKBElement, default_crs: gws.Crs = None) .. py:function:: from_wkb_hex(wkb: str, default_crs: gws.Crs = None) -> gws.Shape Creates a shape object from a hex-encoded WKB string. :param wkb: A hex-encoded WKB or EWKB byte string. :param default_crs: Default Crs. :returns: A Shape object. .. py:function:: from_wkt(wkt: str, default_crs: gws.Crs = None) -> gws.Shape Creates a shape object from a WKT string. :param wkt: A WKT or EWKT string. :param default_crs: Default Crs. :returns: A Shape object. .. py:function:: from_xy(x: float, y: float, crs: gws.Crs) -> gws.Shape Creates a point Shape from coordinates. :param x: X coordinate (lon/easting) :param y: Y coordinate (lat/northing) :param crs: A Crs object. :returns: A Shape object. .. py:class:: Props(*args, **kwargs) Bases: :py:obj:`gws.Props` Shape properties object. .. py:attribute:: crs :type: str .. py:attribute:: geometry :type: dict .. py:class:: Shape(geom, crs: gws.Crs) Bases: :py:obj:`gws.Shape` Geo-referenced geometry. .. py:attribute:: crs CRS of this shape. .. py:attribute:: geom :type: shapely.geometry.base.BaseGeometry .. py:attribute:: type Geometry type. .. py:attribute:: x X-coordinate for Point geometries, None otherwise. .. py:attribute:: y Y-coordinate for Point geometries, None otherwise. .. py:method:: area() Computes the area of the geometry. .. py:method:: bounds() Returns a Bounds object that bounds this shape. .. py:method:: centroid() Returns a centroid as a Point shape. .. py:method:: contains(other) Returns True if this shape contains the other. .. py:method:: covered_by(other) Returns True if this shape is covered by the other. .. py:method:: covers(other) Returns True if this shape covers the other. .. py:method:: crosses(other) Returns True if this shape crosses the other. .. py:method:: disjoint(other) Returns True if this shape does not intersect with the other. .. py:method:: equals(other) Returns True if this shape is equal to the other. .. py:method:: intersection(*others) Computes an intersection of this shape and other shapes. .. py:method:: intersects(other) Returns True if this shape intersects with the other. .. py:method:: is_empty() Returns True if this shape is empty. .. py:method:: is_ring() Returns True if this shape is a ring. .. py:method:: is_simple() Returns True if this shape is 'simple'. .. py:method:: is_valid() Returns True if this shape is valid. .. py:method:: overlaps(other) Returns True if this shape overlaps the other. .. py:method:: to_ewkb() Returns an EWKB representation of this shape as a binary string. .. py:method:: to_ewkb_hex() Returns an EWKB representation of this shape as a hex string. .. py:method:: to_ewkt() Returns an EWKT representation of this shape. .. py:method:: to_geojson(always_xy=False) Returns a GeoJSON representation of this shape. .. py:method:: to_multi() Converts a singly-geometry shape to a multi-geometry one. .. py:method:: to_props() Returns a GeoJSON representation of this shape. .. py:method:: to_type(new_type: gws.GeometryType) Converts a geometry to another type. .. py:method:: to_wkb() Returns a WKB representation of this shape as a binary string. .. py:method:: to_wkb_hex() Returns a WKB representation of this shape as a hex string. .. py:method:: to_wkt() Returns a WKT representation of this shape. .. py:method:: tolerance_polygon(tolerance=None, quad_segs=None) Builds a buffer polygon around the shape. .. py:method:: touches(other) Returns True if this shape touches the other. .. py:method:: transformed_to(crs) Returns this shape transformed to another CRS. .. py:method:: union(others) Computes a union of this shape and other shapes. .. py:method:: within(other) Returns True if this shape is within the other.