【发布时间】:2021-02-17 10:05:37
【问题描述】:
我正在做一个需要使用US States Zip Code Data 的项目。我想合并两个 geojson 文件,同时保留这些文件中的数据。 geojson-merge https://github.com/mapbox/geojson-merge 这样做,但我希望有一个基于 python 的解决方案。
每个州都有一个单独的 *.json 文件。例如:
-
mt_montana_zip_codes_geo.min.json
-
nd_north_dakota_zip_codes_geo.min.json
import json nd_boundary_file = r"C:\Data_ZipCodes_States\State-zip-code-GeoJSON-master" \ r"\nd_north_dakota_zip_codes_geo.min.json" with open(nd_boundary_file, 'r') as f: nd_zipcode_boundary = json.load(f) mt_boundary_file = r"C:\\Data_ZipCodes_States\State-zip-code-GeoJSON-master" \ r"\mt_montana_zip_codes_geo.min.json" with open(mt_boundary_file, 'r') as f: mt_zipcode_boundary = json.load(f) #This overwrote the mt_zipcode_boundary with the nd_zipcode_boundary into merged #merged = {**mt_zipcode_boundary, **nd_zipcode_boundary} #produced a file with two json objects one 'mt' and the other 'nd' data = {'mt': mt_zipcode_boundary, 'nd':nd_zipcode_boundary} #Also overwrote mt_zipcode_boundary mt_zipcode_boundary.update(nd_zipcode_boundary)
如何编写代码将这两个 geojson 文件合并到一个文件中?
【问题讨论】:
-
它们的结构是否相同?与列中一样。
-
@martinfleis 是的,它们具有相同的结构。
标签: python json geojson geopandas