Geomtry to mdsys.sdo_geometry

Hi, i'm a newbie of Oracle Spatial, i'm working with sdoapi, i need to convert
geometries encoded with GML into valid geometries encoded in msdsys.sdo_geometry
to perform query throug SQL over other geoemtries stored into a table.
For example, if i've a box geometry in GML like this:
<gml:Box>
     <gml:coord>
          <gml:X>-103</gml:X>
          <gml:Y>31</gml:Y>
     </gml:coord>
     <gml:coord>
          <gml:X>-103.5</gml:X>
          <gml:Y>31.5</gml:Y>
     </gml:coord>
</gml:Box>
I would make a query like:
SELECT a.geometry
FROM My_Spatial_Table a
WHERE mdsys.sdo_relate(a.geometry, mdsys.sdo_geometry (2003, null, null,mdsys.sdo_elem_info_array (1,1003,3),mdsys.sdo_ordinate_array (-103,31,-103.5,31.5)),'querytype=WINDOW layer_gtype=notpoint') = 'TRUE';
I've look in sdoapi's samples that i can make an adapter from my
GML (XML) to Oracle's geometry, now i would know if i can map
this geometry into a mdsys.sdo_geometry form.
For geometries like point, box, there's no problems, but for geometries
like polygon, linestring, multipolygon i don't know how do this! :-(
Any tips or documentation for my problem?
Best Regards
Luigi

Are you positive that the data is only being saved
with 6 places of precisions ?
As far as I remember SQLPlus only displays up to 6
decimal points, although there are more in the data.
I remember a similar thread on this before where
there was a Tip that suggested setting the SQLPlus
number format highr in order to display the full
coordinates.
e.g. SET NUMFORMAT 9999999999999999.99999999999999999999999;
Ro

Similar Messages

  • Calling a SP or Function from Java receiving a geometry(MDSYS.SDO_GEOMETRY)

    Hi there,
    What I want to do is: calling a stored procedure OR function from Java with a String-variable as input and receiving a geometry (SDO_GEOMETRY).
    I’m facing currently the problem of calling a stored function on oracle 11g from Java using JPA (EclipseLink), Spring 2.5.6 returning an MDSYS.SDO_GEOMETRY object.
    I’ve tried to call a stored procedure with MDSYS.SDO_GEOMETRY as an output parameter instead, but with no success.
    The function’s signature looks like this:
    CREATE or REPLACE
    FUNCTION GET_GEO_BRD_FUNCTION(p_geo_brd_id IN VARCHAR2) RETURN MDSYS.SDO_GEOMETRY AS
    sdo_geom    MDSYS.SDO_GEOMETRY := null;
    BEGIN
    /* do some fancy stuff on the database side */
      SELECT sp_geom
        INTO sdo_geom
        FROM geo_brd WHERE id = p_geo_brd_id;
      RETURN sdo_geom;
    END;
    The calling code looks like this:
    MyClass extends JpaDaoSupport{
       /** logger */
       protected static final ILogger LOG = LogFactory.getLogger(MyClass.class);
        * {@inheritDoc}
        * @see com.example.MyClass#calculateGeometry(java.lang.String)
       @Override
       public JGeometry calculateGeometry(final String id) {
           JGeometry geometry = null;
           final JpaCallback action = new JpaCallback() {
                @Override
                public Object doInJpa(final EntityManager em) throws PersistenceException {
                   final Session session = JpaHelper.getEntityManager(em).getActiveSession();
                   final StoredFunctionCall functionCall = new StoredFunctionCall();
                   functionCall.setProcedureName("GET_GEO_BRD_FUNCTION");
                   functionCall.addNamedArgument("p_geo_brd_id");
                   functionCall.setResult("sdo_geom", Oracle.sql.STRUCT.class);
                   final ValueReadQuery query = new ValueReadQuery();
                   query.setCall(functionCall);
                   query.addArgument("p_geo_brd_id");
                   final ArrayList args = new ArrayList();
                   args.add("2e531e62-2105-4522-978a-ab8baf19e273");// hardcoded for test
                   final Object result = session.executeQuery(query, args);
                   return result;
        final STRUCT result = (STRUCT) this.getJpaTemplate().execute(action);
        try {
           geometry = JGeometry.load(result);
        } catch (final SQLException e) {
           MyClass.LOG.error("Error loading JGeometry from STRUCT.", e);
           return null;
        return geometry;
    And when I execute the query I get the following error:
    Internal Exception: java.sql.SQLException: ORA-06550: Row 1, Column 13:
    PLS-00382: expression is of wrong type
    ORA-06550: Row 1, Column 7:
    PL/SQL: Statement ignored
    Error Code: 6550
    Call: BEGIN ? := GET_GEO_BRD_FUNCTION(p_geo_brd_id=>?); END;
         bind => [=> sdo_geom, 2e531e62-2105-4522-978a-ab8baf19e273]
    Query: ValueReadQuery()
    So I thought may be let's try it with a stored procedure instead...
    The procedure looks like this:
    CREATE or REPLACE
    PROCEDURE GET_GEO_BRD_PROCEDURE(p_geo_brd_id IN VARCHAR2, sdo_geom OUT MDSYS.SDO_GEOMETRY) AS
    BEGIN
    /* do some fancy stuff on the database side */
      SELECT sp_geom
        INTO sdo_geom
        from geo_brd where id = p_geo_brd_id;
    END;
    The calling Java code in case of the stored procedure looks like this (only the content of the JPACallback has changed):
    @Override
    public Object doInJpa(final EntityManager em) throws PersistenceException {
        final Session session = JpaHelper.getEntityManager(em).getActiveSession();
        final StoredProcedureCall spCall = new StoredProcedureCall();
        spCall.setProcedureName("GET_GEO_BRD_PROCEDURE");
        spCall.addNamedArgument("p_geo_brd_id", "p_geo_brd_id", String.class);
        spCall.addNamedOutputArgument("sdo_geom", "sdo_geom", OracleTypes.STRUCT);
        final ValueReadQuery query = new ValueReadQuery();
        query.setCall(spCall);
        query.addArgument("p_geo_brd_id"); // input
        final List args = new ArrayList();
        args.add("2e531e62-2105-4522-978a-ab8baf19e273");// hardcoded for test
        final Object result = session.executeQuery(query, args);
        return result;
    And when I execute the query I get the following error:
    java.sql.SQLException: ORA-06550: Row 1, Column 13:
    PLS-00306: wrong number or types of arguments in call to 'GET_GEO_BRD_PROCEDURE'
    ORA-06550: Row 1, Column 7:
    PL/SQL: Statement ignored
    So both exceptions look quite similar.
    I guess in both cases the exception description leads to the assumption, that the wrong type for the return value / output parameter is used…
    So - how can a receive a MDSYS_SDO_GEOMETRY object from a stored procedure or stored function in Java ?
    What is wrong in the Java code?
    Thank you in advance for any suggestions!
    Yours,
    Chris
    Edited by: user3938161 on 20.12.2011 07:46
    Edited by: user3938161 on Dec 20, 2011 8:06 AM: added variable declaration of JGeometry geometry in source code

    Thanks, that did the trick! ;-)
    Here is now the code for stored procedure and function for anybody else encountering the same troubles... (be aware of the parameter order and/or naming!)
    Code for stored functions:
    final JpaCallback action = new JpaCallback() {
      @Override
      public Object doInJpa(final EntityManager em) throws PersistenceException {
         final Session session = JpaHelper.getEntityManager(em).getActiveSession();
           * Using CallableStatement for stored functions
          STRUCT st = null;
          CallableStatement cs = null;
          final DatabaseLogin login = session.getLogin();
          final Connection _conn = (Connection) login.connectToDatasource(session.getDatasourceLogin().buildAccessor(), session);
          try {
             try {
                cs = _conn.prepareCall("{? = call GET_GEO_BRD_FUNCTION(?)}");
                cs.registerOutParameter(1, OracleTypes.STRUCT, "MDSYS.SDO_GEOMETRY");
                cs.setString(2, "2e531e62-2105-4522-978a-ab8baf19e273");//TODO: hardcoded for test
                cs.execute();
             } catch (final SQLException e) {
                MyClass.LOG.error("An exception occured calling the stored procedure", e);
             if (cs != null) {
                //reading geometry from the database
                try {
                   st = (STRUCT) cs.getObject(1);
                } catch (final SQLException e) {
                   MyClass.LOG.error("An exception occured converting the query result to oracle.sql.STRUCT", e);
          } finally {
             try {
                if (_conn != null && !_conn.isClosed()) {
                    _conn.close();
             } catch (final SQLException e) {
                MyClass.LOG.error("An exception occured on closing the database connection.", e);
          return st;
    final STRUCT result = (STRUCT) this.getJpaTemplate().execute(action);
    The code for stored procedure solution:
    final JpaCallback action = new JpaCallback() {
      @Override
      public Object doInJpa(final EntityManager em) throws PersistenceException {
          final Session session = JpaHelper.getEntityManager(em).getActiveSession();
           * Using CallableStatement for stored procedure
          STRUCT st = null;
          CallableStatement cs = null;
          final DatabaseLogin login = session.getLogin();
          final Connection _conn = (Connection) login.connectToDatasource(session.getDatasourceLogin().buildAccessor(), session);
          try {
             try {
                cs = _conn.prepareCall("{call GET_GEO_BRD_PROCEDURE(?,?)}");
                cs.setString("p_geo_brd_id", "2e531e62-2105-4522-978a-ab8baf19e273");
                cs.registerOutParameter("sdo_geom", OracleTypes.STRUCT, "MDSYS.SDO_GEOMETRY");
                cs.execute();
              } catch (final SQLException e) {
                MyClass.LOG.error("An exception occured calling the stored procedure", e);
              if (cs != null) {
                //reading geometry from the database
                try {
                   st = (STRUCT) cs.getObject("sdo_geom");
                } catch (final SQLException e) {
                   MyClass.LOG.error("An exception occured converting the query result to oracle.sql.STRUCT", e);
           } finally {
              try {
                if (_conn != null && !_conn.isClosed()) {
                   _conn.close();
              } catch (final SQLException e) {
                MyClass.LOG.error("An exception occured on closing the database connection.", e);
            return st;
    final STRUCT result = (STRUCT) this.getJpaTemplate().execute(action);

  • Mdsys.sdo_geometry ( 2007 , ....

    Hello,
    I have one table with polygons (one by row, so sdo_gtype=2003 ) and I want to take some of them and place it in one single row of another table defined by sdo_gtype=2007 (multipolygon)
    I don't know if it's possible and how I can do that
    I know how to recover the sdo_ordinates and the
    sdo_elem_info but i don't know how to insert it in the field SHAPE of my new table
    Thanks a lot
    taofoo

    hi,
    You might want to let spatial create the geometry for you using sdo_geom.sdo_union. That was you can be sure the new geometry will be legal (it will be a multi-polygon if necessary, but also it will appropriately not create single elelments which overlap).

  • How to retreive x/y from mdsys.sdo_geometry

    I need to retreive the coord pair for a point table. If I use:
    select p.id, p.shape.sdo_point.x, p.shape.sdo_point.y from pointdatastore p
    the returned result is null. Said table was created from ESRI tools via ArcSDE which I believe is the root problem. I'm a newbie to Spatial but a lot of years with ESRI tools.
    Any help.

    Neil,
    Are you certain ESRI is storing the points as a SDO_POINT type? Although I do not know for certain I expect they are not - which is why you would be coming up with NULLs. Rather ESRI is probably using the ordinate array which you can select vertices from using SDO_UTIL.GETVERTICES (which is found in Oracle Spatial). here's the corresponding documentation:
    http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14255/sdo_util.htm#BABDEGIA
    I hope this helps.
    -Justin

  • Using OFFLINE_INSTANTIATION with a spatial object - SDO_GEOMETRY type

    Hello
    I am looking for guidance on the usage of DBMS_REPCAT_RGT.INSTANTIATE_OFFLINE for a table object with an SDO_GEOMETRY
    column defined.
    The table is:
    SQL> descr jtx.jtx_jobs_aoi
    Name Null? Type
    OBJECTID NOT NULL NUMBER(38)
    JOB_ID NUMBER(10)
    SHAPE MDSYS.SDO_GEOMETRY
    SE_ANNO_CAD_DATA BLOB
    The mview is defined as:
    CREATE MATERIALIZED VIEW jtx.JTX_JOBS_AOI REFRESH FAST WITH PRIMARY KEY FOR UPDATE AS
    SELECT * FROM JTX.JTX_JOBS_AOI@ncgsdb_master_s;
    And the command we are using is:
    SQL> SET SERVEROUTPUT ON
    SQL>
    SQL> DECLARE
    2 dt_num NUMBER;
    3 BEGIN
    4 dt_num := DBMS_REPCAT_RGT.INSTANTIATE_OFFLINE(
    5 refresh_template_name => 'jtx_refg_dt',
    6 user_name => 'jtx',
    7 site_name => 'NCGSDB_MVSITE1',
    8 next_date => SYSDATE,
    9 interval => 'SYSDATE + (1/96)');
    10 DBMS_OUTPUT.PUT_LINE('Template ID = ' || dt_num);
    11 END;
    12 /
    When we run this on an 11.1.0.6 database we get:
    DECLARE
    ERROR at line 1:
    ORA-30373: object data types are not supported in this context
    ORA-06512: at "SYS.DBMS_REPCAT_RGT_CUST", line 1991
    ORA-06512: at "SYS.DBMS_REPCAT_RGT", line 1330
    ORA-06512: at line 4
    Now the strange thing is this appears to work for ONLINE_INSTANTIATION.
    1. Is this supported?
    2. If so what are we doing wrong?
    Thanks
    Richard

    Here a full example with  CAST MULTISET as @PhilHerring wrote and with CAST COLLECT using the simplest possible function make_geometry:
    CREATE OR REPLACE TYPE t_sdo_geometries AS TABLE OF MDSYS.sdo_geometry;
    CREATE OR REPLACE FUNCTION make_geometry (p_points t_sdo_geometries)
      RETURN t_sdo_geometries IS
    BEGIN
      RETURN p_points;
    END;
    SELECT make_geometry (
            t_sdo_geometries (
              sdo_geometry(2001, 32774, sdo_point_type(1, 1, null), null, null),
              sdo_geometry(2001, 32774, sdo_point_type(2, 2, null), null, null),
              sdo_geometry(2001, 32774, sdo_point_type(3, 3, null), null, null),
              sdo_geometry(2001, 32774, sdo_point_type(4, 4, null), null, null)))
            AS geom
      FROM DUAL;
    WITH geoms(pcol) AS
    (SELECT sdo_geometry(2001, 32774, sdo_point_type(1, 1, null), null, null) FROM dual UNION ALL
      SELECT sdo_geometry(2001, 32774, sdo_point_type(2, 2, null), null, null) FROM dual UNION ALL
      SELECT sdo_geometry(2001, 32774, sdo_point_type(3, 3, null), null, null) FROM dual UNION ALL
      SELECT sdo_geometry(2001, 32774, sdo_point_type(4, 4, null), null, null) FROM dual)
    SELECT make_geometry(cast(multiset(select pcol from geoms a) as t_sdo_geometries)) FROM dual;
    WITH geoms(pcol) AS
    (SELECT sdo_geometry(2001, 32774, sdo_point_type(1, 1, null), null, null) FROM dual UNION ALL
      SELECT sdo_geometry(2001, 32774, sdo_point_type(2, 2, null), null, null) FROM dual UNION ALL
      SELECT sdo_geometry(2001, 32774, sdo_point_type(3, 3, null), null, null) FROM dual UNION ALL
      SELECT sdo_geometry(2001, 32774, sdo_point_type(4, 4, null), null, null) FROM dual)
    SELECT make_geometry(cast(collect(pcol) as t_sdo_geometries)) FROM geoms;
    Hope that helps
    _jum

  • More than one SDO_GEOMETRY columns in one Oracle 8i spatial table

    I have a spatial table as follows:
    CREATE TABLE TEST(
    ID VARCHAR2(255) NOT NULL,
    POINT MDSYS.SDO_GEOMETRY,
    LINE MDSYS.SDO_GEOMETRY,
    POLYGON MDSYS.SDO_GEOMETRY,
    PRIMARY KEY(ID));
    Is it a good practice to have more than one SDO_GEOMETRY columns
    in one spatial table? What are the drawbacks if any to have a
    spatial with more than one layer?

    I have one question about more than one SDO_GEOMETRY columns
    in one table in Oracle 8.1.7. When I wanted to create two
    spatial indices for this table, every time I got some error.
    Can anyone tell me how to figure it out?
    Thanks very much,
    Fan Fan,
    You need to insert metadata record before creating spatial
    indices.
    Try the following:
    REM USER_SDO_GEOM_METADATA :
    REM insert a row for the geom layer for TEST TEST2 tables
    REM
    INSERT INTO USER_SDO_GEOM_METADATA
    ( TABLE_NAME, COLUMN_NAME, DIMINFO, SRID)
    VALUES ('TEST', 'POINT', MDSYS.SDO_DIM_ARRAY
    (MDSYS.SDO_DIM_ELEMENT('LON', -180,
    180, .000005),MDSYS.SDO_DIM_ELEMENT('LAT', -90, 90, .000005)),
    NULL);
    INSERT INTO USER_SDO_GEOM_METADATA
    ( TABLE_NAME, COLUMN_NAME, DIMINFO, SRID)
    VALUES ('TEST', 'LINE', MDSYS.SDO_DIM_ARRAY
    (MDSYS.SDO_DIM_ELEMENT('LON', -180,
    180, .000005),MDSYS.SDO_DIM_ELEMENT('LAT', -90, 90, .000005)),
    NULL);
    INSERT INTO USER_SDO_GEOM_METADATA
    ( TABLE_NAME, COLUMN_NAME, DIMINFO, SRID)
    VALUES ('TEST', 'POLYGON', MDSYS.SDO_DIM_ARRAY
    (MDSYS.SDO_DIM_ELEMENT('LON', -180,
    180, .000005),MDSYS.SDO_DIM_ELEMENT('LAT', -90, 90, .000005)),
    NULL);
    REM create a spatial index based on TRAFFIC.GEOM
    REM
    REM
    CREATE INDEX TEST_G_POINT_IDX ON TEST(POINT) INDEXTYPE IS
    MDSYS.SPATIAL_INDEX;
    CREATE INDEX TEST_G_LINE_IDX ON TEST(LINE) INDEXTYPE IS
    MDSYS.SPATIAL_INDEX;
    CREATE INDEX TEST_G_POLYGON_IDX ON TEST(POLYGON) INDEXTYPE IS
    MDSYS.SPATIAL_INDEX;

  • 4.0EA3 BUG: Database copy of a SDO_GEOMETRY column fails

    I'm trying to copy a table that has a SDO_GEOMETRY column and it just fails:
    When copying a error message appears:
    Error occurred inserting data for TABLE: CLIENT_LOCATION.  Batch 1 containing 500 rows failed.
      ORA-00932: inconsistent datatypes: expected MDSYS.SDO_GEOMETRY got CHAR
    The problem seems to be present also in sql developer 3.2.20.09: https://forums.oracle.com/message/11001171

    It's still a bug. Limitation in the JDBC driver and user defined types is causing the issue.

  • How to insert Sdo_Geometry from VB

    Hi,
    I have some queries for you guys. After trying several times, I still cannot make it work.
         Here is the scenario:
         I am retrieving a Polygon object from Oracle Spatial DB and I wanted to insert it into another Spatial Database.
    I am using the Oracle Object for OLE (OO4O). The Polygons contain attributes as well. I intend to insert
    the Attributes and the Geometries at the same time.
    Please find my code below for your reference.
    Public Function ConnectToOracle(sDBName As String, sUserAndPassword As String) As OraDatabase
    Dim OraSession As OraSession
    Dim OraDatabase As OraDatabase
    Set OraSession = CreateObject("OracleInProcServer.XOraSession")
    Set OraDatabase = OraSession.OpenDatabase(sDBName, sUserAndPassword, ORADB_DEFAULT)
    Set ConnectToOracle = OraDatabase
    End Function
    Public Function RetrieveRecord(sBldgID As String) As String
    Dim oraDB As OraDatabase
    Dim DS As OraDynaset
    Dim Ordinates As OraCollection
    Dim sdo_geometry As OraObject
    Dim sql As String
    Dim sGeom As String
    Dim sBldg_ID As String, sMainBldg_ID As String, sEstate_ID As String, sCat_ID As String, sBldg_Type As String, sCat_Type As String
    Dim sStatCode As String, sName As String, sMRC As String
    Dim DteCreate, DteDelete, dteUpdate
    Dim sAttributes As String
    Set oraDB = ConnectToOracle("service1", "user1/pwd1")
    sql = "select a.bldg_id,a.main_bldg_id,a.estate_id,a.cat_bldg_id,a.bldg_type, " & _
    "a.cat_type,a.bldg_type,a.status_code,a.name,a.centroid_mrc, a.dte_create,a.dte_delete, " & _
    "a.dte_update, b.geometry from bldg a, bldg_geom b where a.bldg_id='" & sBldgID & "' and b.bldg_id=' " & sBldgID & "'"
    Set DS = oraDB.CreateDynaset(sql, ORADB_DEFAULT)
    If Not DS.EOF Then
    Set sdo_geometry = DS.Fields("geometry").Value
    If Not IsNull(sdo_geometry.Item("sdo_ordinates").Value) Then
    Set Ordinates = sdo_geometry.Item("sdo_ordinates").Value
    sBldg_ID = DS.Fields("bldg_id").Value
    sMainBldg_ID = DS.Fields("main_bldg_id").Value
    sEstate_ID = IIf(IsNull(DS.Fields("estate_id").Value), """", DS.Fields("estate_id").Value)
    sCat_ID = DS.Fields("cat_bldg_id").Value
    sBldg_Type = DS.Fields("bldg_type").Value
    sCat_Type = DS.Fields("cat_type").Value
    sStatCode = DS.Fields("status_code").Value
    sName = DS.Fields("name").Value
    sMRC = DS.Fields("centroid_mrc").Value
    DteCreate = CDate(DS.Fields("dte_create").Value)
    If (IsNull(DS.Fields("dte_delete").Value)) Then
    DteDelete = DateTime.Date
    Else
    DteDelete = CDate(DS.Fields("dte_delete").Value)
    End If
    If (IsNull(DS.Fields("dte_update").Value)) Then
    dteUpdate = DateTime.Date
    Else
    dteUpdate = CDate(DS.Fields("dte_update").Value)
    End If
    Else
    MsgBox "No geometry!"
    End If
    ' Concatenate all the Geometries separated by comma
    For i = 1 To Ordinates.Size
    If i = 1 Then
    sGeom = Ordinates(i)
    Else
    sGeom = sGeom & "," & Ordinates(i)
    End If
    Next i
    sAttributes = "'" & sBldg_ID & "','" & sMainBldg_ID & "','" & sEstate_ID & "','" & sCat_ID & "','" & sBldg_Type & "','" & _
    sCat_Type & "','" & sStatCode & "','" & sName & "','" & sMRC & "','" & _
    DteCreate & "','" & DteDelete & "','" & dteUpdate & "'"
    End If
    DS.Close
    Set DS = Nothing
    Call InsertSingleRecord(sAttributes, sGeom)
    End Function
    Public Function InsertSingleRecord(sAttributes As String, sGeometry As String)
    Dim oraDB As OraDatabase
    Dim sql As String
    Set oraDB = ConnectToOracle("service2", "user2/pwd2")
    sql = "Insert into bldg(bldg_id,main_bldg_id,estate_id,cat_bldg_id,bldg_type,cat_type,status_code,name,centroid_mrc,geom) " & _
    "values ( " & sAttributes & ", " & _
    "MDSYS.SDO_GEOMETRY ( " & _
    "2003, NULL, NULL, " & _
    "MDSYS.SDO_ELEM_INFO_ARRAY (1,1003,1), " & _
    "MDSYS.SDO_ORDINATE_ARRAY ( " & sGeometry & " )" & _
    oraDB.ExecuteSQL sql
    oraDB.Close
    Set oraDB = Nothing
    End Function
    After running this code, I successfully retrieved the data and able to manipulate it by concatenating them and stored in a variable to be inserted to database. During the insertion comes the problem, the error message is "ORA-00907: missing right parenthesis".
    I tried to manually execute the SQL Statement in the SQL Plus and it gives me the same error message. My observation is that the SQL Plus truncates the statement at a certain length. By the way, I checked the length of the resulting SQL from VB and it gives me 3096 characters. I am not sure if there is a limitation on the SQL statement length.
    I cannot figure out what's wrong with this code. I hope you can help me.
    I would appreciate any feedback from you guys and thank you in advance.
    Best Regards,
    Arnold Higuit
    Singapore

    Hi Daniel,
    Thank you for your reply. Here is the SQL Statement that was stored in the variable. I extracted this statement from the immediate window of VB IDE while debugging the code.
    Insert into bldg(bldg_id,main_bldg_id,estate_id,cat_bldg_id,bldg_type,cat_type,status_code,name,centroid_mrc,geom) values ( 'P0750109270947202318','P0750109270947202318','"','P0750109270947202318','BT6','GO1','SC2','Istana','19489D8262', MDSYS.SDO_GEOMETRY ( 2003, NULL, NULL, MDSYS.SDO_ELEM_INFO_ARRAY (1,1003,1), MDSYS.SDO_ORDINATE_ARRAY ( 103.843218549901','1.30748186974166','103.843111698469','1.30753323638373','103.843175054448','1.3076666268715','103.843218549901','1.3076457365646','103.843286364106','1.30761206827051','103.843309190232','1.30765384888431','103.84336940088','1.30762445775988','103.84334855182','1.30758014498768','103.843450820054','1.30752724096372','103.843387104607','1.30739810088471','103.843380274743','1.30740307476731','103.843372007012','1.30738697747455','103.843413076066','1.30736617760188','103.843373624612','1.30728487723001','103.843367873147','1.30728704765151','103.843359875016','1.30727303034601','103.843375601678','1.30726724255536','103.84337901661','1.30727167383258','10
    3.84338998034','1.30726751385805','103.843385846475','1.30725919390898','103.843432397393','1.30723839403631','103.843426915528','1.30722446716504','103.843435183259','1.30722030719051','103.843425657395','1.30719525690908','103.843437969125','1.30718838390768','103.843401033936','1.30711097220766','103.843384408608','1.30711802607752','103.843328781159','1.30699919550062','103.843419097131','1.30695343578075','103.843372725945','1.30686028852489','103.843282409974','1.30690604824476','103.84322372706','1.3067892072209','103.843234466425','1.30678423766741','103.843218549901','1.30675736008999','103.84319024191','1.30670124147699','103.843174515249','1.30670929012337','103.84316058592','1.30668188855198','103.843135692861','1.30669454934404','103.843128323797','1.30667998943317','103.843023898763','1.30673343606251','103.843030908361','1.306747453368','103.843003229437','1.30676165154195','103.843015720899','1.3067864305207','103.843003499037','1.3067926704825','103.843040973425','1.30686709785296','103.8430
    19495298','1.3068781308289','103.843067214483','1.30697272503243','103.843021292631','1.30699614749774','103.843012935034','1.30697959803383','103.842944995855','1.30701432477776','103.842937716658','1.30699985530112','103.842849647353','1.30704480111293','103.842855129217','1.30705565322041','103.842784314307','1.30709191734624','103.842804290778','1.30713151608386','103.842819395053','1.3071608264333','103.842755284935','1.30718898377967','103.842727570789','1.30713392035982','103.842402269693','1.30729272579281','103.842486918126','1.30745403780143','103.842796133371','1.30730154741566','103.842762964268','1.30723686242187','103.842840463056','1.30720170959418','103.842874899878','1.30726853539547','103.842937447058','1.30723787819184','103.842943827589','1.30725099115504','103.843037468626','1.30720496013248','103.843030728628','1.30719085239276','103.843098667806','1.30715757259649','103.843094623807','1.30714916221319','103.843139377393','1.30712691539286','103.843187006711','1.30721762092454','103.843
    218549901','1.30720498324404','103.84322585379','1.30720205696391','103.843278414575','1.30731373992449','103.843285873506','1.30730731909423','103.843297196702','1.30733381632332','103.843290906038','1.30733589631059','103.843326313493','1.30741005237836','103.843336378556','1.30740326981119','103.843341860421','1.30741855319589','103.843218549901','1.30748121514446 )) )
    The error message is:
    Run-time error '440':
    SQL Execution error, 0RA-00907: missing right parenthesis
    And here is the equivalent statement and error in SQL Plus after I copied and pasted the code.
    SQL> Insert into bldg(bldg_id,main_bldg_id,estate_id,cat_bldg_id,bldg_type,cat_type,status_code,name
    ,centroid_mrc,geom)
    2 values ('P0750109270947202318','P0750109270947202318','"','P0750109270947202318','BT6','GO1','S
    C2','Istana','19489D8262',
    3 MDSYS.SDO_GEOMETRY ( 2003, NULL, NULL, MDSYS.SDO_ELEM_INFO_ARRAY (1,1003,1), MDSYS.SDO_ORDINATE
    _ARRAY ( 103.843218549901,1.30748186974166,103.843111698469,1.30753323638373,103.843175054448,1.3076
    666268715,103.843218549901,1.3076457365646,103.843286364106,1.30761206827051,103.843309190232,1.3076
    5384888431,103.84336940088,1.30762445775988,103.84334855182,1.30758014498768,103.843450820054,1.3075
    2724096372,103.843387104607,1.30739810088471,103.843380274743,1.30740307476731,103.843372007012,1.30
    738697747455,103.843413076066,1.30736617760188,103.843373624612,1.30728487723001,103.843367873147,1.
    30728704765151,103.843359875016,1.30727303034601,103.843375601678,1.30726724255536,103.84337901661,1
    .30727167383258,10
    4 3.84338998034,1.30726751385805,103.843385846475,1.30725919390898,103.843432397393,1.30723839403
    631,103.843426915528,1.30722446716504,103.843435183259,1.30722030719051,103.843425657395,1.307195256
    90908,103.843437969125,1.30718838390768,103.843401033936,1.30711097220766,103.843384408608,1.3071180
    2607752,103.843328781159,1.30699919550062,103.843419097131,1.30695343578075,103.843372725945,1.30686
    028852489,103.843282409974,1.30690604824476,103.84322372706,1.3067892072209,103.843234466425,1.30678
    423766741,103.843218549901,1.30675736008999,103.84319024191,1.30670124147699,103.843174515249,1.3067
    0929012337,103.84316058592,1.30668188855198,103.843135692861,1.30669454934404,103.843128323797,1.306
    67998943317,103.843023898763,1.30673343606251,103.843030908361,1.306747453368,103.843003229437,1.306
    76165154195,103.843015720899,1.3067864305207,103.843003499037,1.3067926704825,103.843040973425,1.306
    86709785296,103.8430
    5 19495298,1.3068781308289,103.843067214483,1.30697272503243,103.843021292631,1.30699614749774,10
    3.843012935034,1.30697959803383,103.842944995855,1.30701432477776,103.842937716658,1.30699985530112,
    103.842849647353,1.30704480111293,103.842855129217,1.30705565322041,103.842784314307,1.3070919173462
    4,103.842804290778,1.30713151608386,103.842819395053,1.3071608264333,103.842755284935,1.307188983779
    67,103.842727570789,1.30713392035982,103.842402269693,1.30729272579281,103.842486918126,1.3074540378
    0143,103.842796133371,1.30730154741566,103.842762964268,1.30723686242187,103.842840463056,1.30720170
    959418,103.842874899878,1.30726853539547,103.842937447058,1.30723787819184,103.842943827589,1.307250
    99115504,103.843037468626,1.30720496013248,103.843030728628,1.30719085239276,103.843098667806,1.3071
    5757259649,103.843094623807,1.30714916221319,103.843139377393,1.30712691539286,103.843187006711,1.30
    721762092454,103.843
    6 218549901,1.30720498324404,103.84322585379,1.30720205696391,103.843278414575,1.30731373992449,1
    03.843285873506,1.30730731909423,103.843297196702,1.30733381632332,103.843290906038,1.30733589631059
    ,103.843326313493,1.30741005237836,103.843336378556,1.30740326981119,103.843341860421,1.307418553195
    89,103.843218549901,1.30748121514446 )) )
    7
    SQL> /
    3.84338998034,1.30726751385805,103.843385846475,1.30725919390898,103.843432397393,1.30723839403631,1
    ERROR at line 4:
    ORA-00907: missing right parenthesis
    We are actually dealing with large polygons and this one is just an example of a building outline.
    The other objects we have are Boundaries and Islands. I am worried about the 999 ordinates limitation. I can just hope that our largest Boundary would not reach that number.
    I hope you can spot the problem. Once again many thanks.
    Best Regards,
    Arnold

  • How can i return a SDO_GEOMETRY value in a Java-Stored-Function?

    For a example, Ive got a java-function witch returns a
    oracle.sdoapi.geom.Geometry like:
    public static Geometry GetQPoint(String sF_TABLE_NAME, long lFID)
    And now, Ill try to deploy this function as a PL-SQL stored-function like:
    GET_Q_POINT(
    F_TABLE_NAME IN VARCHAR2,
    FID IN NUMBER
    ) RETURN MDSYS.SDO_GEOMETRY;
    I can't deploy this above mentioned java-function with Oracle9i JDeveloper because oracle.sdoapi.geom.Geometry can not mapped in any PL-SQL data type.
    Is there any possibility to do it in a other way?
    Please help me.

    a quick example that takes as input a longitude and latitude,
    and return a point geometry in wgs 84:
    CREATE OR REPLACE FUNCTION get_geom (
         longitude IN          NUMBER,
         latitude     IN          NUMBER )
         RETURN mdsys.sdo_geometry
         DETERMINISTIC IS
         BEGIN
    RETURN mdsys.sdo_geometry (2001,8307,
              mdsys.sdo_point_type (longitude, latitude, NULL), NULL, NULL );
    END;
    other pl/sql examples:
    REM
    REM This function doesn't really do anything, but demonstrates some simple
    REM mechanisms on how to manipulate the array portion of the geometry object, and
    REM also how to write a function that returns a geometry object.
    REM
    REM The function demonstrates:
    REM 1) .EXTEND (there is also .DELETE)
    REM 2) .COUNT
    REM 3) Any function that returns an object (including the SDO_GEOMETRY object)
    REM should be declared as DETERMINSTIC (see below).
    REM
    create or replace function create_geometry return mdsys.sdo_geometry deterministic as
    temp_geom mdsys.sdo_geometry := mdsys.sdo_geometry (2002, 8307, null,
    mdsys.sdo_elem_info_array (1,2,1),
    mdsys.sdo_ordinate_array ());
    begin
    for i in 1 .. 10 loop
    temp_geom.sdo_ordinates.extend (2);
    temp_geom.sdo_ordinates(temp_geom.sdo_ordinates.count-1) := i;
    temp_geom.sdo_ordinates(temp_geom.sdo_ordinates.count) := i+1;
    end loop;
    return temp_geom;
    end;
    select create_geometry from dual;
    set linesize 80
    set pages 1000
    drop table TEST_MODIFY;
    create table TEST_MODIFY (geom mdsys.sdo_geometry);
    insert into TEST_MODIFY values
    (mdsys.sdo_geometry (2002, 8307, null,
    mdsys.sdo_elem_info_array (1,2,1),
    mdsys.sdo_ordinate_array (1,1, 2,2, 3,3, 4,4)));
    insert into TEST_MODIFY values
    (mdsys.sdo_geometry (2002, 8307, null,
    mdsys.sdo_elem_info_array (1,2,1),
    mdsys.sdo_ordinate_array (21,21, 22,22, 23,23, 24,24)));
    REM
    REM Select values before update.
    REM
    select geom from TEST_MODIFY;
    REM
    REM This PL*SQL block updates all the ordinates of a geometry by adding 10 to each x value
    REM and 20 to each y value.
    REM
    declare
    i NUMBER;
    cursor c1 is select geom, rowid
    from TEST_MODIFY;
    begin
    for r in c1 loop
    i := 1;
    while (i < r.geom.sdo_ordinates.count) loop
    r.geom.sdo_ordinates(i) := r.geom.sdo_ordinates(i) + 10;
    r.geom.sdo_ordinates(i+1) := r.geom.sdo_ordinates(i+1) + 20;
    i := i + 2;
    end loop;
    update TEST_MODIFY set geom = r.geom where rowid = r.rowid;
    end loop;
    end;
    REM
    REM Select values after update.
    REM
    select geom from TEST_MODIFY;

  • Extracting x,y co-ordinates of SDO_GEOMETRY into two variables say x1, ya

    Hi All,
    I am able to store the output SDO_GEOMETRY into a variable but i am facing difficulties in extracting ordinates in sdo_geometry to two independent variables say xa, ya. Kindly suggest some solution.
    The procedure is as follows:
    CREATE OR REPLACE PROCEDURE fnd_2nd_Point
    (Input_Fiber_Id IN NUMBER,
    xa IN FLOAT,
    ya IN FLOAT,
    Length_Fiber IN FLOAT,
    Result OUT VARCHAR,
    xCordInAte OUT FLOAT,
    yCordInAte OUT FLOAT)
    IS
    ProjPoint_a mdsys.sDo_Geometry := NULL;
    v_Point_xa FLOAT := NULL;
    v_Point_ya FLOAT := NULL;
    BEGIN
    SELECT sDo_lrs.Project_pt(a.Shape,m.DimInfo,mdsys.Sdo_geometry(2001,8307,NULL,mdsys.Sdo_elem_info_array(1,1,1),
    mdsys.Sdo_ordinate_array(xa,ya,Length_Fiber)))
    INTO {color:#0000ff}ProjPoint_a
    {color}FROM lrs_Access_Fiber a,
    User_sDo_geom_MetAdAta m
    WHERE m.Table_Name = 'LRS_ACCESS_FIBER'
    AND m.Column_Name = 'SHAPE'
    AND a.Unique_Id = Input_Fiber_Id;
    {color:#0000ff}-- SELECT t.x, t.y INTO v_Point_xa, v_Point_ya FROM TABLE(sDo_util.Getvertices(ProjPoint_a)) t;
    {color}
    {color:#0000ff}-- dbms_Output.Put_Line('Point Xa is ' ||v_Point_xa||' and point Ya is '||v_Point_ya);
    {color}
    {color:#0000ff}-- xCordInAte := v_Point_xa;
    {color}
    {color:#0000ff}-- yCordInAte := v_Point_ya;
    {color}
    -- Result := 'success';
    END;
    Kindly advice on the options available to extract the ordinates of sdo_geometry into 2 independent variables.
    Regards,
    Venkat

    Please find the output as below for the following inputs: INPUT_FIBER_ID :=2005; XA := 78.424; YA := 17.643; LENGTH_FIBER :=500;
    Point Xa is 78.48686988 and point Ya is 17.61674904
    RESULT = success
    XCORDINATE = 78.48686988
    YCORDINATE = 17.61674904
    Is this output correct? Actually, I have to integrate this with UMN MapServer. Kindly advice
    Regards
    Venkat

  • How to get the x1,y1 and z1 coordinates out of an sdo_geometry object?

    Hello,
    i have stored several boxes into an sdo_geometry object like the following:
    mdsys.sdo_geometry(3003,null,null,
    mdsys.sdo_elem_info_array(1,1003,3),
    mdsys.sdo_ordinate_array(x1,y1,z1,x2,y2,z2)
    now i would like to get the x1,y1,z1 coordinates from the boxes. how can i get them with a simple sql-statement?
    When i do "SELECT v.shape.sdo_ordinates ..." then i get a sdo_ordinate_array. But how can i get only the first coorinates?
    I know how it works to get x1,y1 and z1 over a java-prog. But i want to get them with a sql-statement as i also want to get the min and max x1,y1,z1.
    Hope there is anybody that can help me. Thanks in advance.
    Markus Veith

    You can get coordinates from an SDO_POINT_TYPE as follows:
    SELECT      t.GEOMETRY.SDO_POINT.x,t.GEOMETRY.SDO_POINT.y
    FROM      TABLE T
    (where geometry is the geometry column and table is the geometry table, note
    that a table alias must be used.)
    Getting the coordinates from the SDO_ORDINATES is a little trickier.
    You'll need to use a loop in PL/SQL, eg:
    SET SERVEROUT ON
    DECLARE
    i number;
    j NUMBER;
    BEGIN
    FOR sel IN (SELECT <geom_column> FROM <geom_table> WHERE ROWNUM < 10) LOOP
    i := 1;
    while i < sel.<geom_column>.sdo_ordinates.count LOOP
    j:= sel.GEOMETRY.sdo_ordinates(i);
    dbms_output.put_line(j);
    i := i + 1;
    j:= sel.GEOMETRY.sdo_ordinates(i);
    end loop;
    dbms_output.put_line(j);
    END LOOP;
    END;
    This will print the SDO_ORDINATES to the SQLPLUS screen, put a WHERE clause to reduce output.
    To use these values in a query, put them in a cursor.

  • How to define SDO_GEOMETRY

    Hello,
    I created an Oracle Object Type named MDSYS.SDO_GEOMETRY (no Attributes). Then I defined on table "COUNTIES" a column named "GEOMETRY" with this data type.
    While trying to generate the table into the database I run into:
    CDS-11349 Warning: The Oracle Object Type MDSYS.SDO_GEOMETRY cannot be generated.
    CDS-18025 Error: Table 'COUNTIES' will not be created as Oracle Object Type 'MDSYS.SDO_GEOMETRY' is not created
    Processing Complete: 1 error(s), 1 warning(s)
    How can SDO_GEOMETRY types be defined?
    Thanks Jan

    Hello Jan
    We have stored it as follows:
    - create three oracle object types (in the server tab of the DE) with the names SDO_POINT_TYPE, SDO_DIM_ELEMENT and MDSYS.SDO_GEOMETRY
    - create attributes for SDO_POINT_TYPE: X, Y and Z, all the datatype NUMBER
    - create attributes for SDO_DIM_ELEMENT: SDO_LB, SDO_UB, SDO_TOLERANCE (all 3 NUMBER) and SDO_DIMNAME (VARCHAR2(64))
    - create 3 oracle collection types:
    --- MDSYS.SDO_DIM_ARRAY (object datatype SDO_DIM_ELEMENT, the one we have just created)
    --- MDSYS.SDO_ELEM_INFO_ARRAY (scalar datatype NUMBER)
    --- MDSYS.SDO_ORDINATE_ARRAY(scalar datatype NUMBER)
    - create attributes for MDSYS.SDO_GEOMETRY:
    --- SDO_ELEM_INFO based on oracle type MDSYS.SDO_ELEM_INFO_ARRAY
    --- SDO_ORDINATES, based on oracle type MDSYS.SDO_ORDINATE_ARRAY
    --- SDO_POINT, based on oracle type SDO_POINT_TYPE
    --- SDO_GTYPE, based on datatype number
    --- SDO_SRID, based on datatype number
    Than the same, add it to a column in a table an this should do the trick...
    good luck...
    Alex
    [email protected]

  • Got confused!! MDSYS.SDO_WITHIN_DISTANCE (8.1.7),

    I used the following query to select GID whose GEOM is within some distance from a point, circle, polygon and rectangle. It works well in 8.1.6 version.
    When I upgrade from 8.1.6 to 8.1.7, only rectangle one works and other shapes end with a message of "ORA-03113: end-of-file on communication channel"(disconnected with my lovely orcale:(
    (1)Select lines within some distance from A Rectangle(works both in 8.1.6 and 8.1.7)
    SELECT L.LINE_ID
    FROM LINE L
    WHERE
    MDSYS.SDO_WITHIN_DISTANCE(L.Geom, mdsys.sdo_geometry(2003,NULL,NULL, mdsys.sdo_elem_info_array(1,1003,3), mdsys.sdo_ordinate_array(1,5,8,15),'distance = 1') = 'TRUE';
    (2) Select lines within some distance from a Polygon.(ONLY works in 8.1.6)
    SELECT L.LINE_ID
    FROM LINE L
    WHERE
    MDSYS.SDO_WITHIN_DISTANCE(L.Geom,MDSYS.SDO_GEOMETRY(2003, NULL, NULL, MDSYS.SDO_ELEM_INFO_ARRAY(1, 1003, 2), MDSYS.SDO_ORDINATE_ARRAY(1,3,1,1,4,1, 4,4, 1,3)),'distance =1') = 'TRUE';
    (3) Select lins within some distance from a point.(ONLY work in 8.1.6)
    SELECT L.LINE_ID
    FROM LINE L
    WHERE
    SDO_WITHIN_DISTANCE(L.Geom,mdsys.sdo_geometry(2001,NULL,NULL,
    mdsys.sdo_elem_info_array(1,1,1),
    mdsys.sdo_ordinate_array(3,3)),'distance =1') = 'TRUE';
    (4) Select lines within some distance from a Cirlce(ONLY works in 8.1.6)
    SELECT L.LINE_ID
    FROM LINE L
    WHERE
    MDSYS.SDO_WITHIN_DISTANCE(L.Geom,MDSYS.SDO_GEOMETRY(2003, NULL, NULL,
    MDSYS.SDO_ELEM_INFO_ARRAY(1, 1003, 4),
    MDSYS.SDO_ORDINATE_ARRAY(1,3, 2,1, 3,3)),'distance = 0.01') = 'TRUE';
    Anyhelp?
    Thanks in advance!
    Jerry.
    null

    Thank you, Dave.
    It is good to know 8.1.7 have SRID work.
    I think it is also safe to stay that field 'NULL' if we don't want to use these new coordinate system functions.
    We check the error 'ORA-03113:end of file..' and find it is likely related to an R-tree index bug. After runniing the 8.1.7 patch, the problem is sloved.
    Someone also saw that problem happened in sdo_relate statement several days ago.
    Thanks for your help.
    Jerry
    null

  • JDBC insert empty STRUCT (JGeometry) into SDO_GEOMETRY

    Hi!
    I need to insert empty or null value intro oracle table with SDO_GEOMETRY field.
    I'm using prepared statement.
    I have tried pstmt.setNull(1, null), pstmt.setObject(1, null)
    Normaly I do it like this:
    STRUCT obj = JGeometry.store(jgeom, conn);
    pstmt.setObject(1, obj);
    So I probably need to create an empty STRUCT or something.
    I have also tried using :
    StructDescriptor type_descriptor = StructDescriptor.createDescriptor ("MDSYS.SDO_GEOMETRY", conn); but I don't know if I'm using it right.
    The syntax is like:
    StructDescriptor structdesc = StructDescriptor.createDescriptor (sql_type_name, connection); but I don't know what sql_type_name means? Is it tablename, fieldname? Tried them all...no success.
    I've read that JDBC doesn't support that kind of insert with setNull, is there a workaround or any other way of doing this.
    Thanks in advance and have a nice day.
    Simon

    http://www.oracle.com/technology/tech/java/sqlj_jdbc/pdf/a96654.pdf seems to have the clues that you are looking for.
    BTW, we are adding a Connection.createStruct/Array method so that you can create these types of objects in portable with JDBC in JDBC 4

  • Error using mdsys.sdo_relate()

    Hi, I am using Oracle 8.1.5 and i am trying to execute the following sql statement
    SQL> select p.name
    2 from parks p
    3 where mdsys.sdo_relate(p.shape,
    mdsys.sdo_geometry(
    3,null,null,
    mdsys.sdo_elem_info_array(1,3,3),
    4 mdsys.sdo_ordinate_array(10,10,20,20)),
    5 'mask=anyinteract querytype=window')
    = 'true';
    But i recieved the following error message
    ERROR at line 1:
    ORA-29902: error in executing ODCIIndexStart() routine
    ORA-13207: incorrect use of the [SDO_RELATE] operator
    ORA-06512: at "MDSYS.SDO_INDEX_METHOD", line 73
    ORA-06512: at line 1
    Do anyone know how to recify this?
    Thanks!
    null

    Ops, sorry it's TRUE not true
    I managed to solved it. Thanks:>
    brian
    null

Maybe you are looking for