我在處理大的geojson資料(超過1Gb)時,采用這種結構。 是它的一部分。
{'type'/span>: 'FeatureCollection',
'crs': {'type': 'name', 'properties': {'name': 'EPSG:4326'}}。
'features': [{'type': 'Feature',
'屬性': {'date_create': '15.03.2008',
'statecd': '06',
'cc_date_approval': None,
'children': None,
'adate': '23.08.2017',
'cc_date_entering': '01.01.2014',
'rifr_cnt': None,
'parcel_build_attrs': None,
'rifr': None,
'sale_date': None,
' area_unit': '055',
'util_code': None,
'util_by_doc': None,
'area_value': 115558.0,
'application_date': None,
'sale': None,
'cad_unit': '383',
'kvartal': '69:3:11',
'parent_id': '69:3:11:248',
'sale_cnt': None,
'sale_doc_date': None,
'date_cost': None,
'category_type': '003008000000',
'rifr_dep': None,
'kvartal_cn': '69:03:0000011',
'parent_cn': '69:03:0000011:248',
'cn': '69:03:0000011:245',
'is_big': False。
'rifr_dep_info': None,
'sale_dep': None,
'sale_dep_uo': None,
'parcel_build': False,
'id': '69:3:11:245',
'address': '',
' area_type': '009',
'parcel_type': 'parcel',
'sale_doc_num': None,
'sale_doc_type': None,
'sale_price': None,
'cad_cost': 139698.06,
'fp': None,
'center'/span>: {'x'/span>: 33.14727379331379, 'y': 55.87764081906541}},
'geometry'/span>: {'type'/span>: 'MultiPolygon',
'坐標': []},
我需要保存特征'id'和'area_value',對它們進行重命名并洗掉其他的特征,這樣在嵌套表里面就只有這兩個鍵。
而且我必須保存其他結構的資料,否則,程式將無法理解它們。
我只得到了檢索的資料,但我不能重寫它們。 我使用這個方法。 在pandas中我有pd.Dataframe,我知道如何過濾和選擇,但我不知道如何回傳或重寫資料。
from pandas.io.json import json_normalize
f = 'data_file_name.json'/span>
with open(f,'r') as dff:
data = json.loads(dff.read())
df = json_normalize(data,record_path=['features'], errors='ignore')
df
另外,我嘗試用ijson作業。在這里,我有同樣的問題
def parse_json(json_filename)。
with open(json_filename, 'rb'/span>) as input_file:
# load json iteratively
parser = ijson.parse(input_file)
for prefix, event, value in parser:
if prefix == 'features.items.id'。
id_val = value
if prefix == 'features.items.area_value':
area_val = value
print(id_val)
# print('prefix={}, event={}, value={}'.format(pref ix, event, value))
if __name__ == '__main__'/span>:
parse_json('data_file_name.json')
謝謝大家!
uj5u.com熱心網友回復:
如果你確定資料是GeoJSON,并且結構正確,那么這個答案是有效的:
對于讀取GeoJSON的資料,你需要知道它的結構。
對于讀取GeoJSON資料,你可以使用Geopandas庫:
importgeopandas as gpd
gdf = gpd.read_file('data_file_name.json')
這將在geopandas GeoDataFrame中加載GeoJSON檔案,它是一個具有空間分析功能的pandas資料框架。 你可以閱讀更多這里
在你對資料進行了操作之后,你可以將其匯出為GeoJSON格式:
gdf.to_file('data_file_name.geojson'/span>, driver='GeoJSON'/span>)
這將保留geojson的結構。如果你的進一步分析是使用其他軟體,你可以把它保存為其他空間格式,如Geopackage、shapefiles甚至CSV與WKT格式的幾何圖形。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/307054.html
標籤:
上一篇:如何將"Searchkick.multi_search"與"with_highlights"一起使用?未定義的方法"with_highlights
