geocoding webservice on giif
After I saw this: I created a specialized, simplified, hacked up version on giif, that is pretty useful. the simplest way to see its use is by going here (ken-ichi, i'm leaving the link text == href intentionally): http://firecenter.berkeley.edu/proxy/geoservice.py/geocode/2134%20Allston%20Way,%20Berkeley,%20CA,%2094704 that is the lat/lon of CanCun Burritos. If you prefer your burritos in UTM, you can request by appending ?epsg=26910 to the end: http://firecenter.berkeley.edu/proxy/geoservice.py/geocode/2134%20Allston%20Way,%20Berkeley,%20CA,%2094704?epsg=26910 or any valid EPSG code that GDAL on giifweb will recognize. (if you dont know what EPSG is, you should consider freeing yourself from your dependency on ESRI products.) likewise, reverse geocoding: http://firecenter.berkeley.edu/proxy/geoservice.py/reverse_geocode/-122.2584/37.8675 and it may return you a list of info. depending on wether geonames.org can reverse_geocode your points. again that assumes lat/lon, you can specify an EPSG code by appening ?epsg=26910 to the end of the query. it's useful to have this built into a webGIS. where,perhaps, the user enters an address and you move the map to that lat/lon. the script will generate an example if you browse to: http://firecenter.berkeley.edu/proxy/geoservice.py/example if you enter an address and an EPSG, it should alert the lat/lon, and then try to reverse_geocode and alert that derived place. if you view the source on that page, you can see how to include the necessary javascript: and if you browse to that url, you'll see the lovely javascript that is generated. Since AJAX is used, you'll either need to download the source to somewhere that has GDAL and web.py installed, or be on giifweb. to use the javascript, you need to attach an event to call the geocode() javascript function:
document.getElementById('button').onclick = function(){
geocode(document.getElementById('address').value, 4326);
};
where geocode() generates a url and makes the AJAX request to server to do the geocoding for you. again, the 4326 is the default, optional EPSG, to use other projections, just put that as the 2nd argument. then, when the result returns from the server, it geocode.callback is called with the resulting JSON: so you can define your own callback like: geocode.callback = function(result){ // do something with the result. document.getElementById('x').value = result.x document.getElementById('y').value = result.y }; where result.x and result.y correspond to the x and y properties here it's simpler than it sounds, best to view and read the source of the example. or better yet, just make the python script print itself. in all places in this post where it says firecenter.berkeley.edu, you can substitute giif.cnr.berkeley.edu or giifweb.cnr.berkeley.edu, and it will work as it should. and you will have to do this if you use the javascript/AJAX because of cross-domain issues. sorry i dont know how to format html properly on this blag.
Reader Comments (4)
Hi!,
Hello!,