|
Replies:
8
-
Pages:
1
-
Last Post:
Jul 7, 2007 6:44 AM
Last Post By: Hans Forbrich
|
|
|
Posts:
312
Registered:
06/27/07
|
|
|
|
fetching Spatial geometry Array values
Posted:
Jun 27, 2007 3:17 AM
|
|
|
How to fetch geometry of values
I wanted to fetch the 4th positioned n 5th positioned values from the
SDO_ORDINATE_ARRAY and one unique Column ID,
sample data for the same follows
SQL> desc TEST
Name Null? Type
--------
GEOMETRY MDSYS.SDO_GEOMETRY
ID NUMBER
SQL> select id, geometry from test
where rownum<7
;
TEST GEOMETRY(SDO_GTYPE, SDO_SRID, SDO_POINT(X, Y, Z), SDO_ELEM_INFO, SDO_ORDINATES)
1 SDO_GEOMETRY(2001, NULL, NULL, SDO_ELEM_INFO_ARRAY(1, 0, 6000, 4, 1, 1), SDO_ORDINATE_ARRAY(0, 1, 0, 408551.27, 2925997.25))
2 SDO_GEOMETRY(2001, NULL, NULL, SDO_ELEM_INFO_ARRAY(1, 0, 6000, 4, 1, 1), SDO_ORDINATE_ARRAY(.011493516, -.99993395, 0, 408442.69, 2925997.45))
3 SDO_GEOMETRY(2001, NULL, NULL, SDO_ELEM_INFO_ARRAY(1, 0, 6000, 4, 1, 1), SDO_ORDINATE_ARRAY(-.02636329, .999652428, 0, 408551.45, 2926096.46))
4 SDO_GEOMETRY(2001, NULL, NULL, SDO_ELEM_INFO_ARRAY(1, 0, 6000, 4, 1, 1), SDO_ORDINATE_ARRAY(0, 1, 0, 408551.77, 2926212.98))
5 SDO_GEOMETRY(2001, NULL, NULL, SDO_ELEM_INFO_ARRAY(1, 0, 6000, 4, 1, 1), SDO_ORDINATE_ARRAY(0, 1, 0, 408552.01, 2926314.81))
6 SDO_GEOMETRY(2001, NULL, NULL, SDO_ELEM_INFO_ARRAY(1, 0, 6000, 4, 1, 1), SDO_ORDINATE_ARRAY(1, 0, 0, 408470.67, 2926137.08))
6 rows selected.
SQL>
another table TESTZ is created to insert the fetched values from TEST
table
SQL> desc TESTZ
Name Null? Type
--------
TEST NUMBER
ES NUMBER
NR NUMBER
The following pl/sql program is used for fetching the required data
DECLARE
CURSOR p_cur
IS
select id,geometry from test order by rownum ;
es number;
nr number;
locus mdsys.sdo_geometry;
BEGIN
for i in p_cur
loop
locus := i.geometry ;
es:=locus.sdo_ordinates(4);
nr:=locus.sdo_ordinates(5);
insert into testz values(i.idz,es,nr);
end loop;
END;
/
ERROR at line 1:
ORA-06533: Subscript beyond count
ORA-06512: at line 20
the same Script is working well for other data sets But its giving the
following Errror for the ABOVE
data set, the test table got 90,000 records
please Suggest me the required Solution to fecth the 4th and 5th
postioned values from SDO_ORDINATE_ARRAY ;
Many thanks
ZAMEER
|
|
|
Posts:
7,547
Registered:
03/08/99
|
|
|
|
Re: fetching Spatial geometry Array values
Posted:
Jun 27, 2007 7:45 AM
in response to: FZ13
|
|
|
Personally, I suggest you to post this thread at the Spatial Data Forum.
~ Regards.
|
|
|
Posts:
10,458
Registered:
03/13/99
|
|
|
|
Re: fetching Spatial geometry Array values
Posted:
Jun 27, 2007 8:41 AM
in response to: FZ13
|
|
|
This is VARRAY stuff in PL/SQL and is not unique to Spatial. The PL/SQL docs provide some aditional help.
I understand this is really confusing. For myself, I often refer back to the Pro Oracle Spatial to verify the operations - that book has an excellent chapter (chapter 7) to work through this exact type of problem.
Here is my example:
SQL> connect test/test
Connected.
SQL> desc x3
Name Null? Type
--------
ID VARCHAR2(10)
SPAT SDO_GEOMETRY
SQL> insert into x3 values (1, sdo_geometry(2001, 8307, null, sdo_elem_info_array(1, 1003, 1),
2 sdo_ordinate_array(-77.02287, 39.90437,
3 -77.024645, 39.90409,
4 -77.02615, 39.90331)));
1 row created.
SQL> insert into x3 values (1, sdo_geometry(2001, 8307, null, sdo_elem_info_array(1, 1003, 1),
2 sdo_ordinate_array(-78.02287, 39.90437, -78.024645, 39.90409, -78.02615, 39.90331)));
1 row created.
SQL> commit;
Commit complete.
SQL> create or replace function get_array_mem(geom sdo_geometry, mem number default 1) return number
2 is
3 begin
4 if mem<1 or mem>geom.sdo_ordinates.count()
5 then
6 return null;
7 end if;
8
9 return geom.sdo_ordinates(mem);
10 end;
11 /
Function created.
SQL> select get_array_mem(spat, 2) from x3;
GET_ARRAY_MEM(SPAT,2)
39.90437
39.90437
SQL>
BTW - when posting code, I encourage you to use the 'code formatting' construct - prefix your code with ['pre'] and suffix it with ['/pre']
BTW2 - this is the 'installation forum' and the question would be more appropriate in either the SQL and PL/SQL forum or the Spatial forum. Both visible from http://forums.oracle.com > Database > More
|
|
|
Posts:
312
Registered:
06/27/07
|
|
|
|
Re: fetching Spatial geometry Array values
Posted:
Jun 30, 2007 2:12 AM
in response to: Hans Forbrich
|
|
|
|
dear Hans,
the code is Working fine vth the functions u've given, in my Requirement here i wanted to fetch 2 values at once and place them in a new table in to diffierent columns i.,e in single record in a table should contain the 4th & 5th postioned of the Array vales in 2 respective columns And ID unique Column.
SQL> DESC INSERT_TABLE
Name Null? Type
--------
fourth_positioned NUMBER fifth_positioned NUMBER
ID NUMBER
can u please Help out.
Many Thanks
ZameeR
|
|
|
Posts:
10,458
Registered:
03/13/99
|
|
|
|
Re: fetching Spatial geometry Array values
Posted:
Jun 30, 2007 7:10 AM
in response to: FZ13
|
|
|
|
If I was not too worried about performance. I'd do something like the following untested code:
INSERT INTO insert_table (id, fourth_positioned, fifth_positioned)
SELECT unique_seq.next_val, get_array_mem(spat, 4), get_array_mem(spat, 5)
FROM x3;
If I was worried about performance, I might be reading the PL/SQL User Manual, in the chapter on Collections, to get a better handle on what I was doing. [sic]
|
|
|
Posts:
457
Registered:
03/25/98
|
|
|
|
Re: fetching Spatial geometry Array values
Posted:
Jul 1, 2007 12:03 AM
in response to: Hans Forbrich
|
|
|
Personally, I would use an object and a function that returns it but here's something that works in straight SQL...
drop table test;
create table test (id integer, geometry mdsys.sdo_geometry);
insert into test (
id, geometry
) values (
1, SDO_GEOMETRY(2001, NULL, NULL, SDO_ELEM_INFO_ARRAY(1, 0, 6000, 4, 1, 1), SDO_ORDINATE_ARRAY(0, 1, 0, 408551.27, 2925997.25)));
insert into test (
id, geometry
) values (
2, SDO_GEOMETRY(2001, NULL, NULL, SDO_ELEM_INFO_ARRAY(1, 0, 6000, 4, 1, 1), SDO_ORDINATE_ARRAY(0, 1, 0, 508551.27, 3925997.25)));
commit;
select a0.id, c.column_value, e.column_value
from test a0,
(select b1.id, mod(rownum,5) rown, b2.*
from test b1,
table(b1.geometry.sdo_ordinates) b2
) c,
(select d1.id, mod(rownum,5) rown, d2.*
from test d1,
table(d1.geometry.sdo_ordinates) d2
) e
where ( c.id = a0.id and c.rown = 4 )
and ( e.id = a0.id and e.rown = 0 )
/
regards
Simon
|
|
|
Posts:
312
Registered:
06/27/07
|
|
|
|
Re: fetching Spatial geometry Array values
Posted:
Jul 2, 2007 2:11 AM
in response to: Hans Forbrich
|
|
|
|
Dear Hans,
The Scirpt u've Provided is Working Fine with my Requirement,
I do not find any Performance Issues,
Many thanks
ZameeR
|
|
|
Posts:
312
Registered:
06/27/07
|
|
|
|
Urgently Needed Trigger Help please
Posted:
Jul 7, 2007 2:18 AM
in response to: Hans Forbrich
|
|
|
Dear Hans,
Could u please Provide the Solution for the Following Requirement,
the details as follows,didnt get any response from PL/SQL forums Block , please do Help me in this regard,
Many Thanks
ZAMEER
On inserting SERVICE column into the table MAP_PDA The Columns XCAB, YCAB, XDP & YDP columns are left empty,
We have to update the columns XCAB, YCAB, XDP & YDP taking the values from MAP_PDA_DP , MAP_PDA_cabinet TABLES on Insertion.
please help in Writing a Trigger, which updates the XCAB, YCAB, XDP & YDP COLUMNS into MAP_PDA table on Insertions by taking the values from MAP_PDA_DP and MAP_PDA_CABINET ,
HERE Insertions is taking place into the table MAP_PDA (SERVICE) excpet the XCAB, YCAB, XDP & YDP columns., in the tables SERVICE is the unique and common Column in all tables,BASED on Service Column we need to update the XCAB, YCAB, XDP & YDP.,
TABLE Structures
SQL> desc MAP_PDA
Name Null? Type
--------
SERVICE VARCHAR2(100)
XCAB NUMBER(15,7)
YCAB NUMBER(15,7)
XDP NUMBER(15,7)
YDP NUMBER(15,7)
SQL> desc MAP_PDA_dp
Name Null? Type
--------
SERVICE VARCHAR2(100)
XDP NUMBER(15,7)
YDP NUMBER(15,7)
SQL> desc MAP_PDA_cabinet
Name Null? Type
--------
SERVICE VARCHAR2(100)
XCAB NUMBER(15,7)
YCAB NUMBER(15,7)
tables sample DATA
SQL> select * from map_pda_dp
where rownum<12;
SERVICE XDP YDP
14656678 46.6951059 24.6838268
14631615 46.6931104 24.6965182
14628004 46.6881358 24.6934382
14628042 46.6968004 24.6930734
14656631 46.6870479 24.7017963
14628086 46.6680757 24.7045349
14656676 46.6895173 24.7165425
14656639 46.6792683 24.6947766
14631617 46.686456 24.6797586
14658241 46.6973395 24.6903543
14628008 46.6900394 24.683718
SQL> select * from map_pda_CABINET ;
SERVICE XCAB YCAB
14162463 46.6733614 24.7004141
14656613 46.6838635 24.7037447
14631638 46.6754532 24.694261
14631630 46.6874459 24.7178064
14644557 46.6945441 24.6986835
14162467 46.6733614 24.7004141
12933266 46.6732582 24.7020294
12933262 46.6848151 24.6988623
14614310 46.6747191 24.6991448
14658268 46.7014387 24.6750658
12177759 46.6778083 24.6847673
SQL> DESC MAp_PDA
Name Null? Type
--------
SERVICE VARCHAR2(100)
XCAB NUMBER(15,7)
YCAB NUMBER(15,7)
XDP NUMBER(15,7)
YDP NUMBER(15,7)
On insertion of the Follwing Service column values
the in to map_pda, the XDP,YD,XCAB, YCAB
COLUMNS to be UPDATED IN THE MAP_PDA by taking taking values from map_pda_dp and
map_pda_cabinet tables EVRYTIME., BASED ON SERVICE UNIQUE common COLUMN IN EACH table,
sample data insertion on map_pda
for Service column
14656613
14631638
14631630
14644557
14162467
12933266
12933262
14614310
14658268
12177759
|
|
|
Posts:
10,458
Registered:
03/13/99
|
|
|
|
Re: Urgently Needed Trigger Help please
Posted:
Jul 7, 2007 6:44 AM
in response to: FZ13
|
|
|
|
I'd be using function based index and index based geometry to handle this - after getting a proper problem description. That is worth several days of consulting and/or training - not something I usually do on a [free] forum.
I encourage you to get the book I referenced. Fairly inexpensive used from Amazon. Gives you the tools to answer this yourself.
|
|
|
|
Legend
|
|
Guru : 2500
- 1000000
pts
|
|
Expert : 1000
- 2499
pts
|
|
Pro : 500
- 999
pts
|
|
Journeyman : 200
- 499
pts
|
|
Newbie : 0
- 199
pts
|
|
Oracle ACE Director
|
|
Oracle ACE Member
|
|
Oracle Employee ACE
|
|
Helpful Answer
(5 pts)
|
|
Correct Answer
(10 pts)
|
|