gws.base.shape

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: gws.base.shape

Package Contents

exception gws.base.shape.Error

Bases: gws.Error

GWS error.

gws.base.shape.from_bounds(bounds: gws.Bounds) gws.Shape

Creates a polygon Shape from a Bounds object.

Parameters:

bounds – A Bounds object.

Returns:

A Shape object.

gws.base.shape.from_dict(d: dict) gws.Shape

Creates a Shape from a dictionary.

Parameters:

d – A dictionary with the keys ‘crs’ and ‘geometry’.

Returns:

A Shape object.

gws.base.shape.from_extent(extent: gws.Extent, crs: gws.Crs, always_xy=False) gws.Shape

Creates a polygon Shape from an extent.

Parameters:
  • extent – A hex-encoded WKB byte string.

  • crs – A Crs object.

  • always_xy – If True, coordinates are assumed to be in the XY (lon/lat) order

Returns:

A Shape object.

gws.base.shape.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.

Parameters:
  • geojson – A GeoJSON geometry dict

  • crs – A Crs object.

  • always_xy – If True, coordinates are assumed to be in the XY (lon/lat) order

Returns:

A Shape object.

gws.base.shape.from_props(props: gws.Props) gws.Shape

Creates a Shape from a properties object.

Parameters:

props – A properties object.

Returns:

A Shape object.

gws.base.shape.from_wkb(wkb: bytes, default_crs: gws.Crs = None) gws.Shape

Creates a shape object from a WKB byte string.

Parameters:
  • wkb – A WKB or EWKB byte string.

  • default_crs – Default Crs.

Returns:

A Shape object.

gws.base.shape.from_wkb_element(element: gws.lib.sa.geo.WKBElement, default_crs: gws.Crs = None)
gws.base.shape.from_wkb_hex(wkb: str, default_crs: gws.Crs = None) gws.Shape

Creates a shape object from a hex-encoded WKB string.

Parameters:
  • wkb – A hex-encoded WKB or EWKB byte string.

  • default_crs – Default Crs.

Returns:

A Shape object.

gws.base.shape.from_wkt(wkt: str, default_crs: gws.Crs = None) gws.Shape

Creates a shape object from a WKT string.

Parameters:
  • wkt – A WKT or EWKT string.

  • default_crs – Default Crs.

Returns:

A Shape object.

gws.base.shape.from_xy(x: float, y: float, crs: gws.Crs) gws.Shape

Creates a point Shape from coordinates.

Parameters:
  • x – X coordinate (lon/easting)

  • y – Y coordinate (lat/northing)

  • crs – A Crs object.

Returns:

A Shape object.

class gws.base.shape.Props(*args, **kwargs)

Bases: gws.Props

Shape properties object.

crs: str
geometry: dict
class gws.base.shape.Shape(geom, crs: gws.Crs)

Bases: gws.Shape

Geo-referenced geometry.

geom: shapely.geometry.base.BaseGeometry
area()

Computes the area of the geometry.

bounds()

Returns a Bounds object that bounds this shape.

centroid()

Returns a centroid as a Point shape.

contains(other)

Returns True if this shape contains the other.

covered_by(other)

Returns True if this shape is covered by the other.

covers(other)

Returns True if this shape covers the other.

crosses(other)

Returns True if this shape crosses the other.

disjoint(other)

Returns True if this shape does not intersect with the other.

equals(other)

Returns True if this shape is equal to the other.

intersection(*others)

Computes an intersection of this shape and other shapes.

intersects(other)

Returns True if this shape intersects with the other.

is_empty()

Returns True if this shape is empty.

is_ring()

Returns True if this shape is a ring.

is_simple()

Returns True if this shape is ‘simple’.

is_valid()

Returns True if this shape is valid.

overlaps(other)

Returns True if this shape overlaps the other.

to_ewkb()

Returns an EWKB representation of this shape as a binary string.

to_ewkb_hex()

Returns an EWKB representation of this shape as a hex string.

to_ewkt()

Returns an EWKT representation of this shape.

to_geojson(always_xy=False)

Returns a GeoJSON representation of this shape.

to_multi()

Converts a singly-geometry shape to a multi-geometry one.

to_props()

Returns a GeoJSON representation of this shape.

to_type(new_type: gws.GeometryType)

Converts a geometry to another type.

to_wkb()

Returns a WKB representation of this shape as a binary string.

to_wkb_hex()

Returns a WKB representation of this shape as a hex string.

to_wkt()

Returns a WKT representation of this shape.

tolerance_polygon(tolerance, quad_segs=None)

Builds a buffer polygon around the shape.

touches(other)

Returns True if this shape touches the other.

transformed_to(crs)

Returns this shape transformed to another CRS.

union(others)

Computes a union of this shape and other shapes.

within(other)

Returns True if this shape is within the other.