~ubuntu-branches/ubuntu/trusty/liblas/trusty-proposed

« back to all changes in this revision

Viewing changes to python/examples/las_summary.py

  • Committer: Package Import Robot
  • Author(s): Francesco Paolo Lovergine
  • Date: 2014-01-05 17:00:29 UTC
  • mfrom: (7.1.2 sid)
  • Revision ID: package-import@ubuntu.com-20140105170029-ddtp0j63x5jvck2u
Tags: 1.7.0+dfsg-2
Fixed missing linking of system boost component.
(closes: #733282)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
 
 
3
from liblas import file as lasfile
 
4
from liblas import header
 
5
from liblas import point
 
6
 
 
7
import glob
 
8
 
 
9
import os, sys
 
10
 
 
11
class PointSummary(object):
 
12
    def __init__(self):
 
13
        self.number_of_point_records = (0,) * 8
 
14
        self.number_of_returns_of_given_pulse = (0,) * 8
 
15
        self.classifications = (0,) * 32
 
16
        self.classification_synthetic = 0
 
17
        self.classification_keypoint = 0
 
18
        self.classification_withheld = 0
 
19
        
 
20
        self.min = point.Point()
 
21
        self.max = point.Point()
 
22
    
 
23
    
 
24
class LAS(object):
 
25
    def __init__(self, filename):
 
26
        self.las = lasfile.File(filename,mode='r')
 
27
        
 
28
        self.s = PointSummary()
 
29
        
 
30
        self.summarize_points()
 
31
        
 
32
    def summarize_points(self):
 
33
        import pdb;pdb.set_trace()
 
34
        i = 0
 
35
        for p in self.las:
 
36
            i = i + 1
 
37
            self.s.min.x = min(self.s.min.x, p.x)
 
38
            self.s.max.x = max(self.s.max.x, p.x)
 
39
            
 
40
            self.s.min.y = min(self.s.min.y, p.y)
 
41
            self.s.max.y = max(self.s.max.y, p.y)
 
42
            
 
43
            self.s.min.z = min(self.s.min.z, p.z)
 
44
            self.s.max.z = max(self.s.max.z, p.z)
 
45
            
 
46
            self.s.min.time = min(self.s.min.time, p.time)
 
47
            self.s.max.time = max(self.s.max.time, p.time)
 
48
                    
 
49
        import pdb;pdb.set_trace()
 
50
 
 
51
class Summary(object):
 
52
 
 
53
    def construct_parser(self):
 
54
        from optparse import OptionParser, OptionGroup
 
55
        usage = "usage: %prog [options] arg"
 
56
        parser = OptionParser(usage)
 
57
        g = OptionGroup(parser, "Base options", "Basic Translation Options")
 
58
        g.add_option("-i", "--input", dest="input",
 
59
                          help="Input directory", metavar="INPUT")
 
60
        g.add_option("-o", "--output", dest='output',
 
61
                          help="ReSTructured text file to write for output", metavar="OUTPUT")
 
62
        g.add_option("-r", "--recursive",
 
63
                          action="store_true", dest="recursive", 
 
64
                          help="recurse down the directory")
 
65
 
 
66
        g.add_option("-u", "--url", dest='url',
 
67
                          help="URL to base for links to files", metavar="URL")
 
68
 
 
69
        g.add_option("-q", "--quiet",
 
70
                          action="store_false", dest="verbose", default=False,
 
71
                          help="Don't say what we're doing on stdout")
 
72
                          
 
73
        parser.add_option_group(g)
 
74
 
 
75
        if self.opts:
 
76
            g = OptionGroup(parser, "Special Options", "Special options")
 
77
            for o in self.opts:
 
78
                g.add_option(o)
 
79
            parser.add_option_group(g)
 
80
            
 
81
        parser.set_defaults(verbose=True, recursive=False)
 
82
 
 
83
        self.parser = parser
 
84
        
 
85
    def __init__(self, arguments, options=None):
 
86
        self.input = None
 
87
        self.output = None
 
88
        
 
89
        self.opts = options
 
90
        self.construct_parser()
 
91
        self.options, self.args = self.parser.parse_args(args=arguments)
 
92
        
 
93
        if self.args:
 
94
            self.options.input = self.args[0]
 
95
        if not self.options.output:
 
96
            try:
 
97
                self.options.output = self.args[1]
 
98
            except IndexError:
 
99
                self.options.output = 'output.txt'
 
100
            
 
101
    
 
102
    def list_files(self):
 
103
        def get_files(path):
 
104
            output = []
 
105
            fn = path+"/*.LAS"
 
106
            output = glob.glob(fn)
 
107
            fn = path+"/*.las"
 
108
            output.extend(glob.glob(fn))
 
109
            return output
 
110
 
 
111
        if self.options.input:
 
112
            self.options.input = os.path.abspath(self.options.input)
 
113
            if not os.path.isdir(self.options.input):
 
114
                raise self.parser.error("Inputted path '%s' was not a directory" % self.options.input)
 
115
        else:
 
116
            raise self.parser.error("No input directory was specified")
 
117
        
 
118
        if self.options.recursive:
 
119
            directories = {}
 
120
            for root, dirs, files in os.walk(self.options.input):
 
121
                directories[root] = root
 
122
                for d in dirs:
 
123
                    directories[os.path.join(root, d)] = os.path.join(root, d)
 
124
            
 
125
            self.files = []
 
126
            for d in directories:
 
127
                files = get_files(d)
 
128
                if files:
 
129
                    self.files.extend(files)
 
130
 
 
131
        else:
 
132
            self.files = get_files(self.options.input)
 
133
    
 
134
    def summarize_files(self):
 
135
        files = []
 
136
        for f in self.files:
 
137
            import pdb;pdb.set_trace()
 
138
            files.append(LAS(f))
 
139
            
 
140
    def process(self):
 
141
        self.list_files()
 
142
        self.summarize_files()
 
143
        return None
 
144
        
 
145
 
 
146
def main():
 
147
    import optparse
 
148
 
 
149
    options = []
 
150
#     o = optparse.make_option("-r", "--remainder", dest="remainder",
 
151
#                          type="choice",default='end', 
 
152
#                           help="""what to do with the remainder -- place it at the beginning, 
 
153
# place it at the end, or evenly distribute it across the segment""",
 
154
#                           choices=['end','begin','uniform'])
 
155
#     options.append(o)
 
156
    
 
157
    d = Summary(sys.argv[1:], options=options)
 
158
    d.process()
 
159
 
 
160
if __name__=='__main__':
 
161
    main()
 
 
b'\\ No newline at end of file'