Transformer.transform_geometry_collection

classmethod Transformer.transform_geometry_collection(geometry, mode=1, to_wkt=False)[source]

Transform a collection of geometry from dict into a shapely.geometry object.

Parameters:
  • geometry (list | dict) – geometry data for a feature of GeometryCollection

  • mode (int) –

    indicate the way of parsing the input;

    • when mode=1 (default), the input geometry should be directly accessible and would be in the format of {'type': <shape type>, 'coordinates': <coordinates>} or as a row of a pandas.DataFrame;

    • when mode=2, the input geometry is in the GeoJSON format

  • to_wkt (bool) – whether to represent the geometry in the WKT (well-known text) format, defaults to False

Returns:

reformatted geometry data

Return type:

shapely.geometry.base.HeterogeneousGeometrySequence | dict | str

Examples:

>>> from pydriosm.reader import PBFReadParse
>>> from shapely.geometry import GeometryCollection

>>> g1_dat_ = {
...     'type': 'GeometryCollection',
...     'geometries': [
...         {'type': 'Point', 'coordinates': [-0.5096176, 52.6605168]},
...         {'type': 'Point', 'coordinates': [-0.5097337, 52.6605812]}
...     ]
... }
>>> g1_dat = g1_dat_['geometries']
>>> g1_data = PBFReadParse.transform_geometry_collection(g1_dat)
>>> type(g1_data)
shapely.geometry.collection.GeometryCollection
>>> g1_data.wkt
'GEOMETRYCOLLECTION (POINT (-0.5096176 52.6605168), POINT (-0.5097337 52.6605812))'

>>> g2_dat = {
...     'type': 'Feature',
...     'geometry': {
...         'type': 'GeometryCollection',
...         'geometries': [
...             {'type': 'Point', 'coordinates': [-0.5096176, 52.6605168]},
...             {'type': 'Point', 'coordinates': [-0.5097337, 52.6605812]}]
...      },
...     'properties': {
...         'osm_id': '256254',
...         'name': 'Fife Close',
...         'type': 'site',
...         'other_tags': '"naptan:StopAreaCode"=>"270G02701525"'
...     },
...     'id': 256254
... }
>>> g2_data = PBFReadParse.transform_geometry_collection(g2_dat, mode=2)
>>> type(g2_data)
dict
>>> list(g2_data.keys())
['type', 'geometry', 'properties', 'id']
>>> g2_data['geometry']
'GEOMETRYCOLLECTION (POINT (-0.5096176 52.6605168), POINT (-0.5097337 52.6605812))'