Oracle Autonomous Database includes a powerful built-in function called SDO_GCDR.ELOC_GEOCODE_AS_GEOM, which can geocode an address and return its location as an SDO_GEOMETRY object. This function works with both formatted (structured) and unformatted (free-text) addresses and returns the geographic coordinates along with standardized address metadata.
This feature is only available within Oracle Autonomous Database and is especially useful when combined with Oracle Analytics for building location-aware workbooks.
How Geocoding Works
The function geocodes a formatted (with the address parts like street, city, and country separated) or unformatted (single-line full address) string and returns a spatial point.
Formatted Address Example
‘123 Beacon St’, ‘Boston’, ‘MA’, ‘02116’, ‘US’)
).GET_GEOJSON() FROM DUAL;
{ “type”: “Point”, “coordinates”: [-71.07355, 42.35517] }
Unformatted Address Example
‘123 Beacon St, Boston, MA 02116, US’
).GET_GEOJSON() FROM DUAL;
{ “type”: “Point”, “coordinates”: [-71.07355, 42.35517] }
Example: Static Geocoding Query
You can use this function to geocode a specific address and return the geometry data type of the location:
SDO_GCDR.ELOC_GEOCODE_AS_GEOM(‘1 Oracle Dr, Nashua NH, 03062, US’) AS GEOCODE_AS_GEOM
FROM
DUAL;
To make this geocoding process dynamic and interactive, you can create session variables within the semantic model and bind the session variables to parameters within a workbook in Oracle Analytics.
Step 1: Create Session Variables to Use in the SQL Query
Before you can reference a session variable in your SQL, you must define it in the semantic model:
- Define two session variables: MY_ADDRESS and MY_COUNTRY.
- Assign default values for testing.
- Deploy the semantic model.
- Then, use the following SQL to geocode addresses dynamically based on user input, and use the SQL to create a dataset:
SDO_GCDR.ELOC_GEOCODE_AS_GEOM(‘VALUEOF(NQ_SESSION.MY_ADDRESS), VALUEOF(NQ_SESSION.MY_COUNTRY)’) AS LOCATION_PIN
FROM
DUAL;
Step 2: Create Workbook Parameters and Bind Them to the Session Variables
Once the SQL is created and saved as a dataset in Oracle Analytics, you can:
- Create parameters in your workbook for the address and country and expose them as dashboard filter controls on your canvas. For example, parameters by the name ‘Enter Your Address’ and ‘Enter Your Country’ will make sense to users as dashboard filter controls on the canvas.
- Use parameter binding to connect the user-entered values to the session variables.
When a user enters an address and country via the dashboard filter controls, the geocoding function dynamically returns the coordinates. Later, you can expose the parameters to your users through a dashboard filter with the filter type, Text Box. Users can input their choice of address and country using these text boxes.
The resulting spatial geometry LOCATION_PIN can be visualized directly on a map.
Geocoding is a key step in spatial analytics, and with Oracle Autonomous Database and Oracle Analytics, it becomes seamless. You can convert addresses into map locations dynamically, visualize them instantly, and create interactive, location-aware workbooks with no external tools required.
Stay Tuned
In the next part of this series, we will explore Drive Time Polygons through Spatial SQL and Oracle Analytics
Reference
Call to Action
Now that you’ve read this article, try it yourself and let us know your results in the Oracle Analytics Community, where you can also ask questions and post ideas. Be sure to explore the Community Gallery as well, where users share their most creative dashboards and map visualizations for inspiration.
