如果您不想手动创建此字典,也可以依靠geopandas
来创建它:
翻译后:
如果你不想手动创建这个字典,你也可以依赖于 geopandas
来创建:
In [1]: import shapely.geometry
In [2]: import geopandas
In [3]: shapely_polygon = shapely.geometry.Polygon([(0, 0), (0, 1), (1, 0)])
In [4]: geopandas.GeoSeries([shapely_polygon]).__geo_interface__
Out[4]:
{'bbox': (0.0, 0.0, 1.0, 1.0),
'features': [{'bbox': (0.0, 0.0, 1.0, 1.0),
'geometry': {'coordinates': (((0.0, 0.0),
(0.0, 1.0),
(1.0, 0.0),
(0.0, 0.0)),),
'type': 'Polygon'},
'id': '0',
'properties': {},
'type': 'Feature'}],
'type': 'FeatureCollection'}
(请注意,这将得到一个FeatureCollection而不是单个要素。)
或者将其转换为字符串(或文件):
In [4]: geopandas.GeoSeries([shapely_polygon]).to_json()
Out[4]: '{"features": [{"bbox": [0.0, 0.0, 1.0, 1.0], "geometry": {"coordinates": [[[0.0, 0.0], [0.0, 1.0], [1.0, 0.0], [0.0, 0.0]]], "type": "Polygon"}, "properties": {}, "id": "0", "type": "Feature"}], "bbox": [0.0, 0.0, 1.0, 1.0], "type": "FeatureCollection"}'
"geometry": { }
中吗? - conv3d