How to Speed Up Your Oracle APEX Map? Spatial Indexes

Performance. We often want to display a large dataset on our map. This is not a problem. However, we want to do it within a time frame that is acceptable to the user, and this can be a challenge. In this article, I will present a solution that can effectively improve the performance of our map in APEX applications. I will use data from previous articles, specifically a dataset of 140,000 cities from around the world, which we will display on our map. Let's get started!

Initial settings

First, we will display the entire dataset. My map looks like this:

💡
Conclusion: Our map takes over 40 seconds to load and is unreadable.

Improving map readability

  1. Heat Map

Sometimes changing the layer type from Points to Heat Map can improve map readability, but this change didn’t work for me. 🙂

More about layer types here.

  1. Presenting a selected part of the map

Presenting only the part of the map that interests you can also improve readability. To achieve this, set the parameter values in the map attributes under the Initial Position and Zoom section. These are the values I use:

Type: Static Values

Longitude: -90

Latitude: 35

Zoom Level: 5

  1. Clusters

Using Clusters may also be a good solution.

More about clusters here.

  1. Faceted Search

Adding the Faceted Search component and using appropriate filters will limit the number of points displayed on the map, improving its readability. More about Faceted Search here.

💡
Conclusion: Above I have presented solutions that can (but do not have to) improve the readability of the map. However, the loading time of my map is still over 40 seconds.

Improving Performance by Using a Spatial Index

A spatial index in Oracle Database helps speed up searches for location-based data, such as maps or shapes (points, lines, and areas). It makes finding and retrieving this data faster by organizing it in a way that is easy to search. Such an index can be created on a column of the SDO_GEOMETRY type, so we will have to convert our geographic data stored in the Longitude and Latitude columns of the VARCHAR2 type. Once we do that, we can create an index in the following way:

CREATE INDEX cities_spatial_idx ON cities (sdo_geom)
INDEXTYPE IS MDSYS.SPATIAL_INDEX;

Now we can enable the use of the index. In the layer settings, in the Source section, set the Use Spatial Index parameter to True. That's it. Let's see what happened to our map. Its display time is approximately 6 seconds!

💡
Conclusion: The spatial index has effectively improved the display time of our map.

Conclusions

A map is nothing more than a report that presents geographic data. We can use a few tricks to improve the readability of our map. We can also use the spatial index to enhance its efficiency. However, there is one important thing to consider. If we look at the Help tab of the Spatial Index field, we will find the following information:

Note that a Spatial Index will not be used in the following situations:

  • More than one layer references the Region Source as their data source.

  • The map window is too large; that is the case when it spans more than half of the world.

In the first case, we are safe since I am only displaying one layer. In the second case, setting the values in the Initial Position and Zoom section from point 3 now appears to be more reasonable. If we want to use our secret weapon: the spatial index for the entire map, it simply won't work...