Spatial Data Example for Apex

Staring with version 4.2.5, APEX provides the APEX_SPATIAL package that allows you to manage spatial metadata and indexes. Below is a quick example showing basic usage:

[sourcecode language=”sql”]
— Create table with a latitude and longitude column, as well as a sdo_geometry column
— which allows you to perform spatial queries against the data.
create table geo_testing (id number
,lat varchar2(30)
,lng varchar2(30)
,geom sdo_geometry);

— Sample query to calculate the distance in miles between the two points.
select round(sdo_geom.sdo_distance(a.geom
,b.geom
,1
,’unit=mile’
)
,2) as miles
from geo_testing a
, geo_testing b
where a.id = 1
and b.id = 2;