[Liblas-commits] r1264 - in trunk: apps python/examples

liblas-commits at liblas.org liblas-commits at liblas.org
Fri May 15 00:40:06 EDT 2009


Author: hobu
Date: Fri May 15 00:40:06 2009
New Revision: 1264
URL: http://liblas.org/changeset/1264

Log:
more PC stuff

Modified:
   trunk/apps/las2oci.cpp
   trunk/python/examples/oci_pc.py

Modified: trunk/apps/las2oci.cpp
==============================================================================
--- trunk/apps/las2oci.cpp	(original)
+++ trunk/apps/las2oci.cpp	Fri May 15 00:40:06 2009
@@ -1,7 +1,84 @@
 #include "oci_wrapper.h"
+#include <string>
+#include <sstream>
+#include <iostream>
 
+using namespace std;
 
+OWStatement* Run(OWConnection* connection, ostringstream& command) 
+{
+    OWStatement* statement = 0;
+    statement = connection->CreateStatement(command.str().c_str());
+    
+    if (statement->Execute() == false) {
+        delete statement;
+        return 0;
+    }
+    
+    return statement;    
+}
+
+bool Cleanup(OWConnection* connection, const char* tableName)
+{
+    ostringstream oss;
+    OWStatement* statement = 0;
+    
+    oss << "DELETE FROM " << tableName;
+    statement = Run(connection, oss);
+    if (statement != 0) delete statement; else return false;
+    oss.str("");
+
+    oss << "DROP TABLE " << tableName;
+    cout << oss.str() << endl;
+    statement = Run(connection, oss);
+    if (statement != 0) delete statement; else return false;
+    oss.str("");    
+    
+    oss << "DROP TABLE BLKTAB ";
+    statement = Run(connection, oss);
+    if (statement != 0) delete statement; else return false;
+    oss.str("");
+    
+    oss << "DROP TABLE RES ";
+    statement = Run(connection, oss);
+    if (statement != 0) delete statement; else return false;
+    oss.str("");
+
+    oss << "DROP TABLE INPTAB ";
+    statement = Run(connection, oss);
+    if (statement != 0) delete statement; else return false;
+    oss.str("");
+
+    oss << "DROP TABLE LIDAR_DATA";
+    statement = Run(connection, oss);
+    if (statement != 0) delete statement; else return false;
+    oss.str("");    
+
+    oss << "DELETE FROM USER_SDO_GEOM_METADATA WHERE TABLE_NAME='"<< tableName << "'";
+    statement = Run(connection, oss);
+    if (statement != 0) delete statement; else return false;
+    oss.str("");
+
+    return true;
+    
+    
+}
 
+
+bool CreateTable(OWConnection* connection, const char* tableName)
+{
+    ostringstream oss;
+    OWStatement* statement = 0;
+    
+    oss << "CREATE TABLE "<< tableName <<" (ID VARCHAR2(24), VAL_D1 NUMBER, VAL_D2 NUMBER, VAL_D3 NUMBER)";
+    statement = Run(connection, oss);
+    if (statement != 0) delete statement; else return false;
+    oss.str("");
+    
+    return true;
+    
+
+}
 void usage() {}
 
 int main(int argc, char* argv[])
@@ -59,54 +136,56 @@
     
     OWConnection* con = new OWConnection("lidar","lidar","ubuntu/crrel.local");
     if (con->Succed()) printf("succeded");
+    
+    Cleanup(con, "base");
+    CreateTable(con, "inptab");
 
-
- int   iCol = 0;
-    char  szField[OWNAME];
-    int   hType = 0;
-    int   nSize = 0;
-    int   nPrecision = 0;
-    signed short nScale = 0;
-
-    char szColumnList[OWTEXT];
-    szColumnList[0] = '\0';
-    OCIParam* phDesc = NULL;
-
-    const char* pszVATName="base";
-    phDesc = con->GetDescription( (char*) pszVATName );
-    while( con->GetNextField(
-                phDesc, iCol, szField, &hType, &nSize, &nPrecision, &nScale ) )
-    {
-        printf("field ... %s",szField);
-        switch( hType )
-        {
-            case SQLT_FLT:
-                printf("float...\n");
-                break;
-            case SQLT_NUM:
-                printf ("number...\n");
-                break;
-            case SQLT_CHR:
-            case SQLT_AFC:
-            case SQLT_DAT:
-            case SQLT_DATE:
-            case SQLT_TIMESTAMP:
-            case SQLT_TIMESTAMP_TZ:
-            case SQLT_TIMESTAMP_LTZ:
-            case SQLT_TIME:
-            case SQLT_TIME_TZ:
-                printf ("character...\n");
-                break;
-            default:
-                CPLDebug("GEORASTER", "VAT (%s) Column (%s) type (%d) not supported"
-                    "as GDAL RAT", pszVATName, szField, hType );
-                break;
-        }
-        // strcpy( szColumnList, CPLSPrintf( "%s substr(%s,1,%d),",
-        //     szColumnList, szField, MIN(nSize,OWNAME) ) );
-
-        iCol++;
-    }
+ // int   iCol = 0;
+ //    char  szField[OWNAME];
+ //    int   hType = 0;
+ //    int   nSize = 0;
+ //    int   nPrecision = 0;
+ //    signed short nScale = 0;
+ // 
+ //    char szColumnList[OWTEXT];
+ //    szColumnList[0] = '\0';
+ //    OCIParam* phDesc = NULL;
+ // 
+ //    const char* pszVATName="base";
+ //    phDesc = con->GetDescription( (char*) pszVATName );
+ //    while( con->GetNextField(
+ //                phDesc, iCol, szField, &hType, &nSize, &nPrecision, &nScale ) )
+ //    {
+ //        printf("field ... %s",szField);
+ //        switch( hType )
+ //        {
+ //            case SQLT_FLT:
+ //                printf("float...\n");
+ //                break;
+ //            case SQLT_NUM:
+ //                printf ("number...\n");
+ //                break;
+ //            case SQLT_CHR:
+ //            case SQLT_AFC:
+ //            case SQLT_DAT:
+ //            case SQLT_DATE:
+ //            case SQLT_TIMESTAMP:
+ //            case SQLT_TIMESTAMP_TZ:
+ //            case SQLT_TIMESTAMP_LTZ:
+ //            case SQLT_TIME:
+ //            case SQLT_TIME_TZ:
+ //                printf ("character...\n");
+ //                break;
+ //            default:
+ //                CPLDebug("GEORASTER", "VAT (%s) Column (%s) type (%d) not supported"
+ //                    "as GDAL RAT", pszVATName, szField, hType );
+ //                break;
+ //        }
+ //        // strcpy( szColumnList, CPLSPrintf( "%s substr(%s,1,%d),",
+ //        //     szColumnList, szField, MIN(nSize,OWNAME) ) );
+ // 
+ //        iCol++;
+ //    }
 
 
 

Modified: trunk/python/examples/oci_pc.py
==============================================================================
--- trunk/python/examples/oci_pc.py	(original)
+++ trunk/python/examples/oci_pc.py	Fri May 15 00:40:06 2009
@@ -24,7 +24,7 @@
 
     i= 0
 
-    commit_frequency = 10000
+    commit_frequency = 100000
     sql = """INSERT INTO LIDAR_DATA (ID, GEOMETRY) 
                 VALUES (:id, 
                         MDSYS.SDO_GEOMETRY(3001, NULL, MDSYS.SDO_POINT_TYPE(:x,:y,:z), NULL, NULL))"""
@@ -58,8 +58,15 @@
                 "DROP TABLE BLKTAB",
                 "DROP TABLE INPTAB",
                 "DROP TABLE LIDAR_DATA",
+                "DROP TABLE RES",
                 "DELETE FROM USER_SDO_GEOM_METADATA WHERE TABLE_NAME='BASE'",
                 "DROP TABLE RESTST",
+                "DELETE FROM HOBU",
+                "DROP TABLE HOBU",
+                "DROP TABLE hobures",
+                "DROP TABLE FOO",
+                "DELETE FROM USER_SDO_GEOM_METADATA WHERE TABLE_NAME='FOO'",
+                "DROP INDEX hobu_cloud_idx"
                 ]
 
 run(cleanup)                    
@@ -72,3 +79,213 @@
 insert_lidar(filename)
 
 
+inptab = ["""
+CREATE TABLE inptab NOLOGGING AS
+  SELECT TO_CHAR(a.id)          rid,
+         a.geometry.sdo_point.x val_d1,
+         a.geometry.sdo_point.y val_d2,
+         a.geometry.sdo_point.z val_d3
+  FROM lidar_data a
+"""]
+run(inptab)
+
+base = ["""
+create table base (pc sdo_pc)"""]
+run(base)
+
+blocktab = ["""
+create table blktab as select * from mdsys.sdo_pc_blk_table"""]
+run(blocktab)
+
+res = ["""
+create table res (ptn_id number, point_id number,
+rid varchar2(24), val_d1 number, val_d2 number, val_d3 number)"""]
+run(res)
+
+truncates = ["""truncate table res""","truncate table blktab"]
+run(truncates)
+
+
+init = [
+"""insert into base values (sdo_pc_pkg.init(
+          'BASE', -- Table that has the SDO_POINT_CLOUD column defined
+          'PC',   -- Column name of the SDO_POINT_CLOUD object 
+          'BLKTAB', -- Table to store blocks of the point cloud
+           'blk_capacity=50', -- max # of points per block 
+           mdsys.sdo_geometry(2003, 8307, null,
+              mdsys.sdo_elem_info_array(1,1003,3),
+              mdsys.sdo_ordinate_array(-180, -90, 180, 90)),  -- Extent 
+     0.5, -- Tolerance for point cloud
+           3, -- Total number of dimensions
+           null))
+           """]
+           
+code ="""
+declare
+  pc sdo_pc;
+begin
+  -- Initialize the Point Cloud object. 
+  pc := sdo_pc_pkg.init(
+          'BASE', -- Table that has the SDO_POINT_CLOUD column defined
+          'PC',   -- Column name of the SDO_POINT_CLOUD object 
+          'BLKTAB', -- Table to store blocks of the point cloud
+           'blk_capacity=20000', -- max # of points per block 
+           mdsys.sdo_geometry(2003, 8307, null,
+              mdsys.sdo_elem_info_array(1,1003,3),
+              mdsys.sdo_ordinate_array(630250.00,4834500.00,630500.00,4834750.00)),  -- Extent 
+     0.5, -- Tolerance for point cloud
+           3, -- Total number of dimensions
+           null);
+
+  -- Insert the Point Cloud object  into the "base" table.
+  insert into base values (pc);
+
+  -- Create the blocks for the point cloud.
+  sdo_pc_pkg.create_pc(
+    pc,       -- Initialized PointCloud object
+    'INPTAB', -- Name of input table to ingest into the pointcloud
+    'RES'     -- Name of output table that stores the points (with ptn_id,pt_id)
+  );
+end;"""
+run([code])
+
+con.commit()
+
+
+code = """
+create table restst as select * from mdsys.sdo_pc_blk_table
+
+
+"""
+run([code])
+
+code ="""
+
+declare
+  inp  sdo_pc;
+begin
+  select pc INTO inp  from base where rownum=1;
+  insert into restst
+  select * from
+    table(sdo_pc_pkg.clip_pc
+	  (
+            inp,  -- Input Point Cloud object
+            sdo_geometry(2003, 8307, null,
+              mdsys.sdo_elem_info_array(1, 1003, 3),
+              mdsys.sdo_ordinate_array(630355, 4834609,630395,  4834641)), -- Query 
+	    null, null, null, null));
+end;
+"""
+# -- 630355 4834609 630395 4834641
+#               mdsys.sdo_ordinate_array(630355, 630395, 4834609,4834641)), -- Query 
+# 
+# --              mdsys.sdo_ordinate_array(-74.1, -73.9, 39.99999,40.00001)), -- Query 
+
+run([code])
+
+sql = "select num_points, blk_id from restst order by blk_id"
+cur.execute(sql)
+for i in cur.fetchall():
+    print i
+
+sql = "select NUM_POINTS, POINTS from blktab where blk_id=10"
+cur.execute(sql)
+
+num, pts = cur.fetchone()
+
+data = pts.read()
+
+import struct
+
+# big-endian DOUBLE, DOUBLE, DOUBLE, LONG, LONG
+format = '>dddll'
+size = struct.calcsize(format)
+
+for i in xrange(num):
+    rng = size*i,size*(i+1)
+  #  print rng
+    d = struct.unpack(format,data[size*i:size*(i+1)])
+
+con.commit()
+
+
+code = ["create table foo as select * from blktab",
+        "create table hobures as select * from mdsys.sdo_pc_blk_table"]
+run(code)
+
+
+base = ["""
+create table HOBU (CLOUD sdo_pc)"""]
+run(base)
+
+code = """
+INSERT INTO user_sdo_geom_metadata VALUES (
+    'foo',
+    'blk_extent',
+    MDSYS.SDO_DIM_ARRAY(
+MDSYS.SDO_DIM_ELEMENT('X', 630250.000000, 630500.000000, 0.05),
+MDSYS.SDO_DIM_ELEMENT('Y', 4834500, 4834750, 0.05)),
+    8307)
+"""
+#MDSYS.SDO_DIM_ELEMENT('Z', 46.830000, 170.650000, 0.05)),
+
+run([code])
+
+index=["""CREATE INDEX hobu_cloud_idx ON foo (blk_extent)
+INDEXTYPE IS MDSYS.SPATIAL_INDEX"""]
+run(index)
+
+code ="""
+declare
+  pc sdo_pc;
+begin
+  -- Initialize the Point Cloud object. 
+  pc := sdo_pc_pkg.init(
+          'HOBU', -- Table that has the SDO_POINT_CLOUD column defined
+          'CLOUD',   -- Column name of the SDO_POINT_CLOUD object 
+          'FOO', -- Table to store blocks of the point cloud
+           'blk_capacity=20000', -- max # of points per block 
+           mdsys.sdo_geometry(2003, 8307, null,
+              mdsys.sdo_elem_info_array(1,1003,3),
+              mdsys.sdo_ordinate_array(630250.00,4834500.00,630500.00,4834750.00)),  -- Extent 
+     0.5, -- Tolerance for point cloud
+           3, -- Total number of dimensions
+           null);
+
+  -- Insert the Point Cloud object  into the "base" table.
+  insert into hobu values (pc);
+
+
+end;"""
+run([code])
+con.commit()
+
+
+code ="""
+
+declare
+  inp  sdo_pc;
+begin
+  select cloud INTO inp  from HOBU where rownum=1;
+  insert into hobures
+  select * from
+    table(sdo_pc_pkg.clip_pc
+	  (
+            inp,  -- Input Point Cloud object
+            sdo_geometry(2003, 8307, null,
+              mdsys.sdo_elem_info_array(1, 1003, 3),
+              mdsys.sdo_ordinate_array(630355, 4834609,630395,  4834641)), -- Query 
+	    null, null, null, null));
+end;
+"""
+# -- 630355 4834609 630395 4834641
+#               mdsys.sdo_ordinate_array(630355, 630395, 4834609,4834641)), -- Query 
+# 
+# --              mdsys.sdo_ordinate_array(-74.1, -73.9, 39.99999,40.00001)), -- Query 
+
+run([code])
+
+sql = "select num_points, blk_id from hobures order by blk_id"
+cur.execute(sql)
+for i in cur.fetchall():
+    print i


More information about the Liblas-commits mailing list