[Liblas-commits] hg: 3 new changesets

liblas-commits at liblas.org liblas-commits at liblas.org
Mon Oct 19 13:11:13 EDT 2009


changeset f0f8f5c896d5 in /home/www/liblas.org/hg
details: http://hg.liblas.org/main/hg?cmd=changeset;node=f0f8f5c896d5
summary: mostly working example, need to add options

changeset 64537a3de292 in /home/www/liblas.org/hg
details: http://hg.liblas.org/main/hg?cmd=changeset;node=64537a3de292
summary: provide the ability to set the precision

changeset c6f47214ac29 in /home/www/liblas.org/hg
details: http://hg.liblas.org/main/hg?cmd=changeset;node=c6f47214ac29
summary: oci2las mostly works now, add to default installation

diffstat:

 python/examples/las_summary.py |   56 ++++++++-
 python/scripts/oci2las.py      |  270 +++++++++++++++++++++++++++++++++++++++++++++
 python/setup.py                |    3 +
 3 files changed, 323 insertions(+), 6 deletions(-)

diffs (truncated from 388 to 300 lines):

diff -r d3d4e935cd37 -r c6f47214ac29 python/examples/las_summary.py
--- a/python/examples/las_summary.py	Sat Oct 17 19:17:49 2009 -0500
+++ b/python/examples/las_summary.py	Mon Oct 19 12:07:58 2009 -0500
@@ -2,11 +2,52 @@
 
 from liblas import file as lasfile
 from liblas import header
+from liblas import point
 
 import glob
 
 import os, sys
 
+class PointSummary(object):
+    def __init__(self):
+        self.number_of_point_records = (0,) * 8
+        self.number_of_returns_of_given_pulse = (0,) * 8
+        self.classifications = (0,) * 32
+        self.classification_synthetic = 0
+        self.classification_keypoint = 0
+        self.classification_withheld = 0
+        
+        self.min = point.Point()
+        self.max = point.Point()
+    
+    
+class LAS(object):
+    def __init__(self, filename):
+        self.las = lasfile.File(filename,mode='r')
+        
+        self.s = PointSummary()
+        
+        self.summarize_points()
+        
+    def summarize_points(self):
+        import pdb;pdb.set_trace()
+        i = 0
+        for p in self.las:
+            i = i + 1
+            self.s.min.x = min(self.s.min.x, p.x)
+            self.s.max.x = max(self.s.max.x, p.x)
+            
+            self.s.min.y = min(self.s.min.y, p.y)
+            self.s.max.y = max(self.s.max.y, p.y)
+            
+            self.s.min.z = min(self.s.min.z, p.z)
+            self.s.max.z = max(self.s.max.z, p.z)
+            
+            self.s.min.time = min(self.s.min.time, p.time)
+            self.s.max.time = max(self.s.max.time, p.time)
+                    
+        import pdb;pdb.set_trace()
+
 class Summary(object):
 
     def construct_parser(self):
@@ -56,7 +97,6 @@
                 self.options.output = self.args[1]
             except IndexError:
                 self.options.output = 'output.txt'
-        print self.options, self.args
             
     
     def list_files(self):
@@ -84,20 +124,24 @@
             
             self.files = []
             for d in directories:
-                print d
                 files = get_files(d)
-                print files
                 if files:
                     self.files.extend(files)
 
         else:
-            get_files(self.options.input)
-        
-        print self.files
+            self.files = get_files(self.options.input)
+    
+    def summarize_files(self):
+        files = []
+        for f in self.files:
+            import pdb;pdb.set_trace()
+            files.append(LAS(f))
             
     def process(self):
         self.list_files()
+        self.summarize_files()
         return None
+        
 
 def main():
     import optparse
diff -r d3d4e935cd37 -r c6f47214ac29 python/scripts/oci2las.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/python/scripts/oci2las.py	Mon Oct 19 12:07:58 2009 -0500
@@ -0,0 +1,270 @@
+#!/usr/bin/env python
+
+from liblas import file as lasfile
+from liblas import header
+from liblas import point
+
+import glob
+import struct
+
+import os, sys
+
+
+import cx_Oracle as oci
+
+# big-endian DOUBLE, DOUBLE, DOUBLE, LONG, LONG
+format = '>dddll'
+ptsize = struct.calcsize(format)
+
+
+
+class Translator(object):
+
+    def construct_parser(self):
+        from optparse import OptionParser, OptionGroup
+        usage = "usage: %prog [options] arg"
+        parser = OptionParser(usage)
+        g = OptionGroup(parser, "Base options", "Basic Translation Options")
+        g.add_option("-c", "--connection", dest="connection",
+                          help="OCI connection string", metavar="CONNECTION")
+        g.add_option("-o", "--output", dest='output',
+                          help="LAS file to write", metavar="OUTPUT")
+        g.add_option("-s", "--sql", dest='sql',
+                          help="SQL to select the point cloud ", metavar="SQL")
+        g.add_option("-l", "--column", dest='column',
+                          help="Column name containing the point cloud object ", metavar="COLUMN")
+
+        g.add_option("-p", "--precision", dest='precision',
+                          help="Numeric precision (# of digits) to maintain for the output file ", metavar="PRECISION")
+                          
+        g.add_option("-w", "--overwrite",
+                          action="store_true", dest="overwrite", 
+                          help="overwrite the existing file")
+
+        g.add_option("-m", "--min-offset",
+                          action="store_true", dest="offset", default=False,
+                          help="Use the minimum values as base for offset")
+                          
+        g.add_option("-q", "--quiet",
+                          action="store_false", dest="verbose", default=False,
+                          help="Don't say what we're doing on stdout")
+                          
+        parser.add_option_group(g)
+
+        if self.opts:
+            g = OptionGroup(parser, "Special Options", "Special options")
+            for o in self.opts:
+                g.add_option(o)
+            parser.add_option_group(g)
+            
+        parser.set_defaults(verbose=True, precision = 6)
+
+        self.parser = parser
+        
+    def __init__(self, arguments, options=None):
+        self.connection = None
+        self.output = None
+        self.sql = None
+        
+        self.opts = options
+        self.construct_parser()
+        self.options, self.args = self.parser.parse_args(args=arguments)
+        
+        if self.args:
+            self.options.connection = self.args[0]
+            
+        if not self.options.output:
+            try:
+                self.options.output = self.args[1]
+            except IndexError:
+                self.options.output = 'output.las'
+                
+        if not self.options.sql:
+            try:
+                self.options.sql = self.args[2]
+            except IndexError:
+                raise self.parser.error("No SQL was provided to select the point cloud!")           
+
+        if self.options.output:
+            self.options.output = os.path.abspath(self.options.output)
+            if os.path.isdir(self.options.output):
+                raise self.parser.error("Output '%s' is a directory, not a file " % self.options.output)
+            
+            if os.path.exists(self.options.output):
+                if not self.options.overwrite:
+                    raise self.parser.error("Output file '%s' exists, but you have not selected the --overwrite option" % self.options.output)
+        else:
+            raise self.parser.error("No output was specified")
+
+        try:
+            self.options.precision = int(self.options.precision)
+            if not self.options.precision:
+                raise self.parser.error("Precision cannot be 0")
+        except:
+            raise self.parser.error("Precision was not an number")
+            
+        self.min = point.Point()
+        self.max = point.Point()
+        self.count = 0
+        self.first_point = True
+        self.cloud_column = True
+    def print_options(self):
+        print self.options
+        
+    def connect(self):
+        self.con = oci.Connection(self.options.connection)
+
+    def is_block_table(self, cursor_description):
+        output = True
+        names = [   'OBJ_ID','BLK_ID','BLK_EXTENT','BLK_DOMAIN',
+                    'PCBLK_MIN_RES','PCBLK_MAX_RES','NUM_POINTS',
+                    'NUM_UNSORTED_POINTS','PT_SORT_DIM','POINTS']
+        for name in cursor_description:
+            if name.upper() not in names:
+                return False
+
+            
+    def get_points(self, num_points, block_blob):
+        points = []
+        num, blk = num_points,block_blob
+        data = blk.read()
+        for i in xrange(num):
+            rng = ptsize*i,ptsize*(i+1)
+            d = struct.unpack(format,data[ptsize*i:ptsize*(i+1)])
+            x, y, z, blk_id, pt_id = d
+            p = point.Point()
+            p.x = x; p.y = y; p.z = z
+
+            if self.first_point:
+                self.min.x = p.x
+                self.min.y = p.y
+                self.max.x = p.x
+                self.max.y = p.y
+                self.min.z = p.z
+                self.max.z = p.z
+                self.first_point = False
+
+            # cumulate min/max for the header
+            self.min.x = min(self.min.x, p.x)
+            self.max.x = max(self.max.x, p.x)
+        
+            self.min.y = min(self.min.y, p.y)
+            self.max.y = max(self.max.y, p.y)
+        
+            self.min.z = min(self.min.z, p.z)
+            self.max.z = max(self.max.z, p.z)
+        
+            self.count += 1
+            
+            points.append(p)
+        return points
+    
+    def summarize_files(self):
+        pass
+    
+    def open_output(self):
+        h = header.Header()
+        
+        prec = 10**-(self.options.precision-1)
+        h.scale = [prec, prec, prec]
+        
+        if self.options.offset:
+            h.offset = [self.min.x, self.min.y, self.min.z]
+            if self.options.verbose:
+                print 'using minimum offsets', h.offset
+        output = lasfile.File(self.options.output,mode='w',header=h)
+        return output
+    
+    def write_points(self, points):
+        
+        for p in points:
+            self.output.write(p)
+    
+    def rewrite_header(self):
+        h = self.output.header
+        self.output.close()
+        h.min = [self.min.x, self.min.y, self.min.z]
+        h.max = [self.max.x, self.max.y, self.max.z]
+
+        rc = h.point_return_count
+        rc[0] = self.count
+        h.point_return_count = rc
+        
+        self.output = lasfile.File(self.options.output, mode='w+', header=h)
+        self.output.close()
+    def process(self):
+        self.print_options()
+        self.connect()
+
+        self.cur = self.con.cursor()
+        self.cur.execute(self.options.sql)
+        clouds = []
+


More information about the Liblas-commits mailing list