Transformer.transform_unitary_geometry
- classmethod Transformer.transform_unitary_geometry(geometry, mode=1, to_wkt=False)[source]
Transform a unitary geometry from dict into a shapely.geometry object.
- Parameters:
geometry (dict | pandas.DataFrame) – geometry data for a feature of one of the geometry types including
'Point'
,'LineString'
,'MultiLineString'
and'MultiPolygon'
mode (int) –
indicate the way of parsing the input;
when
mode=1
(default), the inputgeometry
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 inputgeometry
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.Point | dict | str
Examples:
>>> from pydriosm.reader import PBFReadParse >>> g1_dat = {'type': 'Point', 'coordinates': [-0.5134241, 52.6555853]} >>> g1_data = PBFReadParse.transform_unitary_geometry(g1_dat) >>> type(g1_data) shapely.geometry.point.Point >>> g1_data.wkt 'POINT (-0.5134241 52.6555853)' >>> g2_dat = { ... 'type': 'Feature', ... 'geometry': { ... 'type': 'Point', ... 'coordinates': [-0.5134241, 52.6555853] ... }, ... 'properties': { ... 'osm_id': '488432', ... 'name': None, ... 'barrier': None, ... 'highway': None, ... 'ref': None, ... 'address': None, ... 'is_in': None, ... 'place': None, ... 'man_made': None, ... 'other_tags': '"odbl"=>"clean"' ... }, ... 'id': 488432 ... } >>> g2_data = PBFReadParse.transform_unitary_geometry(g2_dat, mode=2) >>> type(g2_data) dict >>> list(g2_data.keys()) ['type', 'geometry', 'properties', 'id'] >>> g2_data['geometry'] 'POINT (-0.5134241 52.6555853)'