[Liblas-commits] hg-main-tree: checkpoint for srs work
liblas-commits at liblas.org
liblas-commits at liblas.org
Fri Apr 22 19:01:49 EDT 2011
details: http://hg.libpc.orghg-main-tree/rev/8eea8b1fbf27
changeset: 633:8eea8b1fbf27
user: Michael P. Gerlek <mpg at flaxen.com>
date: Fri Apr 22 15:54:50 2011 -0700
description:
checkpoint for srs work
Subject: hg-main-tree: checkpoint for srs work
details: http://hg.libpc.orghg-main-tree/rev/d13f2673ec17
changeset: 634:d13f2673ec17
user: Michael P. Gerlek <mpg at flaxen.com>
date: Fri Apr 22 16:01:35 2011 -0700
description:
checkpoint for srs work
diffstat:
include/libpc/SpatialReference.hpp | 18 +-
include/libpc/drivers/las/Header.hpp | 6 +
include/libpc/drivers/las/Reader.hpp | 4 +-
include/libpc/drivers/las/VariableLengthRecord.hpp | 9 +-
include/libpc/drivers/las/Writer.hpp | 3 +
src/SpatialReference.cpp | 439 ++++----------------
src/drivers/las/Header.cpp | 11 +
src/drivers/las/LasHeaderWriter.cpp | 64 +-
src/drivers/las/LasHeaderWriter.hpp | 1 +
src/drivers/las/Reader.cpp | 18 +-
src/drivers/las/VariableLengthRecord.cpp | 243 +++++++++++-
src/drivers/las/Writer.cpp | 10 +
test/unit/SpatialReferenceTest.cpp | 330 ++++++++------
13 files changed, 606 insertions(+), 550 deletions(-)
diffs (truncated from 1569 to 300 lines):
diff -r 8865e3cd1f45 -r d13f2673ec17 include/libpc/SpatialReference.hpp
--- a/include/libpc/SpatialReference.hpp Fri Apr 22 13:07:51 2011 -0700
+++ b/include/libpc/SpatialReference.hpp Fri Apr 22 16:01:35 2011 -0700
@@ -44,6 +44,7 @@
#endif
#include <boost/property_tree/ptree.hpp>
+#include <boost/shared_ptr.hpp>
#include <string>
#include <ostream>
@@ -85,9 +86,7 @@
/// Returns a pointer to the internal GTIF*. Only available if
/// you have libgeotiff linked in.
- const GTIF* getGTIF();
-
- void setGTIF(GTIF* pgtiff, ST_TIFF* ptiff);
+ void rebuildGTIFFromVLRs();
/// Returns the OGC WKT describing Spatial Reference System.
/// If GDAL is linked, it uses GDAL's operations and methods to determine
@@ -153,12 +152,19 @@
int geotiff_ST_SetKey(int tag, int count, GeotiffKeyType geotiff_key_type, void *data);
void geotiff_SetTags();
void geotiff_ResetTags();
+ int geotiff_ST_GetKey(int tag, int *count, int *st_key_type, void **data_ptr) const;
private:
- // FIXME: Define as shared_ptr<GTIF> with custom deleter to get rid of bloated mem management, unsafe anyway --mloskot
- GTIF* m_gtiff;
- ST_TIFF* m_tiff;
+ class TiffStuff
+ {
+ public:
+ TiffStuff();
+ ~TiffStuff();
+ GTIF* m_gtiff;
+ ST_TIFF* m_tiff;
+ };
+ boost::shared_ptr<TiffStuff> m_tiffstuff;
std::string m_wkt;
diff -r 8865e3cd1f45 -r d13f2673ec17 include/libpc/drivers/las/Header.hpp
--- a/include/libpc/drivers/las/Header.hpp Fri Apr 22 13:07:51 2011 -0700
+++ b/include/libpc/drivers/las/Header.hpp Fri Apr 22 16:01:35 2011 -0700
@@ -53,6 +53,7 @@
#include <libpc/Schema.hpp>
#include <libpc/Vector.hpp>
#include <libpc/Bounds.hpp>
+#include <libpc/SpatialReference.hpp>
#include <libpc/drivers/las/Support.hpp>
#include <libpc/drivers/las/VariableLengthRecord.hpp>
@@ -338,6 +339,9 @@
const std::vector<VariableLengthRecord>& getVLRs() const;
std::vector<VariableLengthRecord>& getVLRsRef();
+ void setSpatialReference(const SpatialReference&);
+ const SpatialReference& getSpatialReference() const;
+
//void to_rst(std::ostream& os) const;
//void to_xml(std::ostream& os) const;
//void to_json(std::ostream& os) const;
@@ -392,6 +396,8 @@
std::vector<VariableLengthRecord> m_vlrs;
+ SpatialReference m_spatialReference;
+
LasHeader& operator=(const LasHeader&); // nope
LasHeader(const LasHeader&); // nope
};
diff -r 8865e3cd1f45 -r d13f2673ec17 include/libpc/drivers/las/Reader.hpp
--- a/include/libpc/drivers/las/Reader.hpp Fri Apr 22 13:07:51 2011 -0700
+++ b/include/libpc/drivers/las/Reader.hpp Fri Apr 22 16:01:35 2011 -0700
@@ -81,9 +81,9 @@
boost::uint8_t getVersionMajor() const;
boost::uint8_t getVersionMinor() const;
- const SpatialReference& getSpatialReference() const;
+ boost::uint64_t getPointDataOffset() const;
- boost::uint64_t getPointDataOffset() const;
+ const std::vector<VariableLengthRecord>& getVLRs() const;
protected:
const LasHeader& getLasHeader() const { return m_lasHeader; }
diff -r 8865e3cd1f45 -r d13f2673ec17 include/libpc/drivers/las/VariableLengthRecord.hpp
--- a/include/libpc/drivers/las/VariableLengthRecord.hpp Fri Apr 22 13:07:51 2011 -0700
+++ b/include/libpc/drivers/las/VariableLengthRecord.hpp Fri Apr 22 16:01:35 2011 -0700
@@ -66,8 +66,15 @@
boost::uint16_t getRecordId() const { return m_recordId; }
boost::uint8_t* getDescription() const { return (boost::uint8_t*)m_description; }
- static void setSRS(const std::vector<VariableLengthRecord>& vlrs, SpatialReference& srs);
+ static void setSRSFromVLRs(const std::vector<VariableLengthRecord>& vlrs, SpatialReference& srs);
+ static void setVLRsFromSRS(const SpatialReference& srs, std::vector<VariableLengthRecord>& vlrs);
bool VariableLengthRecord::isGeoVLR() const;
+ enum GeoVLRType
+ {
+ eGeoTIFF = 1,
+ eOGRWKT = 2
+ };
+ static void clearVLRs(GeoVLRType eType, std::vector<VariableLengthRecord>& vlrs);
bool compareUserId(const std::string& str) const;
diff -r 8865e3cd1f45 -r d13f2673ec17 include/libpc/drivers/las/Writer.hpp
--- a/include/libpc/drivers/las/Writer.hpp Fri Apr 22 13:07:51 2011 -0700
+++ b/include/libpc/drivers/las/Writer.hpp Fri Apr 22 16:01:35 2011 -0700
@@ -71,6 +71,8 @@
// default false
void setCompressed(bool);
+ void setSpatialReference(const SpatialReference&);
+
protected:
// this is called once before the loop with the writeBuffer calls
virtual void writeBegin();
@@ -89,6 +91,7 @@
SummaryData m_summaryData;
LASzipper* m_zipper;
ZipPoint* m_zipPoint;
+ SpatialReference m_spatialReference;
LasWriter& operator=(const LasWriter&); // not implemented
LasWriter(const LasWriter&); // not implemented
diff -r 8865e3cd1f45 -r d13f2673ec17 src/SpatialReference.cpp
--- a/src/SpatialReference.cpp Fri Apr 22 13:07:51 2011 -0700
+++ b/src/SpatialReference.cpp Fri Apr 22 16:01:35 2011 -0700
@@ -74,39 +74,12 @@
namespace libpc
{
-
-SpatialReference::SpatialReference()
+SpatialReference::TiffStuff::TiffStuff()
: m_gtiff(0)
, m_tiff(0)
{
- assert(0 == m_gtiff);
- assert(0 == m_tiff);
}
-
-
-SpatialReference::SpatialReference(SpatialReference const& other)
- : m_gtiff(0)
- , m_tiff(0)
- , m_wkt(other.m_wkt)
-{
- ////////////////////////////////////////////////////////////SetVLRs(other.GetVLRs());
- getGTIF();
-}
-
-
-SpatialReference& SpatialReference::operator=(SpatialReference const& rhs)
-{
- if (&rhs != this)
- {
- ////////////////////////////////////////////////SetVLRs(rhs.GetVLRs());
- getGTIF();
- m_wkt = rhs.m_wkt;
- }
- return *this;
-}
-
-
-SpatialReference::~SpatialReference()
+SpatialReference::TiffStuff::~TiffStuff()
{
#ifdef LIBPC_SRS_ENABLED
if (m_gtiff != 0)
@@ -122,18 +95,41 @@
#endif
}
-
-void SpatialReference::setGTIF(GTIF* pgtiff, ST_TIFF* ptiff)
+SpatialReference::SpatialReference()
+ : m_tiffstuff(new TiffStuff())
+ , m_wkt("")
{
- m_gtiff = (GTIF*)pgtiff;
- m_tiff = (ST_TIFF*)ptiff;
- ////////////////////////////////////////ResetVLRs();
- m_gtiff = 0;
- m_tiff = 0;
+ return;
}
-const GTIF* SpatialReference::getGTIF()
+SpatialReference::SpatialReference(SpatialReference const& other)
+ : m_tiffstuff(new TiffStuff())
+ , m_wkt(other.m_wkt)
+{
+ rebuildGTIFFromVLRs();
+}
+
+
+SpatialReference& SpatialReference::operator=(SpatialReference const& rhs)
+{
+ if (&rhs != this)
+ {
+ this->m_tiffstuff = rhs.m_tiffstuff;
+ //////////////////////////////////////////////rebuildGTIFFromVLRs();
+ m_wkt = rhs.m_wkt;
+ }
+ return *this;
+}
+
+
+SpatialReference::~SpatialReference()
+{
+ return;
+}
+
+
+void SpatialReference::rebuildGTIFFromVLRs()
{
#ifndef LIBPC_SRS_ENABLED
return 0;
@@ -142,78 +138,41 @@
// If we already have m_gtiff and m_tiff, that is because we have
// already called GetGTIF once before. VLRs ultimately drive how the
// SpatialReference is defined, not the GeoTIFF keys.
- if (m_tiff != 0 )
+ if (m_tiffstuff->m_tiff != 0 )
{
- ST_Destroy(m_tiff);
- m_tiff = 0;
+ ST_Destroy(m_tiffstuff->m_tiff);
+ m_tiffstuff->m_tiff = 0;
}
- if (m_gtiff != 0 )
+ if (m_tiffstuff->m_gtiff != 0 )
{
- GTIFFree(m_gtiff);
- m_gtiff = 0;
+ GTIFFree(m_tiffstuff->m_gtiff);
+ m_tiffstuff->m_gtiff = 0;
}
- m_tiff = ST_Create();
- std::string const uid("LASF_Projection");
-
- ////////////// Nothing is going to happen here if we don't have any VLRs describing
- ////////////// SRS information on the SpatialReference.
- ////////////for (uint16_t i = 0; i < m_vlrs.size(); ++i)
- ////////////{
- //////////// VariableRecord record = m_vlrs[i];
- //////////// std::vector<uint8_t> data = record.GetData();
- //////////// if (uid == record.GetUserId(true).c_str() && 34735 == record.GetRecordId())
- //////////// {
- //////////// int count = data.size()/sizeof(int16_t);
- //////////// short *data_s = (short *) &(data[0]);
+ m_tiffstuff->m_tiff = ST_Create();
+
+ //////// here it used to read in the VLRs ////////
- //////////// // discard invalid "zero" geotags some software emits.
- //////////// while( count > 4
- //////////// && data_s[count-1] == 0
- //////////// && data_s[count-2] == 0
- //////////// && data_s[count-3] == 0
- //////////// && data_s[count-4] == 0 )
- //////////// {
- //////////// count -= 4;
- //////////// data_s[3] -= 1;
- //////////// }
-
- //////////// ST_SetKey(m_tiff, record.GetRecordId(), count, STT_SHORT, data_s);
- //////////// }
-
- //////////// if (uid == record.GetUserId(true).c_str() && 34736 == record.GetRecordId())
- //////////// {
- //////////// int count = data.size() / sizeof(double);
- //////////// ST_SetKey(m_tiff, record.GetRecordId(), count, STT_DOUBLE, &(data[0]));
- //////////// }
-
- //////////// if (uid == record.GetUserId(true).c_str() && 34737 == record.GetRecordId())
- //////////// {
- //////////// int count = data.size()/sizeof(uint8_t);
- //////////// ST_SetKey(m_tiff, record.GetRecordId(), count, STT_ASCII, &(data[0]));
- //////////// }
- ////////////}
-
- m_gtiff = GTIFNewSimpleTags(m_tiff);
- if (!m_gtiff)
+ m_tiffstuff->m_gtiff = GTIFNewSimpleTags(m_tiffstuff->m_tiff);
+ if (!m_tiffstuff->m_gtiff)
throw std::runtime_error("The geotiff keys could not be read from VLR records");
- return m_gtiff;
+ return;
#endif
More information about the Liblas-commits
mailing list