Implemented conversion to a "mapping"
See original GitHub issueShapely has a mapping
function (https://shapely.readthedocs.io/en/latest/manual.html#shapely.geometry.mapping), which can convert a geometry into a dict (in geojson form):
In [59]: from shapely.geometry import mapping, LineString
In [60]: mapping(LineString([(1, 1), (3, 4)]))
Out[60]: {'type': 'LineString', 'coordinates': ((1.0, 1.0), (3.0, 4.0))}
In geopandas, this is for example used in the iterfeatures
/ __geo_interface__
and so also in to_json
(a method that can convert to a geojson like string, which doesn’t use fiona / GDAL like to_file
, this is already faster as to_file
, and can eg be used for in memory serialization to geojson).
From profiling iterfeatures
in geopandas (for the countries dataset, so for polygons/multipolygons), the mapping
of the geometries takes around 75% of the total time converting the dataframe to a dict.
So this mapping
could be a target for (vectorized) optimization. Since it involves creating python dicts and lists, it might be better suited to do this in cython, and also given that, I am not fully sure it will necessarily give a big speedup (experiments will need to tell).
This is related to https://github.com/pygeos/pygeos/issues/65 in the sense that the same dict needs to be created for both.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:4
- Comments:7 (5 by maintainers)
Top GitHub Comments
A fast/direct way to generate a geojson representation would be great for using with many visualization libraries (Mapbox, Leaflet, etc). No idea if that’s useful, but gdal has a function: https://gdal.org/api/vector_c_api.html#_CPPv418OGR_G_ExportToJson12OGRGeometryH
Closing; this is solved by #413