spatialdata.models.ShapesModel#

class spatialdata.models.ShapesModel#

Attributes table#

ATTRS_KEY

GEOMETRY_KEY

GEOS_KEY

NAME_KEY

RADIUS_KEY

TRANSFORM_KEY

TYPE_KEY

Methods table#

parse(data, **kwargs)

Parse shapes data.

validate(data)

Validate data.

validate_shapes_not_mixed_types(gdf)

Check that the Shapes element is either composed of Point or Polygon/MultiPolygon.

Attributes#

ShapesModel.ATTRS_KEY = 'spatialdata_attrs'#
ShapesModel.GEOMETRY_KEY = 'geometry'#
ShapesModel.GEOS_KEY = 'geos'#
ShapesModel.NAME_KEY = 'name'#
ShapesModel.RADIUS_KEY = 'radius'#
ShapesModel.TRANSFORM_KEY = 'transform'#
ShapesModel.TYPE_KEY = 'type'#

Methods#

classmethod ShapesModel.parse(data, **kwargs)#

Parse shapes data.

Parameters:
  • data (Any) –

    Data to parse:

    • If numpy.ndarray, it assumes the shapes are parsed as ragged arrays, in case of (Multi)`Polygons`. Therefore additional arguments offsets and geometry must be provided

    • if Path or str, it’s read as a GeoJSON file.

    • If geopandas.GeoDataFrame, it’s validated. The object needs to have a column called geometry which is a geopandas.GeoSeries or shapely objects. Valid options are combinations of Polygon/ MultiPolygon or Point. If the geometries are Point, there must be another column called radius.

  • geometry

    Geometry type of the shapes. The following geometries are supported:

    • 0: Circles

    • 3: Polygon

    • 6: MultiPolygon

  • offsets – In the case of (Multi)`Polygons` shapes, in order to initialize the shapes from their ragged array representation, the offsets of the polygons must be provided. Alternatively you can call the parser as ShapesModel.parse(data), where data is a GeoDataFrame object and ignore the offset paramter (recommended).

  • radius – Size of the Circles. It must be provided if the shapes are Circles.

  • index – Index of the shapes, must be of type str. If None, it’s generated automatically.

  • transformations – Transformations of shapes.

  • kwargs (Any) – Additional arguments for GeoJSON reader.

Return type:

GeoDataFrame

Returns:

: geopandas.GeoDataFrame

classmethod ShapesModel.validate(data)#

Validate data.

Parameters:

data (GeoDataFrame) – geopandas.GeoDataFrame to validate.

Return type:

None

Returns:

: None

classmethod ShapesModel.validate_shapes_not_mixed_types(gdf)#

Check that the Shapes element is either composed of Point or Polygon/MultiPolygon.

Parameters:

gdf (GeoDataFrame) – The Shapes element.

Raises:

ValueError – When the geometry column composing the object does not satisfy the type requirements.

Return type:

None

Notes

This function is not called by ShapesModel.validate() because computing the unique types by default could be expensive.