# SDO_LRS.LRS_INTERSECTION and tolerance

**Paul Dziemiela**Sep 26, 2012 2:43 PM

Hi folks,

Not sure if this a bug or an enhancement request or confusion on my part. I've never been a great fan of LRS_INTERSECTION and how it coughs out ORA-13331 in such an unfriendly manner but it is what it is and I try to use it. As a function it does an intersection upon two geometries and then applies the proper set of measures to the output. So we have two sets of calculations going on against two separate sets of dimensions, one against X and Y in one set of units and one against M in another set of units. But just one tolerance input parameter.

So when we give a tolerance to this function, what exactly are we giving?

Referencing

http://docs.oracle.com/cd/E11882_01/appdev.112/e11830/sdo_lrs_concepts.htm#CIHJBDGG

So my reading of that would say that the tolerance value should be applied to the XY intersection of the two input geometries and the LRS tolerance is just unstated, probably using the default of 0.00000001. However, today I was noticing some odd results from the function when the intersection is very small. I have a polygon and an LRS line which definitely overlap at 0.05 meter tolerance but just barely with a result only 0.062 meters long! Yes, that is cutting it close.

Anyhow I cling to the 0.05 meter tolerance for geodetic data like all the rest of you and am happy with my intersection functioning at that tolerance. If the overlap was 0.04 meters long I would be fine and dandy with getting back nothing. But its not. So I provide LRS_INTERSECTION with a tolerance of 0.05 meters expecting to get back something.

I get back nothing.

As I mentioned if I use SDO_INTERSECTION I get back my 0.062 meters of overlap (with hosed measures of course). But LRS_INTERSECTION returns NULL. So after mulling this a bit I changed the tolerance input to 0.00001 and voila - there are my results! I feel pretty sure that the one function input tolerance is being used for

So one solution would be to do what the documentation says:

But my geometries may not be valid at 0.00001 meters of tolerance. What happens to the intersection step with invalid geometries? Also, if they don't intersect at 0.05 meters, I don't want any results. Can anyone shed some light on the matter?

Cheers,

Paul

Not sure if this a bug or an enhancement request or confusion on my part. I've never been a great fan of LRS_INTERSECTION and how it coughs out ORA-13331 in such an unfriendly manner but it is what it is and I try to use it. As a function it does an intersection upon two geometries and then applies the proper set of measures to the output. So we have two sets of calculations going on against two separate sets of dimensions, one against X and Y in one set of units and one against M in another set of units. But just one tolerance input parameter.

So when we give a tolerance to this function, what exactly are we giving?

Referencing

http://docs.oracle.com/cd/E11882_01/appdev.112/e11830/sdo_lrs_concepts.htm#CIHJBDGG

*Many LRS functions require that you specify a tolerance value or one or more dimensional arrays. Thus, you can control whether to specify a single tolerance value for all non-measure dimensions or to use the tolerance associated with each non-measure dimension in the dimensional array or arrays. The tolerance is applied only to the geometry portion of the data, not to the measure dimension. The tolerance value for geodetic data is in meters, and for non-geodetic data it is in the unit of measurement associated with the data.*So my reading of that would say that the tolerance value should be applied to the XY intersection of the two input geometries and the LRS tolerance is just unstated, probably using the default of 0.00000001. However, today I was noticing some odd results from the function when the intersection is very small. I have a polygon and an LRS line which definitely overlap at 0.05 meter tolerance but just barely with a result only 0.062 meters long! Yes, that is cutting it close.

Anyhow I cling to the 0.05 meter tolerance for geodetic data like all the rest of you and am happy with my intersection functioning at that tolerance. If the overlap was 0.04 meters long I would be fine and dandy with getting back nothing. But its not. So I provide LRS_INTERSECTION with a tolerance of 0.05 meters expecting to get back something.

I get back nothing.

As I mentioned if I use SDO_INTERSECTION I get back my 0.062 meters of overlap (with hosed measures of course). But LRS_INTERSECTION returns NULL. So after mulling this a bit I changed the tolerance input to 0.00001 and voila - there are my results! I feel pretty sure that the one function input tolerance is being used for

**both**the XY intersection and the M measure evaluation. This does not seem like a good thing at all. Screwing about with 0.075 tolerance returns the dreaded LRS point because at that tolerance the two geometries are just touching. Try running my code block below with 0.05, 0.075 and 0.00001 and note this confusing results.So one solution would be to do what the documentation says:

*Be sure that the tolerance value used is appropriate to the data and your purpose. If the results of LRS functions seem imprecise or incorrect, you may need to specify a smaller tolerance value.*But my geometries may not be valid at 0.00001 meters of tolerance. What happens to the intersection step with invalid geometries? Also, if they don't intersect at 0.05 meters, I don't want any results. Can anyone shed some light on the matter?

Cheers,

Paul

```
DECLARE
sdo_polygon SDO_GEOMETRY := SDO_GEOMETRY(
2003,
8265,
NULL,
SDO_ELEM_INFO_ARRAY(1,1003,1),
SDO_ORDINATE_ARRAY(
-90.2723236205888,34.3089046489779,-90.2723434018803,34.3086367633515,-90.2707392173661,34.3084621403682,-90.2714391621628,34.3078266803467,-90.2711308198837,34.3072329063238,-90.2677855464361,34.3064063389093,-90.266046692677,34.3068371687339,-90.2644869322497,34.3074521769116,-90.2640778953734,34.3067610051735,-90.2638397934431,34.3051488857908,-90.2633196125303,34.3040143113733,-90.2626565481076,34.3037337411334,-90.2622138718598,34.3027678106083,-90.2586234556832,34.3028257016198,-90.2565180892368,34.3025819558746,-90.2564450549202,34.303013065096,-90.2564807618278,34.3044745337385,-90.2553791003502,34.3044925268907,-90.2551232287851,34.3036092978105,-90.2537434557592,34.3020730067122,-90.2529210792963,34.3016532409998,-90.2523760879501,34.3007515717326,
-90.2510968977626,34.2999752398579,-90.2505835900105,34.3025646332747,-90.2495830701649,34.3022945683535,-90.2491733068569,34.3011989977255,-90.248006992966,34.3013617184064,-90.2471865164011,34.3017485152995,-90.2469561258218,34.3025320556109,-90.2453346745869,34.3023152437147,-90.2446981528576,34.3023361984727,-90.244128518716,34.3045384597202,-90.2418985971879,34.3042410139152,-90.2414831900652,34.3056454856159,-90.2407103227105,34.3058749262462,-90.2408374482424,34.3084214601979,-90.2402320513138,34.3087841730892,-90.239786692857,34.3097953658916,-90.2398811289664,34.3117081162025,-90.2364541599022,34.3110131446682,-90.2357994215034,34.3112778451714,-90.2350948945995,34.3114864986818,-90.2349154659916,34.3118934680219,-90.2378855095725,34.3121647064096,
-90.2395983794317,34.3128145833046,-90.2409335048531,34.3131159965438,-90.2415259377715,34.3134477522725,-90.243086201113,34.3137991216548,-90.2425660202003,34.3152298566521,-90.2453367980023,34.3152075049103,-90.2463246332345,34.3153047349874,-90.2471964070469,34.3149215702523,-90.248076003969,34.3140168835,-90.2491585547073,34.3130098257699,-90.2495600478707,34.3121381637161,-90.2518508778954,34.310992469307,-90.2525576958528,34.3115503687842,-90.2526205601268,34.3160783287737,-90.2538585672299,34.316200481043,-90.2542663747604,34.3148607735144,-90.2546533951709,34.3143569652526,-90.2550015235506,34.3138218086728,-90.25616884327,34.3137524623936,-90.2565437378606,34.311502759574,-90.2653765874556,34.3116565954374,-90.2675727578535,34.3107106697213,
-90.2694102945529,34.3105114598219,-90.269753282032,34.3102532413239,-90.2714172015764,34.3100728068876,-90.2721284340029,34.309040938724,-90.2723236205888,34.3089046489779
)
);
sdo_lrs_line SDO_GEOMETRY := SDO_GEOMETRY(
3302,
8265,
NULL,
SDO_ELEM_INFO_ARRAY(
1,
2,
1
),
SDO_ORDINATE_ARRAY(
-90.2723229705251,
34.308904813298,
100,
-90.2729301705242,
34.3085618799652,
0
)
);
sdo_temp SDO_GEOMETRY;
num_tolerance NUMBER := 0.05;
--num_tolerance NUMBER := 0.075;
--num_tolerance NUMBER := 0.00001;
BEGIN
dbms_output.put_line(' ');
dbms_output.put_line('Using tolerance ' || num_tolerance);
-- Check Polygon and LRS line are valid
dbms_output.put_line('Validate polygon: ' || SDO_GEOM.VALIDATE_GEOMETRY_WITH_CONTEXT(sdo_polygon,num_tolerance));
dbms_output.put_line('Validate LRS line: ' || SDO_GEOM.VALIDATE_GEOMETRY_WITH_CONTEXT(sdo_lrs_line,num_tolerance));
-- Polygon and LRS line are OVERLAPBYDISJOINT at 0.05 meters, there is overlap you can see in mapviewer
dbms_output.put_line('SDO_GEOM.RELATE: ' || SDO_GEOM.RELATE(sdo_polygon,'DETERMINE',sdo_lrs_line,num_tolerance));
-- Running generic SDO_INTERSECTION returns a valid linestring but of course hoses the LRS values
-- No points or whacky collections or anything iffy or squirrelly, but very small
sdo_temp := SDO_GEOM.SDO_INTERSECTION(sdo_polygon,sdo_lrs_line,num_tolerance);
dbms_output.put_line('SDO_GEOM.SDO_INTERSECTION: ' || sdo_util.to_clob(sdo_temp));
dbms_output.put_line('SDO_GEOM.SDO_INTERSECTION length: ' || sdo_geom.sdo_length(sdo_temp,num_tolerance,'UNIT=M'));
-- Running LRS_INTERSECTION at 0.05 tolerance returns NULL, not ORA-13331 or anything, just NULL
sdo_temp := SDO_LRS.LRS_INTERSECTION(sdo_polygon,sdo_lrs_line,num_tolerance);
dbms_output.put_line('SDO_LRS.LRS_INTERSECTION: ' || sdo_util.to_clob(sdo_temp));
dbms_output.put_line('SDO_LRS.LRS_INTERSECTION length: ' || sdo_geom.sdo_length(sdo_temp,num_tolerance,'UNIT=M'));
-- but what is tolerance being applied to? To the 2D geometry intersection or the measure calc?
-- it looks to be both!
END;
/
```

- 44 Views
- Tags: none (add)