Sonoma map: Difference between revisions
Brian Wilson (talk | contribs) Created page with "I am building a map to help me find a house to live in. == Address points == I have parcels but I don't have an official source for address points so I decided to create on..." |
Brian Wilson (talk | contribs) mNo edit summary |
||
(2 intermediate revisions by the same user not shown) | |||
Line 52: | Line 52: | ||
So I am looking at Openstreetmap Nominatum as a possibility. Works for my old house anyway. REST example | So I am looking at Openstreetmap Nominatum as a possibility. Works for my old house anyway. REST example | ||
http://nominatim.openstreetmap.org/reverse?format=json&lat=44.5454&lon=-123.2626&zoom=18&addressdetails=1 | http://nominatim.openstreetmap.org/reverse?format=json&lat=44.5454&lon=-123.2626&zoom=18&addressdetails=1&pretty=1 | ||
{"place_id":"86732458","licence":"Data \u00a9 OpenStreetMap contributors, ODbL 1.0. http:\/\/www.openstreetmap.org\/copyright","osm_type":"way","osm_id":"154822790","lat":"44.545242","lon":"-123.259303","display_name":"Southeast Alexander Avenue, Corvallis, Benton County, Oregon, 97333, United States of America","address":{"road":"Southeast Alexander Avenue","city":"Corvallis","county":"Benton County","state":"Oregon","postcode":"97333","country":"United States of America","country_code":"us"}} | {"place_id":"86732458","licence":"Data \u00a9 OpenStreetMap contributors, ODbL 1.0. http:\/\/www.openstreetmap.org\/copyright","osm_type":"way","osm_id":"154822790","lat":"44.545242","lon":"-123.259303","display_name":"Southeast Alexander Avenue, Corvallis, Benton County, Oregon, 97333, United States of America","address":{"road":"Southeast Alexander Avenue","city":"Corvallis","county":"Benton County","state":"Oregon","postcode":"97333","country":"United States of America","country_code":"us"}} | ||
sudo pip install simplejson | |||
<pre> | |||
python | |||
from nominatim import ReverseGeocoder | |||
client = ReverseGeocoder("http://nominatim.openstreetmap.org/reverse?format=json") | |||
response = client.geocode(44.5454, -123.2626) | |||
print response['full_address'] | |||
</pre> | |||
Gag me! Does not give house number only street, useless! :-) | |||
Trying this one | |||
sudo pip install pygeocoder | |||
Peets Coffee, the sidewalk outside anyway | |||
N 38 26.459 | |||
W 122 42.737 | |||
which the Garmin reports as 276 D Street. | |||
38.440983 -122.712283 | |||
from pygeocoder import Geocoder | |||
results = Geocoder.reverse_geocode(38.440983,-122.71245) | |||
print(results.formatted_address) |
Latest revision as of 05:49, 27 May 2014
I am building a map to help me find a house to live in.
Address points
I have parcels but I don't have an official source for address points so I decided to create one.
I want to walk through the parcel layer, grab the centroid, and geocode it, and generate a new shapefile that contains the centroid with address data as attributes.
I can't use ArcMap right now because I am on vacation and have only this little MacBook. (Yes, this is what I do on vacation.)
I think the easiest way to do this is to use shapely to read and write the file and I have to throttle the geocode requests. I have to spread them out over a few days.
I ran across Fiona, which I wanted to try, so I had to install Homebrew. Installing Homebrew
ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"
Installing gdal then becomes
brew install gdal
I still need pip though and brew recommends
sudo easy_install pip
Then I can do
pip install Fiona
which fails on the Mac so maybe I will not use Fiona at the moment. :-)
The steps
# Read shapefile and load into shapely geometries # For each shape, ## Reverse geocode the centroid ## Write geometry to shapefile
Step one is covered in Finding Intersections with Python but don't forget
import sys, os from osgeo import ogr import shapely.wkt
Once I do step one I have a list of features in both shapely and ogr format (in tuples). I store only the centroid, not the complete shapely polygon.
I wanted to use the geopy module but reverse geocoding is not supported in the trunk and the branch would not build on the Mac. So I am looking at Openstreetmap Nominatum as a possibility. Works for my old house anyway. REST example
http://nominatim.openstreetmap.org/reverse?format=json&lat=44.5454&lon=-123.2626&zoom=18&addressdetails=1&pretty=1
{"place_id":"86732458","licence":"Data \u00a9 OpenStreetMap contributors, ODbL 1.0. http:\/\/www.openstreetmap.org\/copyright","osm_type":"way","osm_id":"154822790","lat":"44.545242","lon":"-123.259303","display_name":"Southeast Alexander Avenue, Corvallis, Benton County, Oregon, 97333, United States of America","address":{"road":"Southeast Alexander Avenue","city":"Corvallis","county":"Benton County","state":"Oregon","postcode":"97333","country":"United States of America","country_code":"us"}}
sudo pip install simplejson
python from nominatim import ReverseGeocoder client = ReverseGeocoder("http://nominatim.openstreetmap.org/reverse?format=json") response = client.geocode(44.5454, -123.2626) print response['full_address']
Gag me! Does not give house number only street, useless! :-)
Trying this one
sudo pip install pygeocoder
Peets Coffee, the sidewalk outside anyway N 38 26.459 W 122 42.737 which the Garmin reports as 276 D Street.
38.440983 -122.712283
from pygeocoder import Geocoder results = Geocoder.reverse_geocode(38.440983,-122.71245) print(results.formatted_address)