Function Repository Resource:

NominatimData

Source Notebook

Look up information about a given location from the OpenStreetMap Nominatim public web service

Contributed by: Daniel de Souza Carvalho

ResourceFunction["NominatimData"][]

returns address information about the current geolocation.

ResourceFunction["NominatimData"][lat,lon]

returns the address information from a specific geolocation provided by two real number for latitude lat and longitude lon.

ResourceFunction["NominatimData"][{lat,lon}]

return the address information from a specific geolocation provided by two real number in a list for latitude lat and longitude lon.

ResourceFunction["NominatimData"][query]

return the address information for a given query in plain English text.

ResourceFunction["NominatimData"][assoc]

return the address information for a given Association.

Details

The assoc in NominatimData[assoc] supports all the properties shown on the Nominatim documentation.

Examples

Basic Examples (3) 

Search for the address for the current location:

In[1]:=
ResourceFunction["NominatimData"][] // Dataset
Out[1]=

Search for White House address:

In[2]:=
ResourceFunction["NominatimData"]["White House"]
Out[2]=

List NASA address at Florida:

In[3]:=
ResourceFunction["NominatimData"]["NASA, Florida, USA"]
Out[3]=

Options (3) 

Request a specific data format such as XML:

In[4]:=
ResourceFunction[
 "NominatimData"][<|"q" -> "Pentagon, USA", "format" -> "xml"|>]
Out[4]=

Geojson format, note that Insper has 2 addresses side by side:

In[5]:=
ResourceFunction[
 "NominatimData"][<|"q" -> "Insper, São Paulo, Brazil", "format" -> "geojson"|>]
Out[5]=

Geojson format:

In[6]:=
ResourceFunction[
 "NominatimData"][<|"q" -> "Kremlin, Moscou", "format" -> "geojson"|>]
Out[6]=

Check address data from the Sugar Loaf Entity at Rio de Janeiro city in Brazil:

In[7]:=
Entity["Mountain", "SugarLoaf::zp598"]["Position"]
Out[7]=
In[8]:=
ResourceFunction["NominatimData"][%] // Dataset
Out[8]=

Get data from a GeoPosition:

In[9]:=
ResourceFunction["NominatimData"][GeoPosition[{-23.63, -46.64}]]
Out[9]=

Applications (7) 

Image from La Casa Rosada in Buenos Aires, Argentina:

In[10]:=
data = First[
  ResourceFunction["NominatimData"]["Casa Rosada, Buenos Aires"] ]
Out[10]=

Notes that the latitude (lat) and longitude (lon) fields are in text (string), conversion to float is needed:

In[11]:=
GeoListPlot[
 GeoPosition[Interpreter["Number"][Lookup[data, {"lat", "lon"}]]], ImageSize -> 400]
Out[11]=

Times Square location in NYC:

In[12]:=
data = ResourceFunction["NominatimData"]["Time Square, NYC"] // First
Out[12]=

Use "display_name" to get a readable address:

In[13]:=
data["display_name"]
Out[13]=
In[14]:=
GeoListPlot[
 GeoPosition[Interpreter["Number"][Lookup[data, {"lat", "lon"}]]], ImageSize -> 400]
Out[14]=

The capital of Brazil, "Distrito Federal":

In[15]:=
data = ResourceFunction["NominatimData"][
    "Esplanada dos Ministérios, Brasília, Brasil"] // First // Dataset
Out[15]=

Geo latitude and longitude values:

In[16]:=
data[{"lat", "lon"}]
Out[16]=

The "lat" and "lon" values are provided as strings from the API, use Interpreter to import them as numbers:

In[17]:=
GeoListPlot[
 GeoPosition[
  Interpreter["Number"][Normal@Values@data[{"lat", "lon"}]]], ImageSize -> 400]
Out[17]=

Search by a company name:

In[18]:=
sb = ResourceFunction["NominatimData"][
   "Starbucks, São Paulo, Brazil"] // Dataset
Out[18]=

Plot the location of stores addresses using geographic information:

In[19]:=
GeoListPlot[
 GeoPosition /@ ToExpression[Normal[Values[sb[All, {"lat", "lon"}] ]]]]
Out[19]=

Find your preferred store:

In[20]:=
ResourceFunction["NominatimData"]["LEGO, NYC"] // First
Out[20]=

And visualize it:

In[21]:=
GeoGraphics[{Polygon[\!\(\*
NamespaceBox["LinguisticAssistant",
DynamicModuleBox[{Typeset`query$$ = "NYC", Typeset`boxes$$ = TemplateBox[{"\"New York City\"", 
RowBox[{"Entity", "[", 
RowBox[{"\"City\"", ",", 
RowBox[{"{", 
RowBox[{"\"NewYork\"", ",", "\"NewYork\"", ",", "\"UnitedStates\""}], "}"}]}], "]"}], "\"Entity[\\\"City\\\", {\\\"NewYork\\\", \\\"NewYork\\\", \\\"UnitedStates\\\"}]\"", "\"city\""}, "Entity"], Typeset`allassumptions$$ = {{"type" -> "Clash", "word" -> "NYC", "template" -> "Assuming \"${word}\" is ${desc1}. Use as ${desc2} instead", "count" -> "2", "Values" -> {{"name" -> "City", "desc" -> "a city", "input" -> "*C.NYC-_*City-"}, {"name" -> "VisualArts", "desc" -> "a photograph", "input" -> "*C.NYC-_*VisualArts-"}}}}, Typeset`assumptions$$ = {}, Typeset`open$$ = {1, 2}, Typeset`querystate$$ = {"Online" -> True, "Allowed" -> True, "mparse.jsp" -> 1.298379, "Messages" -> {}}}, 
DynamicBox[ToBoxes[
AlphaIntegration`LinguisticAssistantBoxes["", 4, Automatic, 
Dynamic[Typeset`query$$], 
Dynamic[Typeset`boxes$$], 
Dynamic[Typeset`allassumptions$$], 
Dynamic[Typeset`assumptions$$], 
Dynamic[Typeset`open$$], 
Dynamic[Typeset`querystate$$]], StandardForm],
ImageSizeCache->{148.04405460858587`, {6.86328125, 15.92578125}},
TrackedSymbols:>{Typeset`query$$, Typeset`boxes$$, Typeset`allassumptions$$, Typeset`assumptions$$, Typeset`open$$, Typeset`querystate$$}],
DynamicModuleValues:>{},
UndoTrackedVariables:>{Typeset`open$$}],
BaseStyle->{"Deploy"},
DeleteWithContents->True,
Editable->False,
SelectWithContents->True]\)], GeoMarker[{GeoPosition[{ToExpression[%["lat"]], ToExpression[%["lon"]]}]}]}]
Out[21]=

Search an address by a postal code:

In[22]:=
Dataset[ResourceFunction[
   "NominatimData"][<|
    "postalcode" -> "61820"|>] ][All, "display_name"]
Out[22]=
In[23]:=
Dataset[ResourceFunction[
   "NominatimData"][<|
    "postalcode" -> "03819"|>] ][All, "display_name"]
Out[23]=

The Terminator would love this function, it makes easy to find somebody:

In[24]:=
ResourceFunction[
 "NominatimData"][<|"q" -> "Sarah Connor", "format" -> "json"|>]
Out[24]=

Query specifying a different format:

In[25]:=
ResourceFunction[
 "NominatimData"][<|"amenity" -> "Walmart", "county" -> "Urbana", "format" -> "xml"|>]
Out[25]=

Search for a street name:

In[26]:=
ResourceFunction[
 "NominatimData"][<|"street" -> "Rua Agua Nova", "format" -> "json"|>]
Out[26]=

Some queries can return a set of results:

In[27]:=
ResourceFunction["NominatimData"]["Brazil"]  // Dataset
Out[27]=

Publisher

Daniel de Souza Carvalho

Requirements

Wolfram Language 13.0 (December 2021) or above

Version History

  • 1.1.0 – 10 July 2024
  • 1.0.0 – 07 June 2023

Related Resources

Author Notes

This function is a wrapper to OpenStreetMap nominatim WEB API (WEB Service). As such, this function requires internet connection. To find addresses is not trivial, there are lots of ambiguity, for example, "Main Street", "Church Street", "Springfield", "Washington" can return many addresses in different places.

License Information