Updated 2013-08-20 01:30:10 by uniquename

Keith Vetter 2013-03-12 : Nominatim is a tcllib module which caught my interest. The man page says it's for "resolving geographical names with a Nominatim service". Digging deeper reveals that Nominatim is "a tool to search OpenStreetMap data by name and address to generate synthetic addresses".

In simpler terms, it essentially takes an address and returns its latitude and longitude.

Here's a short demo which illuminates how this module is to be used.
##+##########################################################################
#
# nominatim.tsh -- quick demo on how map::geocode::nominatim works
# by Keith Vetter 2013-03-12
#

package require Tk
package require map::geocode::nominatim

set S(intro) {
Welcome to Nominatim Demo

Nominatim is a web service for resolving geographical names using OpenStreetMap data. This program demonstrates how to use the map::geocode::nominatim package to query this web service.

Enter any location in the location box and press search button. The Nominatim service will be queried and the result displayed here.

Search terms are processed left to right, from most to least specific.

So 'pilkington avenue, birmingham' will work but 'birmingham, pilkington avenue' will not.

Commas are optional, but improve performance by reducing the complexity of the search.    
    
For more info visit http://wiki.openstreetmap.org/wiki/Nominatim.
}

proc DoDisplay {} {
    global S
    
    wm title . "Nominatim Demo"
    label .l -text "Location:"
    entry .e -textvariable ::S(location)
    ::ttk::button .go -text "Search" -command Go

    frame .f -bd 2 -relief sunken
    text .t -width 100 -wrap word -fg red -bd 0 -yscroll [list .sb set]
    ::ttk::scrollbar .sb -orient vertical -command [list .t yview]
    pack .sb -in .f -side right -fill y
    pack .t -in .f -side left -fill both -expand 1
    
    grid .l .e .go -sticky ew
    grid .f - - -sticky enws
    grid columnconfigure . 1 -weight 1
    grid rowconfigure . 1 -weight 1

    .t insert end $::S(intro)
    bind all <Return> Go
}
proc Go {} {
    .t insert 0.0 "querying nominatim...";
    update
    requestor search $::S(location)
}
proc MyCallBack {args} {
    set ::S(result) $args
    ShowData
}
proc ShowData {} {
    .t delete 0.0 end
    .t config -fg black -wrap char

    set cnt [llength [lindex $::S(result) 0]]
    .t insert end [format "\nFound %d result%s\n\n" $cnt [expr {$cnt == 1 ? "" : "s"}]]
    foreach wrapper $::S(result) {
        for {set i 0} {$i < [llength $wrapper]} {incr i} {
            .t insert end "Location #[expr {$i+1}]\n"
            set myDict [lindex $wrapper $i]
            set maxLen 0
            foreach key [dict keys $myDict] { set maxLen [expr {max($maxLen,[string length $key])}]}
            foreach key [lsort [dict keys $myDict]] {
                set value [dict get $myDict $key]
                .t insert end [format "  %-${maxLen}s : %s\n" $key $value]
            }
            if {[dict exists $myDict lat] && [dict exists $myDict lon]} {
                set value [format "%g %g" [dict get $myDict lat] [dict get $myDict lon]]
                .t insert end [format "  %-${maxLen}s : %s\n" "lat_lon" $value]
            }
            .t insert end "\n"
        }
    }
}
set S(location) "Mount Hamilton, CA"

catch {rename requestor {}}
::map::geocode::nominatim requestor -callback MyCallBack
DoDisplay
return

uniquename 2013aug19

For the readers who do not have time/facilities/whatever to setup this code and then execute it, here is an image that shows the GUI that this code creates.

I do not have the 'map::geocode::nominatim' package installed, so to get this GUI to appear I had to comment out a couple of statements that involved the name 'map::geocode::nominatim'.

The image lets us know that it is a simple GUI with simple input that is involved here.