[Liblas-commits] hg: 2 new changesets

liblas-commits at liblas.org liblas-commits at liblas.org
Wed Sep 30 11:50:41 EDT 2009


changeset 75dd1030c673 in /home/www/liblas.org/hg
details: http://hg.liblas.org/main/hg?cmd=changeset;node=75dd1030c673
summary: add the example script to grab classes out of a file

changeset 9cde96b45e48 in /home/www/liblas.org/hg
details: http://hg.liblas.org/main/hg?cmd=changeset;node=9cde96b45e48
summary: ignore some python stuff

diffstat:

 .hgignore                       |   5 ++-
 python/examples/grab_classes.py |  62 +++++++++++++++++++++++++++++++
 2 files changed, 66 insertions(+), 1 deletions(-)

diffs (80 lines):

diff -r 42d56ee70cea -r 9cde96b45e48 .hgignore
--- a/.hgignore	Wed Sep 30 00:29:37 2009 +0100
+++ b/.hgignore	Wed Sep 30 10:50:34 2009 -0500
@@ -32,4 +32,7 @@
 Makefile.in
 build.hobu
 test/data/*.dat
-test/data/*.idx
\ No newline at end of file
+test/data/*.idx
+python/build/*
+python/dist/*
+python/libLAS.egg-info/*
\ No newline at end of file
diff -r 42d56ee70cea -r 9cde96b45e48 python/examples/grab_classes.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/python/examples/grab_classes.py	Wed Sep 30 10:50:34 2009 -0500
@@ -0,0 +1,62 @@
+from liblas import file
+from liblas import point
+import sys
+import getopt
+def extract_classifications(infile, outfile, classifications):
+    inp = file.File(infile, mode='r')
+    header = inp.header
+    output = file.File(outfile, mode='w', header=header)
+    cnt = 0
+    for p in inp:
+        cls = p.classification
+        if int(cls) in classifications:
+            output.write(p)
+            cnt += 1 # keep a new count
+    inp.close()
+    output.close()
+    del inp
+    del output
+    # overwrite our header with our point count
+    header.point_records_count = cnt
+    output = file.File(outfile, mode='w+', header=header)
+    output.close()
+    del output
+    print 'wrote %d points' % cnt
+def usage():
+    print "grab_classes.py"
+    print "\n"
+    print "--input input.las - Input file name"
+    print "--output output.las - Output file name"
+    print "--classifications 0,1,2,11 - The classifications to keep "
+    sys.exit(2)
+def main():
+    infile = None
+    outfile = None
+    classifications = None
+    try:
+        opts, args = getopt.getopt(sys.argv[1:],
+                                    "i:o:c:",
+                                    ["input=","output=","classifications="])
+    except getopt.GetoptError, err:
+        print str(err)
+        usage()
+        sys.exit(2)
+    for o, a in opts:
+        print o, a
+        if o in ["-i", "--input"]:
+            infile = a
+        if o in ["-o", "--output"]:
+            outfile = a
+        if o in ["-c", "--classifications"]:
+            try:
+                classifications = [int(i) for i in a.split(',')]
+            except:
+                classifications = int(a)
+    if not infile or not outfile:
+        usage()
+    print 'Input: ', infile
+    print 'Output: ', outfile
+    print 'Classifications to fetch: ', classifications
+    extract_classifications(infile, outfile, classifications)
+if __name__ == "__main__":
+    main()


More information about the Liblas-commits mailing list