Element 84 Logo

Natural Language Geocoding

05.07.2024

In our increasingly data-driven world, the ability to quickly and accurately access geospatial data can transform industries from public health to urban planning. Imagine being able to locate and analyze data from ‘within 10 miles of the North Carolina coastline’ in mere seconds. Natural Language Geocoding makes this possible, bridging the gap between complex geospatial queries and user-friendly language. Let’s dive into how this innovative technology is changing the landscape of data analysis, making it more accessible and efficient.

Balancing user needs when identifying geospatial regions 

There are different design goals when allowing the user to specify spatial regions. 

  1. It should be as easy as possible to specify the spatial region. The user shouldn’t have to spend a long time entering coordinates or dragging points around. Dragging a bounding box is an example of something that’s relatively easy on a desktop computer.
  2. The user should be able to express their intent precisely. This means that the most relevant search results will be found and relevant data analyzed. Uploading a shapefile to specify the exact coordinates is a way for the user to specify an exact area.

Both of these goals are important but achieving one can sometimes come at the expense of the other. Bounding boxes are a relatively simple mechanic for users, but are not very precise if the region in question doesn’t fit within a boxy shape. Conversely, dragging points to outline a more precise area with a polygon is both tricky and time-consuming. Finally, uploading an exact spatial area has the potential to produce a highly accurate region, but it requires too much time spent finding geojson areas or converting between shapefiles, KML, and GeoJSON before an upload is even possible. 

A screenshot of the state of Florida with a large box outlining the whole area around the state.
A user-drawn bounding box around Florida; quick but imprecise.
A screenshot of the state of Florida with a loose outline around it in the color blue.
A user-drawn polygon around Florida; more precise but takes time.

Using Natural Language Processing (NLP) to interact with spatial data

With the above dilemma in mind, we’ve been considering the possibilities of implementing Natural Language Processing (NLP) as a strategy for enabling both precision and simplicity. What if the user could just describe the area they want and the system was smart enough to get just that?

The newer advances in Natural Language Processing (NLP) from Large Language Models (LLM) combined with geospatial algorithms allow us to do just that. 

Here are some examples of that.

A screenshot of a map of Florida where a blue, shaded outline accurately covers the state of Florida. The query "Florida" is shown in a search bar.
Natural Language “Florida” to spatial area (easy and precise).
Partial screenshot of the world map, the Natural Language Geocoding query selected is "India south of Mumbai" and the bottom of India is appropriately outlined in a blue line.
Partial screenshot of the world map, the Natural Language Geocoding query selected is "within 2 km of the coast of Maui west of Kahului" and the portion of Maui is appropriately outlined in a blue line.

What is Natural Language Geocoding? 

Natural Language Geocoding is a technology that allows users to interact with geospatial data systems using everyday language. This approach simplifies querying complex data sets without the need for specialized training in Geographic Information Systems (GIS).

If you look at traditional Geocoding APIs they use conventional search approaches to convert region names like “Canada” or addresses “123 Main St. New York, NY” to points or polygons. Natural Language Geocoding goes beyond this traditional approach in a few ways:

  1. Users can specify region names, names of physical features, coastlines, etc.
  2. Users can specify multiple regions; they can include spatial operations in their descriptions like “Between Florida and Cuba” or “Within 10 miles of Washington DC”
  3. The end result of our approach generates a single Geometry, such as points, polygons, lines, etc, that precisely defines the area that was described by the user.

How would Natural Language Geocoding look in practice? 

We see Natural Language Geocoding as a component of a larger AI/Ml strategy. It could support many different use cases whenever a user needs to express a spatial area. We’ve highlighted a few examples below, but the possibilities extend far beyond the scope of this list. 

Geospatial Data Discovery for Climate Change Analysis, Habitat Protection, and Scientific Research

Imagine a feature including Natural Language Geocoding in a tool such as NASA’s Earthdata Search. Scientists and researchers want to quickly identify and obtain the data they need without downloading data outside of the boundaries of their area of study. With Natural Language Geocoding, they’d be able to specify specific areas like “within 10 miles of the North Carolina coastline” in only a fraction of the time required to identify such a specific region without this feature. 

Here’s an example of a tool that combines Image Embedding models with Natural Language Geocoding to allow searching for any features visible through satellite imagery. 

Partial screenshot of the world map, the Natural Language Geocoding query selected is "Show me algal blooms within 2 miles of Cape Cod" and the portion of Massachusetts is appropriately outlined in a blue line. There is an image of the algal blooms tiled next to the map.

Geospatial Data Discovery for Healthcare and Epidemiology

In healthcare, both time and accuracy are crucial. With access to this tool, public health officials and researchers can quickly identify spatial areas  related to disease outbreaks or healthcare access using natural language, streamlining the identification of high-risk areas and planning of healthcare services. For example, during an outbreak of dengue fever, public health officials can use Natural Language Geocoding to quickly locate all reported cases within ’50 miles of Rio de Janeiro city center’, allowing for rapid response and resource allocation.

Geospatial Data Discovery for Education

The introduction of Natural Language Geocoding makes geospatial concepts more accessible to students and educators. With this tool, real-world spatial data analysis is integrated into the classroom without the need for complex GIS software training.

Geospatial Data Discovery for Public Policy/​​Real Estate/Urban Planning

When it comes to policy and housing, through leveraging Natural Language Geocoding professionals become able to monitor urban growth, land use changes, and compliance with zoning laws, making governance more efficient and data-driven.

Widespread adoption of Natural Language Geocoding also streamlines the analysis of land use, zoning, and urban development projects by allowing planners and real estate developers to query geospatial data repositories with natural language, making site selection and planning processes more efficient.

How does Natural Language Geocoding work? 

Spatial Operations in Natural Language Requests

Natural language requests can be understood as directed graphs. In order for users to identify particular regions, different combinations can be interpreted as spatial operations: 

  1. In “California and Nevada”, the inclusion of “and” represents a union of two regions
  2. In “The Great Lakes in Canada”, the inclusion of “in” represents the Intersection of two regions
  3. “Within 50 KM of Madrid” utilizes a buffer zone by including “within” and a specific KM range

By combining several of the above operations such as in, “The Iberian Peninsula north of Barcelona and France west of Paris”, the relative complexity and specificity can be increased. 

These combinations can be thought of as a tree structure such as:

  • Union
    • Directional Constraint
      • Named Location: “Iberian Peninsula”
      • North
        • Named Location: Barcelona
    • Directional Constraint
      • Named Location: “France”
      • West
        • Named Location: Paris

Large Language Models (LLMs) convert user intent into a tree structure

LLMs have improved dramatically when it comes to converting user requests into data structures, and can even produce valid programmatic representations like JSON. This is the same approach that’s used for Agents, which allow LLMs to use APIs based on user requests. We’ve been able to use general purpose LLMs, like Claude 3 Sonnet, with a system prompt to perform conversion from a user query into a tree structure.

Our system prompt is divided into a few sections

  1. Overview – Tells the LLM the overview of the job it has to perform
  2. JSON Schema – Lists the JSON schema that that output must conform to.
  3. Examples – A few examples of user queries and the output response.
  4. Guidelines – A list of important rules to make sure the LLM generates the expected output.

The LLM returns a text based response which we can parse into instances of classes representing each node type. 

Processing the tree

At this point, processing the tree is fairly straightforward. Each node of the tree is processed from the leaves to the root. Named locations like “Washington DC” are converted into a Polygon using a database of known areas. Other tree nodes that are spatial operations are processed using geospatial algorithms. The end result is a single geospatial area that can be converted to GeoJSON or other formats for use. 

Natural Language Geocoding Challenges and Potential Solutions 

I’ve encountered a few challenges with this approach, some of which I’ve been able to overcome and others that will take more time.

Disambiguating multiple responses in a geocoding API

Geocoding databases can contain multiple entries for the same item like “Mississippi River”. When you ask it for something, like “Mississippi River”, there are multiple results that come back and only one of them refers to the entire river. You have to make sure to select the one that’s most likely going to refer to the area that the user wants.

Other examples of ambiguities can be present in an area’s name such as Portland, Maine and Paris, Texas. If the user asks for an area which is ambiguous, such as a city like Paris or Portland, there are a few ways to determine what the user actually means. 

Firstly, context clues may provide an immediate resolution. For example if the user’s request is, “In Texas west of Paris” we can be confident that Paris, Texas is the city being referred to. If the request does not provide sufficient context, it may be possible to ask the user directly for clarification. Portland could refer to the city in Oregon or Maine. We can instruct the LLM to detect situations like this and tell us to prompt the user to clear the ambiguity. Finally, feedback may be available via visual maps. Pairing natural language understanding with visual tools, such as maps, is a clear way for users to confirm that their request was interpreted correctly. Because “Los Angeles” could mean the official boundary of Los Angeles or a greater Los Angeles metro area, a visual confirmation that the correct area was selected is a quick way to disambiguate and avoid confusion. 

Missing areas

Geocoding APIs contain things like countries, cities, individual addresses, and some natural features like rivers. This being said, the natural features included in these APIs are not all inclusive. Other natural features or broad areas like “Rocky Mountains” or the “Congo River Basin Rainforest” typically won’t be in a Geocoding API.

To remedy this problem, we’ll have to identify alternate sources for these kinds of areas. When it comes to coastlines specifically, I found a Natural Earth GeoJSON source containing all of the coastlines for the entire world. If a user requests an area like “California Coastline”, I can perform a spatial intersection of “California” plus a small buffer with the world coastline shape to extract the particular coastline of interest.

Options like the Natural Earth GeoJSON Github Repository contain a large number of additional features like “Rocky Mountains”, but it is not a completely comprehensive resource. This being said, we haven’t found one single source that presents a full picture of this type of information. Further research and development is required on this topic, but a comprehensive understanding of natural features will likely require pulling from multiple sources like the repository referenced above and government websites.

Final Thoughts

Element 84 has a robust background in geospatial data discovery and analysis. Throughout our time in the space, we’ve worked to streamline the process for users to find, acquire, and use the geospatial data they need  for various purposes. On a related note, we pride ourselves in our ability to maintain an current and up-to-date understanding of geospatial technologies, even as they evolve rapidly (and for a more comprehensive picture of our thoughts on up and coming technology, you can find more in our 2023 Geospatial Technology Radar). 

As we detail throughout this blog, the introduction of Natural Language Geocoding as a tool in identifying geospatial regions represents huge potential for both reducing the time and effort required by users while also increasing precision and accuracy throughout the process. In addition to these general benefits, Natural Language Geocoding has huge potential in a variety of specific applications including climate change analysis, healthcare, education, and housing policy. 

We’re working towards integrating natural language capabilities into geospatial analysis. At E84 we’re excited about anything we can do to shorten the distance and effort required to uncover answers to our world’s biggest questions, and increasing efficiency from the geospatial perspective is a large part of that. We’re working on other innovative solutions and we’d love to hear from you if you’re interested in learning more about anything we’ve outlined in this post. Do you have applications that would benefit from Natural Language Geocoding? Are there particular ways of phrasing spatial areas that might be unique to your domain or user base? – connect with our team directly on our contact us page!

Launching A New Geospatial AI Community

Like many others in our community, we appreciate openness and collaboration between groups. We’re passionate about the intersection of geospatial technology and artificial intelligence and want to work with other enthusiasts, professionals, and newcomers who feel the same. We want to actively encourage a collaborative and vibrant environment where members can share knowledge, discuss challenges, and explore innovative solutions within geospatial AI. As we begin to shape this new community, we invite individuals from all backgrounds to provide their input on how we can shape this community to best support learning, sharing, and innovation in applying AI/ML to geospatial workloads. If you’re interested in getting involved, fill out this form to learn more, express your interest, and share your ideas.

Jason Gilman

Principal Software Engineer