1
/******************************************************************************
2
* $Id: lasspatialreference.hpp 1091 2009-03-10 20:17:35Z hobu $
4
* Project: libLAS - http://liblas.org - A BSD library for LAS format data.
5
* Purpose: LAS Spatial Reference class
6
* Author: Howard Butler, hobu.inc@gmail.com
8
******************************************************************************
9
* Copyright (c) 2009, Howard Butler
11
* All rights reserved.
13
* Redistribution and use in source and binary forms, with or without
14
* modification, are permitted provided that the following
17
* * Redistributions of source code must retain the above copyright
18
* notice, this list of conditions and the following disclaimer.
19
* * Redistributions in binary form must reproduce the above copyright
20
* notice, this list of conditions and the following disclaimer in
21
* the documentation and/or other materials provided
22
* with the distribution.
23
* * Neither the name of the Martin Isenburg or Iowa Department
24
* of Natural Resources nor the names of its contributors may be
25
* used to endorse or promote products derived from this software
26
* without specific prior written permission.
28
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
31
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
32
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
33
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
34
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
35
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
36
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
37
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
38
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
40
****************************************************************************/
42
#ifndef LIBLAS_LASSPATIALREFERENCE_HPP_INCLUDED
43
#define LIBLAS_LASSPATIALREFERENCE_HPP_INCLUDED
45
#include <liblas/detail/fwd.hpp>
46
#include <liblas/detail/private_utility.hpp>
47
#include <liblas/variablerecord.hpp>
48
#include <liblas/exception.hpp>
49
#include <liblas/capi/las_config.h>
50
#include <liblas/export.hpp>
51
#include <liblas/external/property_tree/ptree.hpp>
54
#include <stdexcept> // std::out_of_range
55
#include <cstdlib> // std::size_t
58
// Fake out the compiler if we don't have libgeotiff includes already
59
#if !defined(__geotiff_h_)
60
typedef struct GTIFS *GTIF;
62
#if !defined(__geo_simpletags_h_)
63
typedef struct ST_TIFFS *ST_TIFF;
68
/// Spatial Reference System container for libLAS
69
class LAS_DLL SpatialReference
84
/// Default constructor.
88
/// If libgeotiff is enabled, deallocates libtiff and libgeotiff objects used internally.
91
/// Constructor creating SpatialReference instance from given Variable-Length Record.
92
SpatialReference(std::vector<VariableRecord> const& vlrs);
95
SpatialReference(SpatialReference const& other);
97
/// Assignment operator.
98
SpatialReference& operator=(SpatialReference const& rhs);
100
bool operator==(const SpatialReference& other) const;
101
bool operator!=(const SpatialReference& other) const { return !(*this == other); }
103
/// Returns a pointer to the internal GTIF*. Only available if
104
/// you have libgeotiff linked in.
105
const GTIF* GetGTIF();
107
void SetGTIF(GTIF* pgtiff, ST_TIFF* ptiff);
109
/// Returns the OGC WKT describing Spatial Reference System.
110
/// If GDAL is linked, it uses GDAL's operations and methods to determine
111
/// the WKT. If GDAL is not linked, no WKT is returned.
112
/// \param mode_flag May be eHorizontalOnly indicating the WKT will not
113
/// include vertical coordinate system info (the default), or
114
/// eCompoundOK indicating the the returned WKT may be a compound
115
/// coordinate system if there is vertical coordinate system info
117
std::string GetWKT(WKTModeFlag mode_flag = eHorizontalOnly) const;
118
std::string GetWKT(WKTModeFlag mode_flag, bool pretty) const;
120
/// Sets the SRS using GDAL's OGC WKT. If GDAL is not linked, this
121
/// operation has no effect.
122
/// \param v - a string containing the WKT string.
123
void SetWKT(std::string const& v);
125
/// Sets the vertical coordinate system using geotiff key values.
126
/// This operation should normally be done after setting the horizontal
127
/// portion of the coordinate system with something like SetWKT(),
128
/// SetProj4(), SetGTIF() or SetFromUserInput()
129
/// \param verticalCSType - An EPSG vertical coordinate system code,
130
/// normally in the range 5600 to 5799, or -1 if one is not available.
131
/// \param citation - a textual description of the vertical coordinate
132
/// system or an empty string if nothing is available.
133
/// \param verticalDatum - the EPSG vertical datum code, often in the
134
/// range 5100 to 5299 - implied by verticalCSType if that is provided, or
135
/// -1 if no value is available.
136
/// \param verticalUnits - the EPSG vertical units code, often 9001 for Metre.
137
void SetVerticalCS(boost::int32_t verticalCSType,
138
std::string const& citation = std::string(0),
139
boost::int32_t verticalDatum = -1,
140
boost::int32_t verticalUnits = 9001);
142
/// Sets the SRS using GDAL's SetFromUserInput function. If GDAL is not linked, this
143
/// operation has no effect.
144
/// \param v - a string containing the definition (filename, proj4, wkt, etc).
145
void SetFromUserInput(std::string const& v);
147
/// Returns the Proj.4 string describing the Spatial Reference System.
148
/// If GDAL is linked, it uses GDAL's operations and methods to determine
149
/// the Proj.4 string -- otherwise, if libgeotiff is linked, it uses
150
/// that. Note that GDAL's operations are much more mature and
151
/// support more coordinate systems and descriptions.
152
std::string GetProj4() const;
154
/// Sets the Proj.4 string describing the Spatial Reference System.
155
/// If GDAL is linked, it uses GDAL's operations and methods to determine
156
/// the Proj.4 string -- otherwise, if libgeotiff is linked, it uses
157
/// that. Note that GDAL's operations are much more mature and
158
/// support more coordinate systems and descriptions.
159
/// \param v - a string containing the Proj.4 string.
160
void SetProj4(std::string const& v);
162
/// Set the LASVLRs for the SpatialReference. SetVLRs will only copy
163
/// VLR records that pertain to the GeoTIFF keys, and extraneous
164
/// VLR records will not be copied.
165
/// \param vlrs - A list of VLRs that contains VLRs describing GeoTIFF keys
166
void SetVLRs(std::vector<VariableRecord> const& vlrs);
168
/// Add a VLR representing GeoTIFF keys to the SRS
169
void AddVLR(VariableRecord const& vlr);
171
/// Return a copy of the LASVLRs that SpatialReference maintains
172
std::vector<VariableRecord> GetVLRs() const;
174
void ClearVLRs( GeoVLRType eType );
176
liblas::property_tree::ptree GetPTree() const;
179
// FIXME: Define as shared_ptr<GTIF> with custom deleter to get rid of bloated mem management, unsafe anyway --mloskot
185
std::vector<VariableRecord> m_vlrs;
186
bool IsGeoVLR(VariableRecord const& vlr) const;
187
std::string GetGTIFFText() const;
189
/// Reset the VLRs of the SpatialReference using the existing GTIF* and ST_TIF*
190
/// Until this method is called,
191
/// the SpatialReference will only contain a SRS description using the VLRs
192
/// that it was first instantiated with. SetWKT and SetProj4 can
193
/// be used to change the GTIF*
197
} // namespace liblas
199
LAS_DLL std::ostream& operator<<(std::ostream& ostr, const liblas::SpatialReference& srs);
202
#if defined(__geotiff_h_)
203
#if defined(GEO_NORMALIZE_H_INCLUDED)
204
char LAS_DLL * GTIFGetOGISDefn(GTIF*, GTIFDefn*);
207
int LAS_DLL GTIFSetFromOGISDefn(GTIF*, const char*);
208
void SetLinearUnitCitation(GTIF* psGTIF, char* pszLinearUOMName);
210
#if defined(_OGR_SRS_API_H_INCLUDED)
211
void SetGeogCSCitation(GTIF* psGTIF, OGRSpatialReference* poSRS, char* angUnitName, int nDatum, short nSpheroid);
212
#endif // defined _OGR_SRS_API_H_INCLUDED
213
#endif // defined __geotiff_h_
217
#endif // LIBLAS_LASSPATIALREFERENCE_HPP_INCLUDED