1 /******************************************************************************
2 * Copyright (c) 2011, Michael P. Gerlek (mpg@flaxen.com)
3 *
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following
8 * conditions are met:
9 *
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided
15 * with the distribution.
16 * * Neither the name of Hobu, Inc. or Flaxen Geo Consulting nor the
17 * names of its contributors may be used to endorse or promote
18 * products derived from this software without specific prior
19 * written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
28 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
31 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
32 * OF SUCH DAMAGE.
33 ****************************************************************************/
34
35 #include <pdal/Reader.hpp>
36 #include <pdal/util/ProgramArgs.hpp>
37
38 namespace pdal
39 {
40
whereExpr() const41 const expr::ConditionalExpression* Reader::whereExpr() const
42 {
43 return nullptr;
44 }
45
46
mergeMode() const47 Stage::WhereMergeMode Reader::mergeMode() const
48 {
49 return WhereMergeMode::True;
50 }
51
52
l_addArgs(ProgramArgs & args)53 void Reader::l_addArgs(ProgramArgs& args)
54 {
55 Stage::l_addArgs(args);
56 m_filenameArg = &args.add("filename", "Name of file to read", m_filename);
57 m_countArg = &args.add("count", "Maximum number of points read", m_count,
58 (std::numeric_limits<point_count_t>::max)());
59
60 args.add("override_srs", "Spatial reference to apply to data",
61 m_overrideSrs);
62 args.addSynonym("override_srs", "spatialreference");
63
64 args.add("default_srs",
65 "Spatial reference to apply to data if one cannot be inferred",
66 m_defaultSrs);
67 }
68
69
setSpatialReference(MetadataNode & m,const SpatialReference & srs)70 void Reader::setSpatialReference(MetadataNode& m, const SpatialReference& srs)
71 {
72 if (srs.empty() && !m_defaultSrs.empty())
73 {
74 // If an attempt comes in to clear the SRS but we have a default,
75 // revert to the default rather than clearing.
76 Stage::setSpatialReference(m, m_defaultSrs);
77 return;
78 }
79
80 if (getSpatialReference().empty() || m_overrideSrs.empty())
81 {
82 Stage::setSpatialReference(m, srs);
83 }
84 else
85 {
86 log()->get(LogLevel::Debug) <<
87 "Ignoring setSpatialReference attempt: an override was set";
88 }
89 }
90
91
l_initialize(PointTableRef table)92 void Reader::l_initialize(PointTableRef table)
93 {
94 Stage::l_initialize(table);
95
96 if (m_overrideSrs.valid() && m_defaultSrs.valid())
97 throwError("Cannot specify both 'override_srs' and 'default_srs'");
98
99 if (m_overrideSrs.valid())
100 setSpatialReference(m_overrideSrs);
101 else if (m_defaultSrs.valid())
102 setSpatialReference(m_defaultSrs);
103 }
104
l_prepared(PointTableRef table)105 void Reader::l_prepared(PointTableRef table)
106 {
107 Stage::l_prepared(table);
108 }
109
110 } // namespace pdal
111
112