This discussion is archived
8 Replies Latest reply: Nov 13, 2012 11:36 AM by 471938 RSS

How to use java to store Multipolygon

793954 Newbie
Currently Being Moderated
I fell victim to the ORA-00939 problem of too many arguments when inserting a geometry object into the database, and found details on the forum to use java to insert it instead. The code located was:

double[] coords = new double[10000];
for(int i=0; i<coords.length; i++)
coords[i] = ....;

JGeometry mypoly = JGeometry.createLinearPolygon(coords, 2/*dimensions*/, 8256);

PreparedStatement ps = connection.prepareStatement("insert into states values(?)");
//convert JGeometry instance to DB STRUCT
STRUCT obj = JGeometry.store(mypoly, connection);
ps.setObject(1, obj);
ps.execute();


The SDO_GEOMETRY I want to insert is of SDO_GTYPE 2007 (collection of polygons) [in the example below, 2]
I can see in the sample code where to put the SRID (8307), but nowhere in the code, and nowhere in the Geometry class where I can create a multipolygon.
Anyone care to help with this?

As a secondary question: Some of the sites I'm updating have a boundary delineated by one polygon, some by more than one - can SDO_GTYPE 2007 be used for all, regardless of how many there are?




UPDATE LOC SET SITE_BOUNDARY=MDSYS.SDO_GEOMETRY(
2007,
8307,
SDO_POINT_TYPE(60.49772542, -1.452049075, NULL),
MDSYS.SDO_ELEM_INFO_ARRAY(1,1003,1, 105,1003,1),
MDSYS.SDO_ORDINATE_ARRAY(50.49678550013553,-7.217321117344117, ... <trimmed, you don't want to see it all>...)
)
WHERE SITECODE='970A3';
  • 1. Re: How to use java to store Multipolygon
    514170 Newbie
    Currently Being Moderated
    Replace the SDO_POINT_TYPE(60.49772542, -1.452049075, NULL) portion of the Geometry with NULL

    That is only used for Points and should be null when you have the SDO_ELEM_INFO_ARRAY and MDSYS.SDO_ORDINATE_ARRAY populated.

    Ronan
  • 2. Re: How to use java to store Multipolygon
    793954 Newbie
    Currently Being Moderated
    Noted. How about the main issues?
  • 3. Re: How to use java to store Multipolygon
    Luc Van Linden Pro
    Currently Being Moderated
    Hi

    Have you checked this:

    http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14373/oracle/spatial/geometry/JGeometry.html#JGeometry_int__int__int____double___

    the first param in the constructor is the gtype (in your case 2007).

    Luc
  • 4. Re: How to use java to store Multipolygon
    514170 Newbie
    Currently Being Moderated
    double[] coords = new double[10000];
    for(int i=0; i<coords.length; i++)
    coords = ....;

    JGeometry mypoly = JGeometry.createLinearPolygon(coords, 2/*dimensions*/, 8256);


    You cannot use this API to make a Multi Polygon.

    You muse pass an Object[] of double[]'s

    Object[] coords = new Object[2];
    for(int j=0; j<polys.length; j++) {
    double[] ring= new double[10000];
    for(int i=0; i<ring.length; i++) {
    ring= ....;
    }
    coords[j] = ring;
    }


    JGeometry mypoly = JGeometry.createLinearPolygon(coords, 2/*dimensions*/, 8256);

    THEn :

    //JGeometry API Bug !
    if ( coords.length > 1 && mypoly .getType() == 3 )
    {
    mypoly .setType( JGeometry.GTYPE_MULTIPOLYGON );
    }
  • 5. Re: How to use java to store Multipolygon
    793954 Newbie
    Currently Being Moderated
    Simplest answers are the best :-) I was being blinded by all the easy-use static methods and overlooked the standard constructors.

    Much thanks
  • 6. Re: How to use java to store Multipolygon
    919537 Newbie
    Currently Being Moderated
    This didn't work for me, but it got me close. I kept getting a null pointer exception on JGeometry.closeCoord when I used Object[]. Didn't matter if I made sure to close my rings or not. (The API docs suggest it will do this for you.)

    Nonethelss, the following example does work:

    double[] poly1 = {50,100, 51,101, 52,102, 53,103, 54,104};
    double[] poly2 = {60,110, 61,111, 62,112, 63,113};

    double[][] jpoly = {poly1, poly2};

    JGeometry jgeom = JGeometry.createLinearPolygon(jpoly, 2, 8307);

    The first array of doubles contains the x,y points seqentially. {x1,y1, x2,y2, x3,y3, ...}
    Then you just have an array of the array of doubles. One for each polygon in the multipolygon.

    Then, as luc said above, make sure you set the type correctly for multi or single polygon.

    jgeom.setType( JGeometry.GTYPE_MULTIPOLYGON );
    -or-
    jgeom.setType( JGeometry.GTYPE_POLYGON );

    I tested this using the sdoapi.jar from my Oracle 11.2.0.1 install, so I'm pretty sure I'm up to date.

    Hope that helps somebody else.
    -C.
  • 7. Re: How to use java to store Multipolygon
    922719 Newbie
    Currently Being Moderated
    Are you sure this creates a multi polygon? Using the same version 11g I get this when I try your example. This says that it created a polygon with a void that is outside of the original polygon. I am still trying to find the answer to this. Any ideas?

    JGeometry (gtype=7, dim=2, srid=8307,
    ElemInfo(1,1003,1,11,2003,1),
    Ordinates(50.0,100.0
    51.0,101.0
    52.0,102.0
    53.0,103.0
    50.0,100.0
    60.0,110.0
    61.0,111.0
    62.0,112.0
    60.0,110.0
    ))
  • 8. Re: How to use java to store Multipolygon
    471938 Oracle ACE Director
    Currently Being Moderated
    Also check out the following code, it contains valuable examples (GNU Lesser General Public License) for working with JGeometry: http://opensourcejavaphp.net/java/deegree/org/deegree/io/datastore/sql/oracle/JGeometryAdapter.java.html

    Kind regards, Ronald

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points