geopandas.GeoSeries.to_json#
- GeoSeries.to_json(show_bbox=True, drop_id=False, to_wgs84=False, **kwargs)[来源]#
返回GeoSeries的GeoJSON字符串表示形式。
- Parameters:
- show_bboxbool, optional, default: True
在geojson中包含bbox(边界)
- drop_idbool, default: False
在生成的GeoJSON中,是否将GeoSeries的索引保留为id属性。默认值为False,但如果索引仅是任意行号,则可能希望为True。
- to_wgs84: bool, optional, default: False
如果活动几何列上设置了CRS,它将被导出为WGS84 (EPSG:4326),以符合2016 GeoJSON规范。设置为True以强制重投影,设置为False以忽略CRS。默认为False。
- *kwargs* that will be passed to json.dumps().
- Returns:
- JSON string
另请参阅
GeoSeries.to_file
将GeoSeries写入文件
示例
>>> from shapely.geometry import Point >>> s = geopandas.GeoSeries([Point(1, 1), Point(2, 2), Point(3, 3)]) >>> s 0 POINT (1 1) 1 POINT (2 2) 2 POINT (3 3) dtype: geometry
>>> s.to_json() '{"type": "FeatureCollection", "features": [{"id": "0", "type": "Feature", "properties": {}, "geometry": {"type": "Point", "coordinates": [1.0, 1.0]}, "bbox": [1.0, 1.0, 1.0, 1.0]}, {"id": "1", "type": "Feature", "properties": {}, "geometry": {"type": "Point", "coordinates": [2.0, 2.0]}, "bbox": [2.0, 2.0, 2.0, 2.0]}, {"id": "2", "type": "Feature", "properties": {}, "geometry": {"type": "Point", "coordinates": [3.0, 3.0]}, "bbox": [3.0, 3.0, 3.0, 3.0]}], "bbox": [1.0, 1.0, 3.0, 3.0]}'