Skip to content

Instantly share code, notes, and snippets.

@bdon
Created March 14, 2020 08:21
Show Gist options
  • Save bdon/9194b0f0fb3347aa5e34425e46c78556 to your computer and use it in GitHub Desktop.
Save bdon/9194b0f0fb3347aa5e34425e46c78556 to your computer and use it in GitHub Desktop.
import csv
import sys
import json
from urllib import request, parse
from urllib.parse import quote
import time
features = []
with open(sys.argv[1],'r') as csvfile:
reader = csv.DictReader(csvfile,delimiter="\t")
for row in reader:
address = row["縣市"] + row["行政區"] + row["段小段"] + row["母子號"] + "號"
url = "https://twland.ronny.tw/index/search?lands[]={0}".format(quote(address))
resp = request.urlopen(url=url)
j = json.loads(resp.read())
if len(j['features']) > 0:
features.append({'type':'Feature','properties':row,'geometry':j['features'][0]['geometry']})
time.sleep(0.1)
print(json.dumps({'type':'FeatureCollection','features':features}))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment