Haversine formula vs. MDSYS.SDO_GEOM.SDO_DISTANCE
We need to calculate the distance between 2 lat/longs (from GPS unit).
What is more accurate, the use of MDSYS.SDO_GEOM.SDO_DISTANCE or a hand coded Haversine Formula?
Thanks,
JB
Well, easiest thing to do is to conduct a test.
I looked at this website: http://www.movable-type.co.uk/scripts/latlong-vincenty.html
The answer to the default functional demo is 969954.114 meters.
Testing with SDO_DISTANCE we get (I converted the DMS values to DD):
select sdo_geom.sdo_distance(
sdo_geometry(2001,8307,sdo_point_type(-5.71475, 50.0663222222,null),null,null),
sdo_geometry(2001,8307,sdo_point_type(-3.07009444444,58.6440222222,null),null,null),
0.05) as dist
from dual;
-- Result
969954.113110585Which is pretty similar!!
So, don't bother coding your own Haversine (you would have to add extra parameters to pass in the ellisodal params for non-WGS84 SRIDs...), use what comes out of the box.
Does that answer you question? If so, please award points.
regards
Simon
Similar Messages
-
ISSUS IN MDSYS.SDO_GEOM.SDO_DISTANCE()
Hi experts,
SQL> SELECT * FROM LOC_ZIP;
COMP ZIPCD
LOC(SDO_GTYPE, SDO_SRID, SDO_POINT(X, Y, Z), SDO_ELEM_INFO, SDO_ORDINATES)
c1 z1
SDO_GEOMETRY(2001, NULL, SDO_POINT_TYPE(100, 1, NULL), NULL, NULL)
c1 z2
SDO_GEOMETRY(2001, NULL, SDO_POINT_TYPE(200, 2, NULL), NULL, NULL)
SQL> SELECT * FROM SUPP_ZIP;
COMP SUPPI
LOC(SDO_GTYPE, SDO_SRID, SDO_POINT(X, Y, Z), SDO_ELEM_INFO, SDO_ORDINATES)
c1 s1
SDO_GEOMETRY(2001, NULL, SDO_POINT_TYPE(5, 1, NULL), NULL, NULL)
c1 s2
SDO_GEOMETRY(2001, NULL, SDO_POINT_TYPE(77, 7, NULL), NULL, NULL)
SQL> SELECT MDSYS.SDO_GEOM.SDO_DISTANCE(L.LOC,S.LOC,NULL)
FROM Loc_zip L,Supp_zip S
WHERE L.compcd = S.compcd;
SELECT MDSYS.SDO_GEOM.SDO_DISTANCE(L.LOC,S.LOC,NULL)
ERROR at line 1:
ORA-22060: argument [2] is an invalid or uninitialized number
ORA-06512: at "MDSYS.SDO_3GL", line 817
ORA-06512: at "MDSYS.SDO_GEOM", line 3224
ORA-06512: at "MDSYS.SDO_GEOM", line 3238
Many Thanks,
KalingaYou might try specifying a positive tolerance value (as the third argument to SDO_GEOM.SDO_DISTANCE), as in something like:
SELECT
MDSYS.SDO_GEOM.SDO_DISTANCE(L.LOC, S.LOC, 0.5)
FROM
Loc_zip L,
Supp_zip S
WHERE
L.compcd = S.compcd;Hope this helps. -
Bug in function mdsys.sdo_geom.sdo_intersection() ?
Hi,
I got a strange result from the spatial subprogram
SDO_GEOM.SDO_INTERSECTION(
geom1 IN SDO_GEOMETRY,
dim1 IN SDO_DIM_ARRAY,
geom2 IN SDO_GEOMETRY,
dim2 IN SDO_DIM_ARRAY
) RETURN SDO_GEOMETRY;
I’m calling the function three times, passing each time the same geom1 and geom2 parameters. What changes it the value of the tolerance. Depending on the tolerance, sdo_intersection returns null or a valid geometry
tol = 0.02 --> the resulting geometry is correct
tol = 0.01 --> returns null !
tol = 0.005 --> the resulting geometry is correct
Please note that the result is null only for a tolerance in the range between 0.005 and 0.02 but not below or above these values.
I suppose this is a bug in sdo_intersection.
The exact query is:
select mdsys.sdo_geom.sdo_intersection(
(select A1.geoloc AS G1 from A1 where A1.mi_prinx = 390),
(select m.diminfo AS diminfo_1 from user_sdo_geom_metadata m where m.table_name = 'A1'),
(select A2.geoloc AS G2 from A2 where A2.mi_prinx = 245),
(select m.diminfo AS diminfo_2 from user_sdo_geom_metadata m where m.table_name = 'A2')
from dual;
The metadata is changed using this query:
update mdsys.user_sdo_geom_metadata
set diminfo =
SDO_DIM_ARRAY(SDO_DIM_ELEMENT('X', 650000, 800000, .01),
SDO_DIM_ELEMENT('Y', 180000, 300000, .01))
where table_name IN ( 'A1', 'A2');
Here are the geometries:
geom1:
SDO_GEOMETRY(2003, 262148, SDO_POINT_TYPE(758105.191, 245133.936, NULL), SDO_ELEM_INFO_ARRAY(1, 1003, 1), SDO_ORDINATE_ARRAY(758052.231, 245053.334, 758069.068, 245067.151, 758086.21, 245078.671, 758103.848, 245088.516, 758129.333, 245101.44, 758233.145, 245178.636, 758224.249, 245202.49, 758201.602, 245194.226, 758194.164, 245214.538, 758096.977, 245178.816, 758091.076, 245194.648, 758026.177, 245181.097, 758008.793, 245172.515, 757977.236, 245143.726, 758052.231, 245053.334))
geom2:
SDO_GEOMETRY(2003, 262148, SDO_POINT_TYPE(758042.484, 245106.878, NULL), SDO_ELEM_INFO_ARRAY(1, 1003, 1), SDO_ORDINATE_ARRAY(758129.32, 245101.47, 758233.14, 245178.66, 758224.242, 245202.514, 758211.122, 245237.717, 758166.209, 245208.415, 758091.065, 245194.675, 758026.168, 245181.127, 758008.785, 245172.546, 757977.231, 245143.76, 757932.238, 245109.93, 757895.471, 245068.865, 757851.827, 245034.324, 757941.369, 244976.447, 757951, 244976.04, 757960.491, 244979.747, 757992.773, 244998.626, 758005.407, 245007.133, 758026.492, 245029.014, 758052.22, 245053.37, 758069.056, 245067.186, 758086.197, 245078.704, 758103.835, 245088.548, 758129.32, 245101.47))I have tried to replicate your dataset (see below) and then I have execute the same query on the two tables and on metadata table, but the query still runs OK ... !
a doubt: are you sure that the sdo_ordinates arrays stored in the tables are exactly those you include in the msg?
Generally, the result of a "select" is truncated at the default decimal digit of sql client.
You can try to set the NUMF parameter (SET NUMF 999999.999999) and then re-execute the query to obtain a more precise value of ordinates as data input for our test.
Carl
SQL> create table tab1 (idGeom varchar2(1), geom mdsys.sdo_geometry);
Table created.
SQL> create table tab2 (idGeom varchar2(1), geom mdsys.sdo_geometry);
Table created.
SQL> r
1 insert into tab1 (idGeom,geom)
2 values
3 ('1',
4 MDSYS.SDO_GEOMETRY(2003, 262148,
5 MDSYS.SDO_POINT_TYPE(758105.191, 245133.936, NULL),
6 MDSYS.SDO_ELEM_INFO_ARRAY(1, 1003, 1),
7 MDSYS.SDO_ORDINATE_ARRAY(758052.231, 245053.334, 758069.068, 245067.151,
8 758086.21, 245078.671, 758103.848, 245088.516,
9 758129.333, 245101.44, 758233.145, 245178.636,
10 758224.249, 245202.49, 758201.602, 245194.226,
11 758194.164, 245214.538, 758096.977, 245178.816,
12 758091.076, 245194.648, 758026.177, 245181.097,
13 758008.793, 245172.515, 757977.236, 245143.726,
14* 758052.231, 245053.334)))
1 row created.
SQL> r
1 insert into tab2 (idGeom,geom)
2 values
3 ('2',
4 MDSYS.SDO_GEOMETRY(2003, 262148,
5 MDSYS.SDO_POINT_TYPE(758042.484, 245106.878, NULL),
6 MDSYS.SDO_ELEM_INFO_ARRAY(1, 1003, 1),
7 MDSYS.SDO_ORDINATE_ARRAY(758129.32, 245101.47, 758233.14, 245178.66,
8 758224.242, 245202.514, 758211.122, 245237.717,
9 758166.209, 245208.415, 758091.065, 245194.675,
10 758026.168, 245181.127, 758008.785, 245172.546,
11 757977.231, 245143.76, 757932.238, 245109.93,
12 757895.471, 245068.865, 757851.827, 245034.324,
13 757941.369, 244976.447, 757951, 244976.04,
14 757960.491, 244979.747, 757992.773, 244998.626,
15 758005.407, 245007.133, 758026.492, 245029.014,
16 758052.22, 245053.37, 758069.056, 245067.186,
17 758086.197, 245078.704, 758103.835, 245088.548,
18* 758129.32, 245101.47)))
1 row created.
SQL> commit;
Commit complete.
SQL> r
1 insert into user_sdo_geom_metadata
2 (TABLE_NAME,COLUMN_NAME,DIMINFO,SRID)
3 values
4 ('TAB1','GEOM',
5 MDSYS.SDO_DIM_ARRAY(
6 MDSYS.SDO_DIM_ELEMENT('X', 650000, 800000, .01),
7 MDSYS.SDO_DIM_ELEMENT('Y', 180000, 300000, .01)),
8* 262148)
1 row created.
SQL> r
1 insert into user_sdo_geom_metadata
2 (TABLE_NAME,COLUMN_NAME,DIMINFO,SRID)
3 values
4 ('TAB2','GEOM',
5 MDSYS.SDO_DIM_ARRAY(
6 MDSYS.SDO_DIM_ELEMENT('X', 650000, 800000, .01),
7 MDSYS.SDO_DIM_ELEMENT('Y', 180000, 300000, .01)),
8* 262148)
1 row created.
SQL> commit;
Commit complete.
SQL> r
1 select mdsys.sdo_geom.sdo_intersection(
2 (select geom AS G1 from tab1 where tab1.idGeom = '1'),
3 (select m.diminfo AS diminfo_1 from user_sdo_geom_metadata m where m.table_name = 'TAB1'),
4 (select geom AS G2 from tab2 where tab2.idGeom = '2'),
5 (select m.diminfo AS diminfo_1 from user_sdo_geom_metadata m where m.table_name = 'TAB2')
6 )
7* from dual
MDSYS.SDO_GEOM.SDO_INTERSECTION((SELECTGEOMASG1FROMTAB1WHERETAB1.IDGEOM='1'),(SE
SDO_GEOMETRY(2003, 262148, NULL, SDO_ELEM_INFO_ARRAY(1, 1003, 1), SDO_ORDINATE_A
RRAY(758008,793, 245172,515, 757977,236, 245143,726, 758052,22, 245053,37, 75806
9,056, 245067,186, 758086,197, 245078,704, 758103,835, 245088,548, 758129,32, 24
5101,47, 758233,14, 245178,66, 758224,249, 245202,49, 758201,602, 245194,226, 75
8194,164, 245214,538, 758096,977, 245178,816, 758091,076, 245194,648, 758026,177
, 245181,097, 758008,793, 245172,515))
SQL> r
1 update user_sdo_geom_metadata
2 set diminfo =
3 MDSYS.SDO_DIM_ARRAY(
4 MDSYS.SDO_DIM_ELEMENT('X', 650000, 800000, .02),
5 MDSYS.SDO_DIM_ELEMENT('Y', 180000, 300000, .02))
6* where table_name = 'TAB1'
1 row updated.
SQL> r
1 update user_sdo_geom_metadata
2 set diminfo =
3 MDSYS.SDO_DIM_ARRAY(
4 MDSYS.SDO_DIM_ELEMENT('X', 650000, 800000, .02),
5 MDSYS.SDO_DIM_ELEMENT('Y', 180000, 300000, .02))
6* where table_name = 'TAB2'
1 row updated.
SQL> commit;
Commit complete.
SQL> select mdsys.sdo_geom.sdo_intersection(
2 (select geom AS G1 from tab1 where tab1.idGeom = '1'),
3 (select m.diminfo AS diminfo_1 from user_sdo_geom_metadata m where m.table_name = 'TAB1'),
4 (select geom AS G2 from tab2 where tab2.idGeom = '2'),
5 (select m.diminfo AS diminfo_1 from user_sdo_geom_metadata m where m.table_name = 'TAB2')
6 )
7 from dual;
MDSYS.SDO_GEOM.SDO_INTERSECTION((SELECTGEOMASG1FROMTAB1WHERETAB1.IDGEOM='1'),(SE
SDO_GEOMETRY(2003, 262148, NULL, SDO_ELEM_INFO_ARRAY(1, 1003, 1), SDO_ORDINATE_A
RRAY(758008,793, 245172,515, 757977,236, 245143,726, 758052,22, 245053,37, 75806
9,056, 245067,186, 758086,197, 245078,704, 758103,835, 245088,548, 758129,32, 24
5101,47, 758233,14, 245178,66, 758224,249, 245202,49, 758201,602, 245194,226, 75
8194,164, 245214,538, 758096,977, 245178,816, 758091,076, 245194,648, 758026,177
, 245181,097, 758008,793, 245172,515))
SQL> r
1 update user_sdo_geom_metadata
2 set diminfo =
3 MDSYS.SDO_DIM_ARRAY(
4 MDSYS.SDO_DIM_ELEMENT('X', 650000, 800000, .005),
5 MDSYS.SDO_DIM_ELEMENT('Y', 180000, 300000, .005))
6* where table_name = 'TAB1'
1 row updated.
SQL> r
1 update user_sdo_geom_metadata
2 set diminfo =
3 MDSYS.SDO_DIM_ARRAY(
4 MDSYS.SDO_DIM_ELEMENT('X', 650000, 800000, .005),
5 MDSYS.SDO_DIM_ELEMENT('Y', 180000, 300000, .005))
6* where table_name = 'TAB2'
1 row updated.
SQL> commit;
Commit complete.
SQL> select mdsys.sdo_geom.sdo_intersection(
2 (select geom AS G1 from tab1 where tab1.idGeom = '1'),
3 (select m.diminfo AS diminfo_1 from user_sdo_geom_metadata m where m.table_name = 'TAB1'),
4 (select geom AS G2 from tab2 where tab2.idGeom = '2'),
5 (select m.diminfo AS diminfo_1 from user_sdo_geom_metadata m where m.table_name = 'TAB2')
6 )
7 from dual;
MDSYS.SDO_GEOM.SDO_INTERSECTION((SELECTGEOMASG1FROMTAB1WHERETAB1.IDGEOM='1'),(SE
SDO_GEOMETRY(2003, 262148, NULL, SDO_ELEM_INFO_ARRAY(1, 1003, 1), SDO_ORDINATE_A
RRAY(758008,793, 245172,515, 757977,236, 245143,726, 758052,209, 245053,36, 7580
52,22, 245053,37, 758069,056, 245067,186, 758086,197, 245078,704, 758103,835, 24
5088,548, 758129,32, 245101,47, 758233,14, 245178,66, 758224,249, 245202,49, 758
201,602, 245194,226, 758194,164, 245214,538, 758096,977, 245178,816, 758091,076,
245194,648, 758026,177, 245181,097, 758008,793, 245172,515)) -
Incorrect output by SDO_GEOM.SDO_DISTANCE
I am trying to calculate the difference of two points on earth, but is not giving me correct result
SELECT SDO_GEOM.SDO_DISTANCE(
SDO_GEOMETRY(2001,8307,SDO_POINT_TYPE(28.66667,77.43333,NULL),NULL,NULL),
SDO_GEOMETRY(2001,8307,SDO_POINT_TYPE(30.45,77.61667,NULL),NULL,NULL),
0.0001,'unit=km') AS DISTANCE_BETWEEN_POINTS
FROM DUALI tested it against http://www.movable-type.co.uk/scripts/latlong.html
Query is returning me 47.6389006
but the actual distance is: 199.1
Please help me out.I also tested it by
sqrt(x * x + y * y) * 1.609344 // for KM
where x = 69.1 * (lat2 - lat1) and y = 53.0 * (lon2 - lon1)
There is still a lot of difference.
SQL> SQL> SQL> SELECT SDO_GEOM.SDO_DISTANCE(
SDO_GEOMETRY(2001,8307,SDO_POINT_TYPE(28.66667,77.43333,NULL),NULL,NULL),
SDO_GEOMETRY(2001,8307,SDO_POINT_TYPE(30.45,77.61667,NULL),NULL,NULL),
0.0001,'unit=km') AS DISTANCE_BETWEEN_POINTS
FROM DUAL 2 3 4 5 ;
DISTANCE_BETWEEN_POINTS
47.6389006
SQL> SELECT
sqrt(69.1 * (30.45 - 28.66667) * 69.1 * (30.45 - 28.66667) + 53.0 * (77.61667 - 77.43333) * 53.0 * (77.61667 - 77.43333)) * 1.609344
FROM DUAL 2 3 ;
SQRT(69.1*(30.45-28.66667)*69.1*(30.45-28.66667)+53.0*(77.61667-77.43333)*53.0*(
198.932013Please help.... -
SDO_GEOM.SDO_DISTANCE()
my sdo_version is showing me the latest one
hi guys is there anyissue for this sdo.geom package?? i need to use SDO_GEOM.SDO_DISTANCE() function alone..
many thanks
Kalingamy sdo_version is showing me the latest oneIs it easier say this than telling us the version?
hi guys is there any issue for this sdo.geom package??No issue.
i need to use SDO_GEOM.SDO_DISTANCE() function
Not a problem here. -
How Is sdo_geom.sdo_distance calculated in geodetic space?
Hi,
I'm new to oracle spatial -- but very familiar spatial SQL in Manifold GIS. In that package, there are two distance functions, a "distance", which returns the distance in native coordinates, and a "distanceEarth", which is used to return true distance (in meters) rather than degrees when working in lat/lon. When I author a basic distance query in oracle which finds the distances between all the geometries in one table and all the geometries in another table, the sgo_geom.sdo_distance will return the result in meters even when I am working in lat/lon. So when does the oracle distance function convert between degrees and meters? Is it really returning the true distance? In this clear?
thanks!In Oracle Spatial, we always return the true distance based on the coordinate system
of the geometry.
If the geometry has lat/long values for coordinates, and appropriate SRID is set,
we compute the true earth distance.
If there is no SRID set for the geometry, the distance returned will be computed
as if the long/lat values are x,y values.
siva -
SDO_DISTANCE - Tolerance
If I have 2 point parms (not layers), with lat/longs with decimal places from 5 to 7 long, and I wanted to calculate the distance to within 5 CM, the formula would be:
SELECT MDSYS.SDO_GEOM.SDO_DISTANCE(
mdsys.sdo_geometry(2001,8307,mdsys.sdo_point_type(f_long,f_lat,NULL),NULL,NULL),
mdsys.sdo_geometry(2001,8307,mdsys.sdo_point_type(t_long,t_lat,NULL),NULL,NULL),
.05,'unit=KM' ) AS km_dist2 FROM dual;
What would be the equivalent (roughly within 5 cm) using a unit=MILE? Would I need to use a Tolerance of .0005?
SELECT MDSYS.SDO_GEOM.SDO_DISTANCE(
mdsys.sdo_geometry(2001,8307,mdsys.sdo_point_type(f_long,f_lat,NULL),NULL,NULL),
mdsys.sdo_geometry(2001,8307,mdsys.sdo_point_type(t_long,t_lat,NULL),NULL,NULL),
.0005,'unit=MILE' ) AS mi_dist2 FROM dual;
Thanks,
JBIt looks like the Tolerance Check is ALWAYS being done against Meters, even though, the Unit is either KM or MILE. It looks like if we were to set the tolerance to 0.05 it will always consider any 2 points as 1 point ONLY IF they are within approx. 5 CM of each other, even if MILE is specified as the UNIT?
SELECT MDSYS.SDO_GEOM.SDO_DISTANCE(
mdsys.sdo_geometry(2001,8307,mdsys.sdo_point_type(-89.514366,43.072118,NULL),NULL,NULL),
mdsys.sdo_geometry(2001,8307,mdsys.sdo_point_type(-89.2879915,43.1564514,NULL),NULL,NULL),
18300,'unit=KM' ) AS km_dist2 FROM dual;
Result = 20.6698332651529
SELECT MDSYS.SDO_GEOM.SDO_DISTANCE(
mdsys.sdo_geometry(2001,8307,mdsys.sdo_point_type(-89.514366,43.072118,NULL),NULL,NULL),
mdsys.sdo_geometry(2001,8307,mdsys.sdo_point_type(-89.2879915,43.1564514,NULL),NULL,NULL),
18325,'unit=KM' ) AS km_dist2 FROM dual;
Result = 0.0
SELECT MDSYS.SDO_GEOM.SDO_DISTANCE(
mdsys.sdo_geometry(2001,8307,mdsys.sdo_point_type(-89.514366,43.072118,NULL),NULL,NULL),
mdsys.sdo_geometry(2001,8307,mdsys.sdo_point_type(-89.2879915,43.1564514,NULL),NULL,NULL),
18300,'unit=MILE' ) AS km_dist2 FROM dual;
Result = 12.843638939315
SELECT MDSYS.SDO_GEOM.SDO_DISTANCE(
mdsys.sdo_geometry(2001,8307,mdsys.sdo_point_type(-89.514366,43.072118,NULL),NULL,NULL),
mdsys.sdo_geometry(2001,8307,mdsys.sdo_point_type(-89.2879915,43.1564514,NULL),NULL,NULL),
18325,'unit=MILE' ) AS km_dist2 FROM dual;
Result = 0.0 -
ORA-13050: unable to construct spatial object
Hi
I'm executing the following query
select mdsys.sdo_geom.sdo_intersection (geoloc, :1, 20) geoloc, mdsys.sdo_geom.sdo_distance (mdsys.sdo_geom.sdo_intersection (geoloc, :2, 20), :3, 20) distance
from streets
where mdsys.sdo_relate (geoloc, :5, 'mask=touch querytype=window') = 'TRUE'
order by distance
In some locations the query works perfectly and in some other locations it throws
ORA-13050: unable to construct spatial object
Regards,
Néstor BoscánI found the problem
It seems I have invalid polygons in my data.
Regards,
Néstor Boscán -
ORA-13207: incorrect use of the [More than 2D not supported] operator
Oracle 8.1.7.4:
The same query works in an Oracle DB on Linux and Windows, but in a Solaris it gives me the following error:
cc_redes_met_coaxial@ORAG2> SELECT lot_f.lot_id id,
ROUND(MDSYS.SDO_GEOM.SDO_DISTANCE(lot_geom.geometry, ped_geom.geometry, 0.5),2) dist
FROM lot_f,
pedestal_f,
G_GEOMETRY_0 lot_geom,
2 G_GEOMETRY_0 ped_geom
WHERE lot_f.feat_num = lot_geom.feat_num
3 AND pedestal_f.acc_point_id = 611
AND pedestal_f.feat_num = ped_geom.feat_num
4 AND lot_f.g_version+0 = 0
AND (lot_f.g_next_version > 0 OR lot_f.g_next_version IS NULL)
5 AND pedestal_f.g_version+0 = 0
6 AND (pedestal_f.g_next_version > 0 OR pedestal_f.g_next_version IS NULL)
AND MDSYS.SDO_WITHIN_DISTANCE(lot_geom.geometry, ped_geom.geometry,'distance = 100' ) = 'TRUE';
7 8 9 10 11 12 13 14 SELECT lot_f.lot_id id,
ERROR at line 1:
ORA-29902: error in executing ODCIIndexStart() routine
ORA-13207: incorrect use of the [More than 2D not supported] operator
ORA-06512: at "MDSYS.SDO_INDEX_METHOD", line 84
ORA-06512: at line 1
The data is in 3D. I took a look at the trace file but no useful information. It does not have to be 2d, right?
I can use SDO_WITHIN_DISTANCE with data in 3d, can't I?
Does anyone know what is going on? Maybe a bug?
Regards,
AlexDaniel,
I created the spatial index in 2d, but if I collect stats on all tables the optimizer doesn't use the spatial index.
I tried to influence the optimizer using hints, but it seems to ignore the hint clause. The query I did is above:
SELECT /*+ INDEX(lot_geom G_GEOMETRY_0_SI) INDEX(ped_geom G_GEOMETRY_0_SI) */
lot_f.lot_id id,
ROUND(MDSYS.SDO_GEOM.SDO_DISTANCE(lot_geom.geometry, ped_geom.geometry, 0.5),2) dist
FROM lot_f,
pedestal_f,
G_GEOMETRY_0 lot_geom,
G_GEOMETRY_0 ped_geom
WHERE lot_f.feat_num = lot_geom.feat_num
AND pedestal_f.acc_point_id = 611
AND pedestal_f.feat_num = ped_geom.feat_num
AND lot_f.g_version+0 = 0
AND (lot_f.g_next_version > 0 OR lot_f.g_next_version IS NULL)
AND pedestal_f.g_version+0 = 0
AND (pedestal_f.g_next_version > 0 OR pedestal_f.g_next_version IS NULL)
AND MDSYS.SDO_WITHIN_DISTANCE(lot_geom.geometry, ped_geom.geometry,
'distance = 100' ) = 'TRUE';
So I "forced" a plan that uses the spatial indexes deleting the statistics from the tables that have geometry columns. The execution plan looks like this:
Execution Plan
0 SELECT STATEMENT Optimizer=CHOOSE (Cost=2652 Card=10182 Bytes=79969428)
1 0 CONCATENATION
2 1 NESTED LOOPS (Cost=876 Card=3428 Bytes=26923512)
3 2 NESTED LOOPS (Cost=121 Card=1078 Bytes=8450442)
4 3 NESTED LOOPS (Cost=4 Card=33 Bytes=129492)
5 4 TABLE ACCESS (FULL) OF 'PEDESTAL_F' (Cost=1 Card=1 Bytes=16)
6 4 TABLE ACCESS (BY INDEX ROWID) OF 'G_GEOMETRY_0' (Cost=3 Card=3268 Bytes=12771344)
7 6 INDEX (RANGE SCAN) OF 'G_GEOMETRY_0_PRIMARY' (UNIQUE) (Cost=2 Card=3268)
8 3 TABLE ACCESS (BY INDEX ROWID) OF 'G_GEOMETRY_0' (Cost=121 Card=3268 Bytes=12794220)
9 8 DOMAIN INDEX OF 'G_GEOMETRY_0_SI' (Cost=51)
10 2 TABLE ACCESS (BY INDEX ROWID) OF 'LOT_F' (Cost=1 Card=318 Bytes=4770)
11 10 INDEX (RANGE SCAN) OF 'GI_LOT_F0_FEAT_NUM_0' (UNIQUE) (Cost=1 Card=318)
12 1 NESTED LOOPS (Cost=876 Card=3428 Bytes=26923512)
13 12 NESTED LOOPS (Cost=121 Card=1078 Bytes=8450442)
14 13 NESTED LOOPS (Cost=4 Card=33 Bytes=129492)
15 14 TABLE ACCESS (FULL) OF 'PEDESTAL_F' (Cost=1 Card=1 Bytes=16)
16 14 TABLE ACCESS (BY INDEX ROWID) OF 'G_GEOMETRY_0' (Cost=3 Card=3268 Bytes=12771344)
17 16 INDEX (RANGE SCAN) OF 'G_GEOMETRY_0_PRIMARY' (UNIQUE) (Cost=2 Card=3268)
18 13 TABLE ACCESS (BY INDEX ROWID) OF 'G_GEOMETRY_0' (Cost=121 Card=3268 Bytes=12794220)
19 18 DOMAIN INDEX OF 'G_GEOMETRY_0_SI' (Cost=51)
20 12 TABLE ACCESS (BY INDEX ROWID) OF 'LOT_F' (Cost=1 Card=318 Bytes=4770)
21 20 INDEX (RANGE SCAN) OF 'GI_LOT_F0_FEAT_NUM_0' (UNIQUE) (Cost=1 Card=318)
But when I executed the query, I got:
cc_redes_met_coaxial@ORAG2> /
ROUND(MDSYS.SDO_GEOM.SDO_DISTANCE(lot_geom.geometry, ped_geom.geometry, 0.5),2) dist
ERROR at line 2:
ORA-03113: end-of-file on communication channel
Collecting stats on geometry tables makes the query work only because it doesn't use the spatial index.
I took a look the trace file, but I didn't see any interesting information. I can send you if you want.
Do you have any clue?
Regards,
Alex -
Getting ORA-13000 error using SDO_DISTANCE.
Hi!
I am having problem executing query with SDO_DISTANCE function.
System is Windows XP SP2, Oracle 10g latest version.
First tables creation codes:
CREATE TABLE BUILDINGS
B_NUM NUMBER CONSTRAINT C_PK_BUILDINGS PRIMARY KEY,
BUILDING MDSYS.SDO_GEOMETRY,
B_INFO VARCHAR2(20)
CREATE TABLE TREES
T_NUM NUMBER CONSTRAINT C_PK_TREES PRIMARY KEY,
TREE MDSYS.SDO_GEOMETRY,
T_INFO VARCHAR2(20)
Now metadata:
INSERT INTO USER_SDO_GEOM_METADATA
(TABLE_NAME, COLUMN_NAME, DIMINFO, SRID)
VALUES
'BUILDINGS', 'BUILDING',
MDSYS.SDO_DIM_ARRAY(
MDSYS.SDO_DIM_ELEMENT('X', 0, 230, 0.05),
MDSYS.SDO_DIM_ELEMENT('Y', 0, 120, 0.05)),
NULL
INSERT INTO USER_SDO_GEOM_METADATA
(TABLE_NAME, COLUMN_NAME, DIMINFO, SRID)
VALUES
'TREES', 'TREE',
MDSYS.SDO_DIM_ARRAY(MDSYS.SDO_DIM_ELEMENT('X', 0, 230, 0.05),
MDSYS.SDO_DIM_ELEMENT('Y', 0, 120, 0.05)),
NULL
Finaly, the query:
SELECT SDO_GEOM.SDO_DISTANCE(A.BUILDING, B.TREE, 0.005)
FROM BUILDINGS A, TREES B
WHERE A.B_NUM = 2 AND B.T_NUM = 3;
I must add that I have tried various variants, but always receive the same error: ORA-13000 dimension number is out of range
The data I've entered was new and entered.manually, so no problems with old data migration or anything like this. Here are input examples:
INSERT INTO TREES VALUES
1,
MDSYS.SDO_GEOMETRY
3,
NULL,
NULL,
MDSYS.SDO_ELEM_INFO_ARRAY(1, 3, 4),
MDSYS.SDO_ORDINATE_ARRAY(67, 105, 79, 99, 80, 111)
'TREE1'
INSERT INTO BUILDINGS VALUES
1,
MDSYS.SDO_GEOMETRY
3,
NULL,
NULL,
MDSYS.SDO_ELEM_INFO_ARRAY(1, 3, 1),
MDSYS.SDO_ORDINATE_ARRAY(5, 56, 5, 116, 64, 116, 64,56)
'Hall');
Thanks for any info!You are using the 8.1.5 format for your geometry data, you've specified your data incorrectly.
Use the 8.1.6 and higher format for your data:
MDSYS.SDO_GEOMETRY
2003,
NULL,
NULL,
MDSYS.SDO_ELEM_INFO_ARRAY(1,1003, 4),
MDSYS.SDO_ORDINATE_ARRAY(67, 105, 79, 99, 80, 111)
This assumes the geometry above is an optimized circle.
MDSYS.SDO_GEOMETRY
2003,
NULL,
NULL,
MDSYS.SDO_ELEM_INFO_ARRAY(1, 1003, 1),
MDSYS.SDO_ORDINATE_ARRAY(5, 56, 5, 116, 64, 116, 64,56, 5,56)
Note the last ordinate has to match the first for this polygon. -
Is SDO_DISTANCE bug between the line and multipoints?
SDO_GEOM.SDO_DISTANCE(MDSYS.SDO_GEOMETRY(2002,8307,null,MDSYS.SDO_ELEM_INFO_ARRAY(1,2,1),MDSYS.SDO_ORDINATE_ARRAY(113.363258142822,23.133208779985,113.3633,23.13331)),
MDSYS.SDO_GEOMETRY(2005,8307,null,MDSYS.SDO_ELEM_INFO_ARRAY(1,1,2),MDSYS.SDO_ORDINATE_ARRAY(
113.363258142822,23.1868700130491,113.365811605804,23.1322024265981))
,0.000005)
the result is 5955.609972214.
SDO_GEOM.SDO_DISTANCE(MDSYS.SDO_GEOMETRY(2002,8307,null,MDSYS.SDO_ELEM_INFO_ARRAY(1,2,1),MDSYS.SDO_ORDINATE_ARRAY(113.363258142822,23.133208779985,113.3633,23.13331)),
MDSYS.SDO_GEOMETRY(2005,8307,null,MDSYS.SDO_ELEM_INFO_ARRAY(1,1,2),MDSYS.SDO_ORDINATE_ARRAY(
113.365811605804,23.1322024265981,113.363258142822,23.1868700130491
,0.005)
the result is 284.072193675135.
In my points the results should be the same. Why are they different?
If change the Element_Info
SDO_GEOM.SDO_DISTANCE(MDSYS.SDO_GEOMETRY(2002,8307,null,MDSYS.SDO_ELEM_INFO_ARRAY(1,2,1),MDSYS.SDO_ORDINATE_ARRAY(113.363258142822,23.133208779985,113.3633,23.13331)),
MDSYS.SDO_GEOMETRY(2005,8307,null,MDSYS.SDO_ELEM_INFO_ARRAY(1,1,1,3,1,1),MDSYS.SDO_ORDINATE_ARRAY(
113.363258142822,23.1868700130491,113.365811605804,23.1322024265981))
,0.000005)
the result will be 284.072193675135.
Why?Is it a bug of SDO_DISTANCE?Have a look here:
Re: How to use java to store Multipolygon
this is the javadoc:
http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14373/oracle/spatial/geometry/JGeometry.html#JGeometry_int__int__int____double___
public JGeometry(int gtype,
int srid,
int[] elemInfo,
double[] ordinates)
Constructs a JGeometry instance with given information
Parameters:
gtype - the geometry type
srid - the SRS id; if 0 is used then the MDSYS.SDO_GEOMETRY.SDO_SRID will be set to null when converted into DB format.
elemInfo - geometry element info array
ordinates - geometry ordinates array
Maybe something like:
JGeometry ps = New JGeometry (2005, 8307, new int[]{1,1, YOUR NUMBER OF POINTS IN YOUR CLUSTER}, new double[]{YOUR ORDINATES})
Luc -
Spatial 9.0.1.2 SDO_DISTANCE never returns
Query:
select sdo_geom.SDO_DISTANCE (mdsys.sdo_geometry(2001, 8307, mdsys.sdo_point_type(28,235 -26,NULL), NULL, NULL),
mdsys.sdo_geometry(2001, 8307, mdsys.sdo_point_type(28, -26,NULL), NULL, NULL),
0.005) as distance from dual
On oracle 817 returns :235
on oracle 9012 the query never return a value
Thanks
WernerWerner,
Do you mean that the distance comes back as zero ?
If that is the case, there is a known bug in distance
that is causing this problem. This is fixed in the
9.0.1.3 patch set, so applying that patch would help.
siva -
Sdo_distance conversion
What is the proper value to convert a distance returned from the sdo_distance function to miles. I'm guessing that the returned value is cartesian or nautical. If it's nautical then should I multiply by 69.1 ? or do I need more precision or a different number. The srid I'm using is 8265.
If you are using Oracle9i or later, you can let Spatial do the conversion for you:
sdo_geom.sdo_distance(geom1,geom2,tolerance,'unit=mile')
you can get the SDO_UNIT and the conversion factor from meters by using the following select statement:
select sdo_unit,conversion_factor from mdsys.sdo_dist_units;
SDO_UNIT CONVERSION_FACTOR
M 1
METER 1
KM 1000
KILOMETER 1000
CM .01
CENTIMETER .01
MM .001
MILLIMETER .001
MILE 1609.344
NAUT_MILE 1852
SURVEY_FOOT .30480061
FOOT .3048
INCH .0254
YARD .9144
CHAIN 20.1168
ROD 5.0292
LINK .201166195
MOD_USFT .304812253
CL_FT .304797265
IND_FT .304799518
LINK_BEN .201167651
LINK_SRS .201167651
CHN_BEN 20.1167825
CHN_SRS 20.1167651
IND_YARD .914398554
SRS_YARD .914398415
FATHOM 1.8288
27 rows selected.
Sorry, I'm sure this message board will ruin the formatting, but I'm sure you get the idea. -
Hi,
I am trying to use SDO_GEOM.WITHIN_DISTANCE on geodetic data, but I don't want to use meter as unit for the tolerance. I thought I simply can set the unit to 'Degree', but this does not work:
select SDO_GEOM.WITHIN_DISTANCE(
MDSYS.SDO_GEOMETRY('POINT(0 0)', 4326),
+11,+
MDSYS.SDO_GEOMETRY('POINT(0 10)', 4326),
+0.00000000005,+
+'unit=Degree') from dual;+
ORA-13291: conversion error between the specified unit and standard unit
ORA-06512: at "MDSYS.SDO_3GL", line 985
ORA-06512: at "MDSYS.SDO_GEOM", line 1034
ORA-06512: at "MDSYS.SDO_GEOM", line 1049
ORA-06512: at line 1
+13291. 00000 - "conversion error between the specified unit and standard unit"+
*Cause: Cannot convert the specified unit from/to standard unit+
for linear distance, angle, or area.
*Action: Check the unit specification and respecify it.+
What am I doing wrong?
Update: How is the specified unit used? Is WITHIN_DISTANCE trying to convert my 10 degree into a meter value? Because then I would understand why it is not working.
Thanks,
Tobias
Edited by: tsauerwein on May 19, 2010 11:23 PMHI Tobias,
"Degree" is an angle unit, not a distance unit of measurement. For within_distance operations you must use a valid distance unit, which are defined in sdo_dist_units view.
if you indeed want to represent a distance unit in "decimal degree", you may try to define one for that by yourself.
regards
Jeffrey -
SDO_GEOM.RELATE in 8.1.7
I got 'UNKNOWN MASK: 110110001' returned when I used SDO_GEOM.RELATE function to check if 2 mutiplelinstrings are equal or not..
Even I tried to test this function with same geometry, I still got same error message.
BTW, for other geometry like simple polygon, this function works well.
Any suggestions?
Many thanks for your comments and help!
Jack
DECLARE
v_GEOM1 MDSYS.SDO_GEOMETRY;
v_GEOM2 MDSYS.SDO_GEOMETRY;
v_info VARCHAR2(80) ;
BEGIN
v_GEOM1:=MDSYS.SDO_GEOMETRY(2006,NULL, NULL, MDSYS.SDO_ELEM_INFO_ARRAY(1,2,1,11,2,1),
MDSYS.SDO_ORDINATE_ARRAY(8.07280413276778,53.62639558,8.07354916666667,53.6255908333333,
8.07360805555555,53.6255119444444,8.07365694444444,53.6254511111111,
8.073735,53.6253663888889,8.07253709607513,53.62639558,8.07276694444444,
53.6261461111111,8.07306055555556,53.6258655555556,8.073735,53.6253663888889,
8.07395,53.6251330555556,8.074015,53.6250625,8.07409694444445,53.6249738888889,
8.07414888888889,53.6249175,8.07421555555556,53.6248452777778,8.07446527777778,
53.6245747222222,8.07461333333333,53.6244141666667,8.07469027777778,
53.6243308333333,8.07517888888889,53.6238011111111));
v_GEOM2:=MDSYS.SDO_GEOMETRY(2003, NULL, NULL, MDSYS.SDO_ELEM_INFO_ARRAY(1, 1003, 1),
MDSYS.SDO_ORDINATE_ARRAY(8.07109464, 53.62356679, 8.07674003, 53.62356679, 8.07674003, 53.62639558,
8.07109464, 53.62639558, 8.07109464, 53.62356679));
SELECT MDSYS.SDO_GEOM.RELATE(v_GEOM1,'EQUAL', v_GEOM1,0.000000000001) INTO v_info FROM DUAL;
DBMS_OUTPUT.PUT_LINE(v_info);
END;Handle: dee
Status Level: Newbie (5)
Registered: Jun 14, 2010
Total Posts: 61
Total Questions: 30 (30 unresolved)
If its working , Please mark thread as answered why you leave your thread in Open Status
Maybe you are looking for
-
Hi All, i have a requirement files are coming to ftp.But those files are Ziped. I want to unzip it and at last want to archive it to some other folder. Please suggest how it can be done through SSIS package.I am using sql server 2005. Thanks i_pr
-
Considering I've tried everything to get iTunes up...
...and nothing seems to work... Should I call the Best Buy Geek Squad? Do they know anything about fixing iTunes?
-
is any function module available to change the date format yyyy/mm/dd to yyyy/mm Thanks Kumar
-
Error while executing application using Oracle Business Process Workspace
Hi all, I created a simple application to find the length of the message entered and then re direct it to other task depending on the size. but while i try to run the application using Oracle Business Process Workspace, a new popup window is opened a
-
Opening Robohelp 9 project in RBH version 8
I have found a low cost version of Robohelp 8 on the web. I have a project file that i created in the trial of RBH 9 will i be able to open it in the version 8 that i intend to buy?