Skip to content

Instantly share code, notes, and snippets.

@NbtKmy
Last active July 10, 2019 14:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NbtKmy/66dfd22a4c7225e854f0a5671564e765 to your computer and use it in GitHub Desktop.
Save NbtKmy/66dfd22a4c7225e854f0a5671564e765 to your computer and use it in GitHub Desktop.
import json
def main():
f = open("/path/to/your.geojson", 'r')
json_data = json.load(f)
for i in range(len(json_data["features"])):
lat2 = json_data["features"][i]["properties"]["lat2"]
lon2 = json_data["features"][i]["properties"]["lon2"]
if(lat2 is not None):
geo_type = json_data["features"][i]["geometry"]["type"]
geo_type2 = geo_type.replace("Point", "LineString")
json_data["features"][i]["geometry"]["type"] = geo_type2
cord = json_data["features"][i]["geometry"]["coordinates"]
geo_data = [lon2, lat2]
json_data["features"][i]["geometry"]["coordinates"] = [cord, geo_data]
f = open("path/to/your.geojson", 'w')
json.dump(json_data, f, ensure_ascii=False, indent=4)
if __name__ == "__main__":
main()
@NbtKmy
Copy link
Author

NbtKmy commented Jun 30, 2019

人間文化研究機構の歴史地名辞書データ(CSVファイル)をQGISを使ってGeoJson形式に変更した。ここにあげたファイルにより緯度経度が2つあるものに関してはジオメトリのタイプを「LineString」に変更し、かつ2つ目の緯度経度をジオメトリの「coordinates」に挿入するようにした。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment