geopandas数据框到json

时间:2018-02-18 22:04:18

标签: bigdata geojson geopandas

我有一个名为SchooolDistrictDf的地理数据框,其行数超过19,814,822,如下所示:

FIPS    SrcName crate_code  geohash ncessch sLevel  schnam  shape   stAbbrev
0   13820.0 NaN birmingh    djfjrrw 010000700091    1   TRACE CROSSINGS ELEM SCH    {u'type': u'Point', u'coordinates': [-86.85997...   AL
1   13820.0 NaN birmingh    djfjq2v 010000700091    1   TRACE CROSSINGS ELEM SCH    {u'type': u'Point', u'coordinates': [-86.90528...   AL
2   13820.0 NaN birmingh    djfjx17 010000700091    1   TRACE CROSSINGS ELEM SCH    {u'type': u'Point', u'coordinates': [-86.87507...   AL
3   13820.0 NaN birmingh    djfjx26 010000700091    1   TRACE CROSSINGS ELEM SCH    {u'type': u'Point', u'coordinates': [-86.86546...   AL
4   13820.0 NaN birmingh    djfm8rd 010000700091    1   TRACE CROSSINGS ELEM SCH    {u'type': u'Point', u'coordinates': [-86.82151...   AL

我被告知我需要将其转换/保存为json。我不熟悉json,但我尝试在一小部分数据上执行以下操作:

SchooolDistrictDf.geometry.__geo_interface__

但我收到以下错误:

AttributeError: No geometry data set yet (expected in column 'geometry'.

是因为我的shape列采用以下格式

`{u'type': u'Point', u'coordinates': [-86.8599700927734, 33.3084869384766]}`

此外,我怎样才能将大型地理数据框转换为json?我非常感谢任何帮助

编辑:

这就是我尝试将SchooolDistrictDf['shape']转换为普通的geopandas几何图形的方法:

SchooolDistrictDf = pd.concat([SchooolDistrictDf.drop(['shape'], axis=1), SchooolDistrictDf['shape'].apply(pd.Series)], axis=1)
geometry = [Point(xy) for xy in SchooolDistrictDf['coordinates']]
crs = {'init': 'epsg:4269'}
SchooolDistrictDf = GeoDataFrame(SchooolDistrictDf, crs=crs, geometry=geometry)
SchooolDistrictDf = SchooolDistrictDf.drop(['coordinates','type'], axis=1)
SchooolDistrictDf =SchooolDistrictDf.to_crs(epsg=4269)

0 个答案:

没有答案