I’ve a SDO_GEOMETRY column containing quite large multi polygons, defined like this:
INSERT INTO t1 (i, d, g)
VALUES (
25,
'Multipolygon - multi-touch',
sdo_geometry (2007, null, null, sdo_elem_info_array (1,1003,1, 17,1003,1),
sdo_ordinate_array (50,95, 55,95, 53,96, 55,97, 53,98, 55,99, 50,99, 50,95, 55,100, 55,95, 60,95, 60,100, 55,100))
);
Instead of two polygons as in the example above, one column contains > 100 polygons.
I’d like to filter this column so it only will return a relevant subset (using a bbox?), something like:
SELECT filter(Geometry, bbox) from Table Where Id = 1
A first attempt at brute force solution might look something like this:
I say brute force because:
The individual sub-polygons are not indexed, so this solution does not leverage spatial indexing. If performance is important enough, it may be worthwhile to break your multi-polygons into their constitutent sub-polygons (with one row in your source table per sub-polygon) so that you can use a different solution that takes advantage of spatial indexing. You could do this either up front (by changing the design of your source table) or behind the scenes (maybe using a materialized view based on your original table).
It looks like you are on Oracle XE, and so are limited to the Locator subset of the Oracle Spatial functionality.
Items 1 and 2 mean that your only built-in choice for determining which sub-polygons interact with the mask appears to be via SDO_GEOM.SDO_DISTANCE. This is going to be resource intensive (since it will be called for every sub-polygon), and gives you only one type of interaction vs. the many that are possible with the built-in spatial operators (that rely on spatial indexing).
SDO_UTIL.APPEND may not be the most performant (or correct, particularly if your multi-polygons are not disjoint) way of building up the “filtered” multi-polygon result, but it illustrates the concept.
Anyway, this is what I get running your sample geometry against some sample masks. You should make sure the function returns the expected results against your real geometries.
Hope this helps.