This discussion is archived
2 Replies Latest reply: Mar 11, 2013 2:39 PM by bkazar RSS

SDO_Geometry -> J3D_Geometry Conundum

955911 Newbie
Currently Being Moderated
Hi all,

I am new to Oracle Spatial and Java, and also to this forum so apologies for any faux pas or ignorances! I am writing a program to place solar panels on roofs, using Oracle as a backend and java to do the calculations.

At the moment, I have successfully managed to connect to my database and extract the data using the cod below. I want to use Element_Extractor to decompose my 3D building into separate faces stored as JGeometry so that I can then carry out mathematical functions on the coordinates after. That is where I am stuck! The section ""while ((g = e.nextElement(inner_outer)) != null)"" is where I am stumped.

Any suggestions/links/ideas/example code would be much appreciated! Many Thanks,

Kelvin.

     public void loadcoords(String kmltablename) {
                    
          try {
               conn = createCon();
               String query = "select geometry from " + kmltablename;
               System.out.println(query);
               Statement stmt1 = createStatement();
               ResultSet rs = stmt1.executeQuery(query);
               System.out.println("Result Set = " + rs);
               
               
               while (rs.next()) {
                    //System.out.println("rs.getBytes = " + rs.getBytes(1));
                    byte[] image = rs.getBytes(1);

                    // convert image into a JGeometry object using the SDO pickler
                    JGeometry building = JGeometry.load(image);
                    J3D_Geometry building3D = new J3D_Geometry(building.getType(),
                              building.getSRID(), building.getElemInfo(),
                              building.getOrdinatesArray());

                    // Create new extractor
                    ElementExtractor e = new ElementExtractor(building3D, 0,
                              ElementExtractor.MULTICOMP_TOSIMPLE);

                    // Geometry to receive extracted element(s)
                    J3D_Geometry g;

                    // Used to receive the type of element (1=outer, 2=inner)
                    int inner_outer[] = { 0 };
                              
                    // Extract the elements
                    while ((g = e.nextElement(inner_outer)) != null) {
                         
                         // Process extracted element
                         String decomp = g.toStringFull();
                         System.out.println(decomp);
                         
                    }
                    
               }
               rs.close();
               stmt1.close();
               conn.close();
          } catch (ClassNotFoundException e) {
               System.out.println("Class Not Found Error");
               e.printStackTrace();
          } catch (SQLException e) {
               System.out.println("SQL Exception Error");
               e.printStackTrace();
          } catch (Exception e) {// Catch exception if any
               System.err.println("Error: " + e.getMessage());
          }

     }

Legend

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