Skip to content

Instantly share code, notes, and snippets.

@tucotuco
Created January 27, 2013 00:41
Show Gist options
  • Save tucotuco/4645547 to your computer and use it in GitHub Desktop.
Save tucotuco/4645547 to your computer and use it in GitHub Desktop.
Code to create PLSS geocodes
def plss_creator():
i = 0
f = open('/Users/tuco/plss_geocodes.csv', 'w')
for line in open('/Users/tuco/plss_for_geomancer.csv').read().split('\n'):
values = line.split(',')
if values[0] != 'feature_id' and len(values)>1:
# feature_id,name,lat,lon,uncertainty,w,s,e,n
geocode = {
"results" : [
{
"address_components" : [
{
"long_name" : values[1],
"short_name" : values[1],
"types" : [ "locality", "political" ]
},
{
"long_name" : "United States",
"short_name" : "US",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "%s, USA" % values[1],
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : float(values[8].strip()),
"lng" : float(values[7])
},
"southwest" : {
"lat" : float(values[6]),
"lng" : float(values[5])
}
},
"location" : {
"lat" : float(values[2]),
"lng" : float(values[3])
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : float(values[8]),
"lng" : float(values[7])
},
"southwest" : {
"lat" : float(values[6]),
"lng" : float(values[5])
}
}
},
"types" : [ "locality", "political" ]
}
],
"status" : "OK"
}
writeline = '%s,%s\n' % (values[1].lower(), json.dumps(geocode))
f.write(writeline)
f.flush()
f.close()
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment