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

« back to all changes in this revision

Viewing changes to apps/lasinfo.cpp

  • 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
/***************************************************************************
 
2
 *
 
3
 * Project: libLAS -- C/C++ read/write library for LAS LIDAR data
 
4
 * Purpose: LAS information with optional configuration
 
5
 * Author:  Howard Butler, hobu.inc at gmail.com
 
6
 ***************************************************************************
 
7
 * Copyright (c) 2010, Howard Butler, hobu.inc at gmail.com 
 
8
 *
 
9
 * See LICENSE.txt in this source distribution for more information.
 
10
 **************************************************************************/
 
11
 
 
12
#include <liblas/liblas.hpp>
 
13
#include "laskernel.hpp"
 
14
 
 
15
#include <boost/cstdint.hpp>
 
16
#include <boost/foreach.hpp>
 
17
 
 
18
#include <locale>
 
19
 
 
20
 
 
21
using namespace liblas;
 
22
using namespace std;
 
23
 
 
24
 
 
25
liblas::Summary check_points(   liblas::Reader& reader,
 
26
                                std::vector<liblas::FilterPtr>& filters,
 
27
                                std::vector<liblas::TransformPtr>& transforms,
 
28
                                bool verbose)
 
29
{
 
30
 
 
31
    liblas::Summary summary;
 
32
    summary.SetHeader(reader.GetHeader());
 
33
    
 
34
    reader.SetFilters(filters);
 
35
    reader.SetTransforms(transforms);
 
36
 
 
37
 
 
38
 
 
39
    if (verbose)
 
40
    std::cout << "Scanning points:" 
 
41
        << "\n - : "
 
42
        << std::endl;
 
43
 
 
44
    //
 
45
    // Translation of points cloud to features set
 
46
    //
 
47
    boost::uint32_t i = 0;
 
48
    boost::uint32_t const size = reader.GetHeader().GetPointRecordsCount();
 
49
    
 
50
 
 
51
    while (reader.ReadNextPoint())
 
52
    {
 
53
        liblas::Point const& p = reader.GetPoint();
 
54
        summary.AddPoint(p);
 
55
        if (verbose)
 
56
            term_progress(std::cout, (i + 1) / static_cast<double>(size));
 
57
        i++;
 
58
 
 
59
    }
 
60
    if (verbose)
 
61
        std::cout << std::endl;
 
62
    
 
63
    return summary;
 
64
    
 
65
}
 
66
 
 
67
void OutputHelp( std::ostream & oss, po::options_description const& options)
 
68
{
 
69
    oss << "--------------------------------------------------------------------\n";
 
70
    oss << "    lasinfo (" << GetFullVersion() << ")\n";
 
71
    oss << "--------------------------------------------------------------------\n";
 
72
 
 
73
    oss << options;
 
74
 
 
75
    oss <<"\nFor more information, see the full documentation for lasinfo at:\n";
 
76
    
 
77
    oss << " http://liblas.org/utilities/lasinfo.html\n";
 
78
    oss << "----------------------------------------------------------\n";
 
79
 
 
80
}
 
81
 
 
82
void PrintVLRs(std::ostream& os, liblas::Header const& header)
 
83
{
 
84
    if (!header.GetRecordsCount())
 
85
        return ;
 
86
        
 
87
    os << "---------------------------------------------------------" << std::endl;
 
88
    os << "  VLR Summary" << std::endl;
 
89
    os << "---------------------------------------------------------" << std::endl;
 
90
    
 
91
    typedef std::vector<VariableRecord>::size_type size_type;
 
92
    for(size_type i = 0; i < header.GetRecordsCount(); i++) {
 
93
        liblas::VariableRecord const& v = header.GetVLR(i);
 
94
        os << v;
 
95
    }
 
96
    
 
97
}
 
98
 
 
99
 
 
100
int main(int argc, char* argv[])
 
101
{
 
102
 
 
103
    std::string input;
 
104
 
 
105
    bool verbose = false;
 
106
    bool check = true;
 
107
    bool show_vlrs = true;
 
108
    bool show_schema = true;
 
109
    bool output_xml = false;
 
110
    bool output_json = false;
 
111
    bool show_point = false;
 
112
    bool use_locale = false;
 
113
    boost::uint32_t point = 0;
 
114
    
 
115
    std::vector<liblas::FilterPtr> filters;
 
116
    std::vector<liblas::TransformPtr> transforms;
 
117
    
 
118
    liblas::Header header;
 
119
 
 
120
    try {
 
121
 
 
122
        po::options_description file_options("lasinfo options");
 
123
        po::options_description filtering_options = GetFilteringOptions();
 
124
        po::options_description header_options = GetHeaderOptions();
 
125
 
 
126
        po::positional_options_description p;
 
127
        p.add("input", 1);
 
128
        p.add("output", 1);
 
129
 
 
130
        file_options.add_options()
 
131
            ("help,h", "produce help message")
 
132
            ("input,i", po::value< string >(), "input LAS file")
 
133
 
 
134
            ("verbose,v", po::value<bool>(&verbose)->zero_tokens(), "Verbose message output")
 
135
            ("no-vlrs", po::value<bool>(&show_vlrs)->zero_tokens()->implicit_value(false), "Don't show VLRs")
 
136
            ("no-schema", po::value<bool>(&show_schema)->zero_tokens()->implicit_value(false), "Don't show schema")
 
137
            ("no-check", po::value<bool>(&check)->zero_tokens()->implicit_value(false), "Don't scan points")
 
138
            ("xml", po::value<bool>(&output_xml)->zero_tokens()->implicit_value(true), "Output as XML")
 
139
            ("point,p", po::value<boost::uint32_t>(&point), "Display a point with a given id.  --point 44")
 
140
 
 
141
            ("locale", po::value<bool>(&use_locale)->zero_tokens()->implicit_value(true), "Use the environment's locale for output")
 
142
 
 
143
// --xml
 
144
// --json
 
145
// --restructured text output
 
146
        ;
 
147
 
 
148
        po::variables_map vm;
 
149
        po::options_description options;
 
150
        options.add(file_options).add(filtering_options);
 
151
        po::store(po::command_line_parser(argc, argv).
 
152
          options(options).positional(p).run(), vm);
 
153
 
 
154
        po::notify(vm);
 
155
 
 
156
        if (vm.count("help")) 
 
157
        {
 
158
            OutputHelp(std::cout, options);
 
159
            return 1;
 
160
        }
 
161
 
 
162
        if (vm.count("point")) 
 
163
        {
 
164
            show_point = true;
 
165
        }
 
166
 
 
167
        if (vm.count("input")) 
 
168
        {
 
169
            input = vm["input"].as< string >();
 
170
            std::ifstream ifs;
 
171
            if (verbose)
 
172
                std::cout << "Opening " << input << " to fetch Header" << std::endl;
 
173
            if (!liblas::Open(ifs, input.c_str()))
 
174
            {
 
175
                std::cerr << "Cannot open " << input << " for read.  Exiting..." << std::endl;
 
176
                return 1;
 
177
            }
 
178
            liblas::ReaderFactory f;
 
179
            liblas::Reader reader = f.CreateWithStream(ifs);
 
180
            header = reader.GetHeader();
 
181
        } else {
 
182
            std::cerr << "Input LAS file not specified!\n";
 
183
            OutputHelp(std::cout, options);
 
184
            return 1;
 
185
        }
 
186
 
 
187
 
 
188
        filters = GetFilters(vm, verbose);
 
189
 
 
190
        std::ifstream ifs;
 
191
        if (!liblas::Open(ifs, input.c_str()))
 
192
        {
 
193
            std::cerr << "Cannot open " << input << " for read.  Exiting..." << std::endl;
 
194
            return false;
 
195
        }
 
196
    
 
197
 
 
198
        liblas::ReaderFactory f;
 
199
        liblas::Reader reader = f.CreateWithStream(ifs);
 
200
        if (show_point)
 
201
        {
 
202
            try 
 
203
            {
 
204
                reader.ReadPointAt(point);
 
205
                liblas::Point const& p = reader.GetPoint();
 
206
                if (output_xml) {
 
207
                    liblas::property_tree::ptree tree;
 
208
                    tree.add_child("points.point", p.GetPTree());
 
209
                    liblas::property_tree::write_xml(std::cout, tree);
 
210
                    exit(0);
 
211
                } 
 
212
                else 
 
213
                {
 
214
                    if (use_locale)
 
215
                    {
 
216
                        std::locale l("");
 
217
                        std::cout.imbue(l);
 
218
                    }
 
219
                    std::cout <<  p << std::endl;
 
220
                    exit(0);    
 
221
                }
 
222
                
 
223
            } catch (std::out_of_range const& e)
 
224
            {
 
225
                std::cerr << "Unable to read point at index " << point << ": " << e.what() << std::endl;
 
226
                exit(1);
 
227
                
 
228
            }
 
229
 
 
230
        }
 
231
        
 
232
        liblas::Summary summary;
 
233
        if (check)
 
234
            summary = check_points(  reader, 
 
235
                            filters,
 
236
                            transforms,
 
237
                            verbose
 
238
                            );
 
239
 
 
240
 
 
241
        
 
242
        if (output_xml && output_json) {
 
243
            std::cerr << "both JSON and XML output cannot be chosen";
 
244
            return 1;
 
245
        }
 
246
        if (output_xml) {
 
247
            liblas::property_tree::ptree tree;
 
248
            if (check)
 
249
                tree = summary.GetPTree();
 
250
            else 
 
251
            {
 
252
                tree.add_child("summary.header", header.GetPTree());
 
253
            }
 
254
            
 
255
            liblas::property_tree::write_xml(std::cout, tree);
 
256
            return 0;
 
257
        }
 
258
 
 
259
        if (use_locale)
 
260
        {
 
261
            std::locale l("");
 
262
            std::cout.imbue(l);
 
263
        }
 
264
 
 
265
        std::cout << header << std::endl;        
 
266
        if (show_vlrs)
 
267
            PrintVLRs(std::cout, header);
 
268
 
 
269
        if (show_schema)
 
270
            std::cout << header.GetSchema();
 
271
                    
 
272
        if (check) {
 
273
            std::cout << summary << std::endl;
 
274
            
 
275
        }
 
276
    }
 
277
    catch(std::exception& e) {
 
278
        std::cerr << "error: " << e.what() << "\n";
 
279
        return 1;
 
280
    }
 
281
    catch(...) {
 
282
        std::cerr << "Exception of unknown type!\n";
 
283
    }
 
284
    
 
285
    return 0;
 
286
 
 
287
 
 
288
}
 
289
 
 
290
//las2las2 -i lt_srs_rt.las  -o foo.las -c 1,2 -b 2483590,366208,2484000,366612