Skip to content

Instantly share code, notes, and snippets.

@hatobus
Created December 19, 2022 18:04
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 hatobus/8e4c6e4a739a583cab94b69878808613 to your computer and use it in GitHub Desktop.
Save hatobus/8e4c6e4a739a583cab94b69878808613 to your computer and use it in GitHub Desktop.
import json
latitude = 0
longitude = 0
pref_name = "福島県"
with open('prefectures.geojson') as f:
j = json.load(f)
for feature in j["features"]:
if feature["properties"]["name"] == pref_name:
coordinates = feature["geometry"]["coordinates"]
points = [p for i in coordinates for j in i for p in j]
break
for p in points:
latitude = latitude + p[1]
longitude = longitude + p[0]
print("{}, {}".format(latitude/len(points), longitude/len(points)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment