public_library_map/merge_service_data.py at 31550bb512ceecb5dc5a16d2050044753ee4d878 · hughrun/public_library_map · GitHub Skip to content Sign up Why GitHub? Features → Mobile → Actions → Codespaces → Packages → Security → Code review → Project management → Integrations → GitHub Sponsors → Customer stories → Security → Team Enterprise Explore Explore GitHub → Learn & contribute Topics → Collections → Trending → Learning Lab → Open source guides → Connect with others The ReadME Project → Events → Community forum → GitHub Education → GitHub Stars program → Marketplace Pricing Plans → Compare plans → Contact Sales → Nonprofit → Education → In this repository All GitHub ↵ Jump to ↵ No suggested jump to results In this repository All GitHub ↵ Jump to ↵ In this user All GitHub ↵ Jump to ↵ In this repository All GitHub ↵ Jump to ↵ Sign in Sign up {{ message }} hughrun / public_library_map Watch 4 Star 3 Fork 5 Code Issues 13 Pull requests 0 Actions Security Insights More Code Issues Pull requests Actions Security Insights Permalink 31550bb512 public_library_map/merge_service_data.py / Jump to Code definitions No definitions found in this file. Code navigation not available for this commit Go to file Go to file T Go to line L Go to definition R Copy path     Cannot retrieve contributors at this time 41 lines (32 sloc) 1.29 KB Raw Blame #!/usr/bin/env python3 import csv import json from titlecase import titlecase # you need to install the titlecase package from PyPi :-) # files to merge geojson_file = 'website/data/all_library_services.geojson' csv_file = 'website/data/library_services_information.csv' # fields to match on geojson_match = 'name' csv_match = 'short_name' # output file name output_file = 'website/data/boundaries.geojson' # open the geojson file file = open(geojson_file, 'r') # read the file and then load the json so it's a dict json_data = json.loads(file.read()) # for each geojson feature, if a field in the json matches a field in the csv, add new properties to the json for feature in json_data['features']: with open(csv_file, newline='') as f: # use DictReader so we can use the header names reader = csv.DictReader(f) for row in reader: # look for match if row[csv_match] == feature['properties'][geojson_match]: # create new properties in geojson for k in row: feature['properties'][k] = row[k] downcased = titlecase(feature['properties'][geojson_match]) # titlecase name feature['properties']['name'] = downcased # write out new geojson file with the updates with open(output_file, 'w') as newfile: json.dump(json_data, newfile, separators=(',', ':')) Copy lines Copy permalink View git blame Reference in new issue Go © 2021 GitHub, Inc. Terms Privacy Security Status Docs Contact GitHub Pricing API Training Blog About You can’t perform that action at this time. You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.