[Liblas-commits] hg: 2 new changesets
liblas-commits at liblas.org
liblas-commits at liblas.org
Tue Oct 6 12:50:12 EDT 2009
changeset 790e3475846d in /home/www/liblas.org/hg
details: http://hg.liblas.org/main/hg?cmd=changeset;node=790e3475846d
summary: use different fill factor
changeset 94416cbd4575 in /home/www/liblas.org/hg
details: http://hg.liblas.org/main/hg?cmd=changeset;node=94416cbd4575
summary: implement the ability to create a LASReader with an existing header to override the file's header
diffstat:
apps/lasindex.cpp | 2 +-
include/liblas/capi/liblas.h | 9 ++++
include/liblas/lasheader.hpp | 2 +-
include/liblas/lasreader.hpp | 7 +++
python/liblas/core.py | 4 ++
python/liblas/file.py | 9 +++-
python/tests/SRS.txt | 48 +++++++++++++++++-------
src/las_c_api.cpp | 60 ++++++++++++++++++++++-------
src/lasreader.cpp | 23 ++++++++++-
9 files changed, 129 insertions(+), 35 deletions(-)
diffs (truncated from 328 to 300 lines):
diff -r 272621999bc0 -r 94416cbd4575 apps/lasindex.cpp
--- a/apps/lasindex.cpp Tue Oct 06 09:04:02 2009 -0500
+++ b/apps/lasindex.cpp Tue Oct 06 11:47:34 2009 -0500
@@ -117,7 +117,7 @@
LASIndex* idx = new LASIndex(input);
idx->SetType(LASIndex::eExternalIndex);
idx->SetLeafCapacity(10000);
- idx->SetFillFactor(0.99);
+ idx->SetFillFactor(0.8);
idx->Initialize(*idxstrm);
diff -r 272621999bc0 -r 94416cbd4575 include/liblas/capi/liblas.h
--- a/include/liblas/capi/liblas.h Tue Oct 06 09:04:02 2009 -0500
+++ b/include/liblas/capi/liblas.h Tue Oct 06 11:47:34 2009 -0500
@@ -182,6 +182,15 @@
*/
LAS_DLL LASReaderH LASReader_Create(const char * filename);
+/** Creates a LASReaderH object that can be used to read LASHeaderH and
+ * LASPointH objects with. The LASReaderH must not be created with a
+ * filename that is opened for read or write by any other API functions.
+ * @return opaque pointer to a LASReaderH instance.
+ * @param filename Filename to open for read
+*/
+LAS_DLL LASReaderH LASReader_CreateWithHeader( const char * filename,
+ LASHeaderH hHeader);
+
/** Reads the next available point on the LASReaderH instance. If no point
* is available to read, NULL is returned. If an error happens during
* the reading of the next available point, an error will be added to the
diff -r 272621999bc0 -r 94416cbd4575 include/liblas/lasheader.hpp
--- a/include/liblas/lasheader.hpp Tue Oct 06 09:04:02 2009 -0500
+++ b/include/liblas/lasheader.hpp Tue Oct 06 11:47:34 2009 -0500
@@ -108,7 +108,7 @@
/// Default constructor.
/// The default constructed header is configured according to the ASPRS
- /// LAS 1.1 Specification, point data format set to 0.
+ /// LAS 1.2 Specification, point data format set to 0.
/// Other fields filled with 0.
LASHeader();
diff -r 272621999bc0 -r 94416cbd4575 include/liblas/lasreader.hpp
--- a/include/liblas/lasreader.hpp Tue Oct 06 09:04:02 2009 -0500
+++ b/include/liblas/lasreader.hpp Tue Oct 06 11:47:34 2009 -0500
@@ -67,6 +67,11 @@
/// @excepion std::runtime_error - on failure state of the input stream.
LASReader(std::istream& ifs);
+ /// User-defined consructor initializes reader with input stream and
+ /// a header to override the values in the file
+ /// @excepion std::runtime_error - on failure state of the input stream.
+ LASReader(std::istream& ifs, LASHeader& header);
+
/// Destructor.
/// @excepion nothrow
~LASReader();
@@ -145,6 +150,8 @@
LASPoint m_point;
std::vector<LASVariableRecord> m_vlrs;
+ bool bCustomHeader;
+
};
} // namespace liblas
diff -r 272621999bc0 -r 94416cbd4575 python/liblas/core.py
--- a/python/liblas/core.py Tue Oct 06 09:04:02 2009 -0500
+++ b/python/liblas/core.py Tue Oct 06 11:47:34 2009 -0500
@@ -168,6 +168,10 @@
las.LASReader_Create.restype = ctypes.c_void_p
las.LASReader_Create.errcheck = check_void
+las.LASReader_CreateWithHeader.argtypes = [ctypes.c_char_p, ctypes.c_void_p]
+las.LASReader_CreateWithHeader.restype = ctypes.c_void_p
+las.LASReader_CreateWithHeader.errcheck = check_void
+
las.LASReader_GetNextPoint.restype=ctypes.c_void_p
las.LASReader_GetNextPoint.argtypes = [ctypes.c_void_p]
las.LASReader_GetNextPoint.errcheck = check_void_done
diff -r 272621999bc0 -r 94416cbd4575 python/liblas/file.py
--- a/python/liblas/file.py Tue Oct 06 09:04:02 2009 -0500
+++ b/python/liblas/file.py Tue Oct 06 11:47:34 2009 -0500
@@ -75,9 +75,14 @@
def open(self):
if self._mode == 'r' or self._mode =='rb':
- self.handle = core.las.LASReader_Create(self.filename)
+
+ if not self._header:
+ self.handle = core.las.LASReader_Create(self.filename)
+ self._header = lasheader.Header(handle = core.las.LASReader_GetHeader(self.handle))
+ else:
+ self.handle = core.las.LASReader_CreateWithHeader(self.filename, self._header.handle)
+
self.mode = 0
- self._header = lasheader.Header(handle = core.las.LASReader_GetHeader(self.handle))
files['read'].append(self.filename)
if self.in_srs:
diff -r 272621999bc0 -r 94416cbd4575 python/tests/SRS.txt
--- a/python/tests/SRS.txt Tue Oct 06 09:04:02 2009 -0500
+++ b/python/tests/SRS.txt Tue Oct 06 11:47:34 2009 -0500
@@ -66,10 +66,9 @@
... if int(p.x) != 47069244: return False
... f.set_srs(s2)
... p = f.read(0)
- ... p.descale(f.header)
... if not s2.vlr_count() == 3: return False
... if not s2.GetVLR(0).recordlength == 64: return False
- ... return int(round(p.x)) == -93 and int(round(p.y)) == 90
+ ... return int(round(p.x)) == -93 and int(round(p.y)) == 42
... return False
>>> test_srs_2()
@@ -77,9 +76,9 @@
>>> del f
- >>> f = file.File('../test/data/1.2_3.las',mode='r')
- >>> f.header.data_offset
- 438L
+
+# -93.3515625902 41.5771483954
+
>>> utm_wkt = """PROJCS["NAD83 / UTM zone 15N",GEOGCS["NAD83",DATUM["North_American_Datum_1983",SPHEROID["GRS 1980",6378137,298.2572221010002,AUTHORITY["EPSG","7019"]],AUTHORITY["EPSG","6269"]],PRIMEM["Greenwich",0],UNIT["degree",0.0174532925199433],AUTHORITY["EPSG","4269"]],PROJECTION["Transverse_Mercator"],PARAMETER["latitude_of_origin",0],PARAMETER["central_meridian",-93],PARAMETER["scale_factor",0.9996],PARAMETER["false_easting",500000],PARAMETER["false_northing",0],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AUTHORITY["EPSG","26915"]]"""
>>> dd_wkt = """GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.01745329251994328,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4326"]]"""
@@ -87,6 +86,28 @@
>>> s_dd.wkt = dd_wkt
>>> s_utm = srs.SRS()
>>> s_utm.wkt = utm_wkt
+
+ >>> f = file.File('../test/data/1.2_3.las',mode='r')
+ >>> dd_header = f.header
+ >>> utm_header = f.header
+ >>> del f
+
+ >>> utm_header.offset
+ [0.0, 0.0, 0.0]
+ >>> utm_header.offset = [offset+1.0/0.000001 for offset in utm_header.offset]
+ >>> utm_header.offset
+ [1000000.0, 1000000.0, 1000000.0]
+ >>> utm_header.scale = [0.000001,0.000001,0.000001]
+ >>> utm_header.srs = s_utm
+
+ >>> dd_header.scale = [0.000001,0.000001,0.000001]
+ >>> dd_header.srs = s_dd
+
+ >>> f = file.File('../test/data/1.2_3.las',mode='r', header = utm_header)
+ >>> f.header.data_offset
+ 438L
+ >>> f.header.scale
+ [9.9999999999999995e-07, 9.9999999999999995e-07, 9.9999999999999995e-07]
>>> p = f.read(0)
>>> origx, origy = p.x, p.y
>>> origx, origy
@@ -94,12 +115,11 @@
>>> f.set_srs(s_dd)
True
>>> p = f.read(0)
- >>> p.descale(f.header)
>>> p.x, p.y
- (-92.999999999999972, 89.999999999999972)
- >>> dd_header = f.header
- >>> dd_header.scale = [0.000001,0.000001,0.000001]
- >>> dd_header.srs = s_dd
+ (-93.350000000000009, 41.57)
+
+
+
>>> f_project = file.File('junk_srs_project.las',mode='w',header=dd_header)
>>> dd_header.srs.proj4
'+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs '
@@ -112,11 +132,11 @@
>>> s_utm = srs.SRS()
>>> s_utm.wkt = utm_wkt
>>> p3 = f3.read(1)
- >>> p3.x, p3.y
- (-92.999999000000003, 89.999999000000003)
+ >>> int(round(p3.x)), int(round(p3.y))
+ (-93, 42)
>>> p3 = f3.read(0)
- >>> p3.x,p3.y
- (-92.999999000000003, 89.999999000000003)
+ >>> int(round(p3.x)), int(round(p3.y))
+ (-93, 42)
>>> import os
>>> os.remove('junk_srs_project.las')
diff -r 272621999bc0 -r 94416cbd4575 src/las_c_api.cpp
--- a/src/las_c_api.cpp Tue Oct 06 09:04:02 2009 -0500
+++ b/src/las_c_api.cpp Tue Oct 06 11:47:34 2009 -0500
@@ -181,28 +181,36 @@
return static_cast<int>(errors.size());
}
+std::istream* OpenInput(std::string filename)
+{
+ std::ios::openmode const mode = std::ios::in | std::ios::binary;
+ std::istream* istrm = 0;
+ if (compare_no_case(filename.c_str(),"STDIN",5) == 0)
+ {
+ istrm = &std::cin;
+ }
+ else
+ {
+ istrm = new std::ifstream(filename.c_str(), mode);
+ }
+
+ if (!istrm->good())
+ {
+ delete istrm;
+ throw std::runtime_error("Reading stream was not able to be created");
+ exit(1);
+ }
+ return istrm;
+}
+
LAS_DLL LASReaderH LASReader_Create(const char* filename)
{
VALIDATE_LAS_POINTER1(filename, "LASReader_Create", NULL);
try {
- std::ios::openmode const mode = std::ios::in | std::ios::binary;
- std::istream* istrm;
- if (compare_no_case(filename,"STDIN",5) == 0)
- {
- istrm = &std::cin;
- }
- else
- {
- istrm = new std::ifstream(filename, mode);
- }
- if (!istrm->good())
- {
- delete istrm;
- throw std::runtime_error("Reading stream was not able to be created");
- }
+ std::istream* istrm = OpenInput(std::string(filename));
return (LASReaderH) new LASReader(*istrm);
@@ -212,7 +220,29 @@
return NULL;
}
+}
+
+LAS_DLL LASReaderH LASReader_CreateWithHeader( const char* filename,
+ LASHeaderH hHeader)
+
+{
+ VALIDATE_LAS_POINTER1(filename, "LASReader_CreateWithHeader", NULL);
+ VALIDATE_LAS_POINTER1(hHeader, "LASReader_CreateWithHeader", NULL);
+
+ try {
+
+ std::istream* istrm = OpenInput(std::string(filename));
+
+ LASHeader* header = ((LASHeader*) hHeader);
+ return (LASReaderH) new LASReader(*istrm, *header);
+
+ } catch (std::exception const& e)
+ {
+ LASError_PushError(LE_Failure, e.what(), "LASReader_Create");
+ return NULL;
+ }
+
}
LAS_DLL void LASReader_Destroy(LASReaderH hReader)
diff -r 272621999bc0 -r 94416cbd4575 src/lasreader.cpp
--- a/src/lasreader.cpp Tue Oct 06 09:04:02 2009 -0500
+++ b/src/lasreader.cpp Tue Oct 06 11:47:34 2009 -0500
@@ -55,12 +55,21 @@
{
LASReader::LASReader(std::istream& ifs) :
- m_pimpl(detail::ReaderFactory::Create(ifs))
+ m_pimpl(detail::ReaderFactory::Create(ifs)),
+ bCustomHeader(false)
{
Init();
}
+LASReader::LASReader(std::istream& ifs, LASHeader& header) :
+ m_pimpl(detail::ReaderFactory::Create(ifs)),
+ bCustomHeader(false)
+{
+ m_header = header;
+ bCustomHeader = true;
+ Init();
+}
LASReader::~LASReader()
More information about the Liblas-commits
mailing list