[Liblas-commits] hg: 2 new changesets

liblas-commits at liblas.org liblas-commits at liblas.org
Sun Jun 6 15:17:11 EDT 2010


changeset 4e3f97fd2ad7 in /Volumes/Data/www/liblas.org/hg
details: http://hg.liblas.orghg?cmd=changeset;node=4e3f97fd2ad7
summary: proper geos/proj locations for spatialite

changeset b86e82366a19 in /Volumes/Data/www/liblas.org/hg
details: http://hg.liblas.orghg?cmd=changeset;node=b86e82366a19
summary: add the ability for liblas::Reader to seek #180

diffstat:

 buildout/buildout.cfg                   |   6 +++-
 include/liblas/capi/liblas.h            |   8 +++++++
 include/liblas/detail/reader/reader.hpp |   4 ++-
 include/liblas/lasreader.hpp            |   5 ++++
 include/liblas/liblas.hpp               |   3 +-
 python/liblas/core.py                   |   3 ++
 python/liblas/file.py                   |  14 ++++++++---
 python/tests/File.txt                   |  35 ++++++++++++++++++++++++++++++-
 src/detail/reader/reader.cpp            |  37 ++++++++++++++++++++++++++++----
 src/las_c_api.cpp                       |  22 +++++++++++++++++++
 src/lasreader.cpp                       |  11 +++++++++
 test/unit/lasreader_test.cpp            |  24 +++++++++++++++++++++
 12 files changed, 158 insertions(+), 14 deletions(-)

diffs (truncated from 322 to 300 lines):

diff -r 4b5523931254 -r b86e82366a19 buildout/buildout.cfg
--- a/buildout/buildout.cfg	Wed May 26 22:34:57 2010 -0500
+++ b/buildout/buildout.cfg	Sun Jun 06 14:17:03 2010 -0500
@@ -176,8 +176,10 @@
 recipe = hexagonit.recipe.cmmi
 url = http://www.gaia-gis.it/spatialite/libspatialite-amalgamation-2.3.1.tar.gz
 configure-options = 
-    --with-proj=${libproj:location}
-    --with-geos=${libgeos:location}
+    --with-proj-include=${buildout:directory}/include
+    --with-proj-lib=${buildout:directory}/lib
+    --with-geos-include=${buildout:directory}/include
+    --with-geos-lib=${buildout:directory}/lib
 prefix=${buildout:directory}
 
 [libgdal]
diff -r 4b5523931254 -r b86e82366a19 include/liblas/capi/liblas.h
--- a/include/liblas/capi/liblas.h	Wed May 26 22:34:57 2010 -0500
+++ b/include/liblas/capi/liblas.h	Sun Jun 06 14:17:03 2010 -0500
@@ -242,6 +242,14 @@
 LAS_DLL LASError LASReader_SetInputSRS(LASReaderH hReader, const LASSRSH hSRS);
 LAS_DLL LASError LASReader_SetOutputSRS(LASReaderH hReader, const LASSRSH hSRS);
 
+/** Seeks to the specified point for the next LASReader_GetNextPoint
+ *  operation to start from.  If an error is returned, the seek failed
+ *  for some reason.
+ *  @param hReader the LASReaderH instance
+ *  @return a LASError defaulting to LE_None upon success.  
+*/
+LAS_DLL LASError LASReader_Seek(LASReaderH hReader, uint32_t position);
+
 
 /****************************************************************************/
 /* Point operations                                                         */
diff -r 4b5523931254 -r b86e82366a19 include/liblas/detail/reader/reader.hpp
--- a/include/liblas/detail/reader/reader.hpp	Wed May 26 22:34:57 2010 -0500
+++ b/include/liblas/detail/reader/reader.hpp	Sun Jun 06 14:17:03 2010 -0500
@@ -69,7 +69,8 @@
     liblas::Header const& ReadHeader();
     liblas::Point const& ReadNextPoint(const liblas::Header& header);
     liblas::Point const& ReadPointAt(std::size_t n, const liblas::Header& header);
-
+    void Seek(std::size_t n, const liblas::Header& header);
+    
     std::istream& GetStream() const;
     
     void Reset(liblas::Header const& header);
@@ -116,6 +117,7 @@
     liblas::Point const& ReadNextPoint(const liblas::Header& header);
     liblas::Point const& ReadPointAt(std::size_t n, const liblas::Header& header);
 
+    void Seek(std::size_t n, const liblas::Header& header);
     void Reset(liblas::Header const& header);
 
 protected:
diff -r 4b5523931254 -r b86e82366a19 include/liblas/lasreader.hpp
--- a/include/liblas/lasreader.hpp	Wed May 26 22:34:57 2010 -0500
+++ b/include/liblas/lasreader.hpp	Sun Jun 06 14:17:03 2010 -0500
@@ -114,6 +114,11 @@
     /// @excepion may throw std::exception
     void Reset();
 
+    /// Move to the specified point to start 
+    /// ReadNextPoint operations
+    /// @excepion may throw std::exception
+    bool seek(std::size_t n);
+    
     /// Reproject data as they are written if the Reader's reference is
     /// different than the Header's.
     /// @excepion may throw std::exception
diff -r 4b5523931254 -r b86e82366a19 include/liblas/liblas.hpp
--- a/include/liblas/liblas.hpp	Wed May 26 22:34:57 2010 -0500
+++ b/include/liblas/liblas.hpp	Sun Jun 06 14:17:03 2010 -0500
@@ -155,7 +155,8 @@
     virtual Header const& ReadHeader() = 0;
     virtual Point const& ReadNextPoint(const Header& header) = 0;
     virtual Point const& ReadPointAt(std::size_t n, const Header& header) = 0;
-
+    virtual void Seek(std::size_t n, const Header& header) = 0;
+    
     virtual void Reset(const Header& header) = 0;
     virtual void SetInputSRS(const SpatialReference& srs) = 0;
     virtual void SetOutputSRS(const SpatialReference& srs, const Header& header) = 0;
diff -r 4b5523931254 -r b86e82366a19 python/liblas/core.py
--- a/python/liblas/core.py	Wed May 26 22:34:57 2010 -0500
+++ b/python/liblas/core.py	Sun Jun 06 14:17:03 2010 -0500
@@ -195,6 +195,9 @@
 las.LASReader_GetPointAt.argtypes = [ctypes.c_void_p, ctypes.c_ulong]
 las.LASReader_GetPointAt.errcheck = check_void_done
 
+las.LASReader_Seek.argtypes = [ctypes.c_void_p, ctypes.c_ulong]
+las.LASReader_Seek.errcheck = check_return
+
 las.LASReader_SetSRS.argtypes = [ctypes.c_void_p, ctypes.c_void_p]
 las.LASReader_SetSRS.errcheck = check_return
 
diff -r 4b5523931254 -r b86e82366a19 python/liblas/file.py
--- a/python/liblas/file.py	Wed May 26 22:34:57 2010 -0500
+++ b/python/liblas/file.py	Sun Jun 06 14:17:03 2010 -0500
@@ -15,10 +15,10 @@
  * modification, are permitted provided that the following
  * conditions are met:
  *
- *     * Redistributions of source code must retain the above copyright
- *       notice, this list of conditions and the following disclaimer.
- *     * Redistributions in binary form must reproduce the above copyright
- *       notice, this list of conditions and the following disclaimer in
+*     * Redistributions of source code must retain the above copyright
+*       notice, this list of conditions and the following disclaimer.
+*     * Redistributions in binary form must reproduce the above copyright
+*       notice, this list of conditions and the following disclaimer in
  *       the documentation and/or other materials provided
  *       with the distribution.
  *     * Neither the name of the Martin Isenburg or Iowa Department
@@ -297,6 +297,12 @@
             handle=core.las.LASReader_GetPointAt(self.handle, index),
             copy=True)
 
+    def seek(self, index):
+        """Seeks to the point at the given index.  Subsequent calls \
+	   to :meth:`next` will then start at that point."""
+        if self.mode == 0:
+            return core.las.LASReader_Seek(self.handle, index)
+
     def __iter__(self):
         """Iterator support (read mode only)
 
diff -r 4b5523931254 -r b86e82366a19 python/tests/File.txt
--- a/python/tests/File.txt	Wed May 26 22:34:57 2010 -0500
+++ b/python/tests/File.txt	Sun Jun 06 14:17:03 2010 -0500
@@ -16,10 +16,43 @@
   >>> p.x, p.y, p.z
   (630320.95999999996, 4834500.0, 55.009999999999998)
   
+  >>> f.seek(5)
+  True
+
+  >>> for i in f:
+  ...   p = i
+  ...   break
+
+  >>> p.x, p.y, p.z
+  (630323.57000000007, 4834500.0, 55.020000000000003)
+  
+  >>> f.seek(4)
+  True
+
+  >>> for i in f:
+  ...   p = i
+  ...   break
+
+  >>> p.x, p.y, p.z
+  (630327.58999999997, 4834500.0, 54.730000000000004)
+
+  >>> f.seek(0)
+  True
+
+  >>> for i in f:
+  ...   p = i
+  ...   break
+
+  >>> p.x, p.y, p.z
+  (630262.30000000005, 4834500.0, 51.530000000000001)
+  >>> f.close()
+  >>> f.open()
+
   >>> f2 = file.File('../test/data/TO_core_last_clip.las')
   >>> p2 = f2.read(6)
-  >>> p.x, p.y, p.z
+  >>> p2.x, p2.y, p2.z
   (630320.95999999996, 4834500.0, 55.009999999999998)
+
   >>> f2.close()
   >>> del f2
   
diff -r 4b5523931254 -r b86e82366a19 src/detail/reader/reader.cpp
--- a/src/detail/reader/reader.cpp	Wed May 26 22:34:57 2010 -0500
+++ b/src/detail/reader/reader.cpp	Sun Jun 06 14:17:03 2010 -0500
@@ -219,7 +219,6 @@
 
 liblas::Point const& ReaderImpl::ReadPointAt(std::size_t n, const liblas::Header& header)
 {
-    // FIXME: Throw in this case.
     if (m_size == n) {
         throw std::out_of_range("file has no more points to read, end of file reached");
     } else if (m_size < n) {
@@ -240,6 +239,27 @@
     return point;
 }
 
+void ReaderImpl::Seek(std::size_t n, const liblas::Header& header)
+{
+    if (m_size == n) {
+        throw std::out_of_range("file has no more points to read, end of file reached");
+    } else if (m_size < n) {
+        std::ostringstream output;
+        output << "Seek:: Inputted value: " << n << " is greater than the number of points: " << m_size;
+        std::string out(output.str());
+        throw std::runtime_error(out);
+    } 
+
+    std::streamsize pos = (static_cast<std::streamsize>(n) * header.GetDataRecordLength()) + header.GetDataOffset();    
+
+    m_ifs.clear();
+    m_ifs.seekg(pos, std::ios::beg);
+    // m_point_reader->read();
+    // const liblas::Point& point = m_point_reader->GetPoint();
+    
+    m_current = n+1;
+}
+
 CachedReaderImpl::CachedReaderImpl(std::istream& ifs , liblas::uint64_t size) :
     ReaderImpl(ifs), m_cache_size(size), m_cache_start_position(0), m_cache_read_position(0)
 {
@@ -414,10 +434,17 @@
     ReaderImpl::Reset(header);
 
 }
-// CachedReaderImpl::~CachedReaderImpl()
-// {
-//     ~ReaderImpl();
-// }
+
+void CachedReaderImpl::Seek(std::size_t n, const liblas::Header& header)
+{
+
+   if (n < 1 ) {
+       CachedReaderImpl::Reset(header);
+       // ReadCachedPoint(n,header);
+   }
+
+    ReaderImpl::Seek(n,header);
+}
 
 // ReaderImpl* ReaderFactory::Create(std::istream& ifs)
 // {
diff -r 4b5523931254 -r b86e82366a19 src/las_c_api.cpp
--- a/src/las_c_api.cpp	Wed May 26 22:34:57 2010 -0500
+++ b/src/las_c_api.cpp	Sun Jun 06 14:17:03 2010 -0500
@@ -330,6 +330,28 @@
     return NULL;
 
 }
+
+LAS_DLL LASErrorEnum LASReader_Seek(LASReaderH hReader, liblas::uint32_t position)
+{
+    VALIDATE_LAS_POINTER1(hReader, "LASReader_Seek", LE_None);
+
+    try {
+        liblas::Reader *reader = ((liblas::Reader*) hReader);
+        if (reader->seek((std::size_t) position)) 
+            return LE_None;
+        else 
+            return LE_Failure;
+    } catch (invalid_point_data const& e /*e */) {
+        LASError_PushError(LE_Failure, e.what(), "LASReader_Seek Invalid location");
+    } catch (std::exception const& e)
+    {
+        LASError_PushError(LE_Failure, e.what(), "LASReader_Seek");
+    }
+ 
+    return LE_None;
+
+}
+
 LAS_DLL LASHeaderH LASReader_GetHeader(const LASReaderH hReader)
 {
     VALIDATE_LAS_POINTER1(hReader, "LASReader_GetHeader", NULL);
diff -r 4b5523931254 -r b86e82366a19 src/lasreader.cpp
--- a/src/lasreader.cpp	Wed May 26 22:34:57 2010 -0500
+++ b/src/lasreader.cpp	Sun Jun 06 14:17:03 2010 -0500
@@ -154,6 +154,17 @@
 
 }
 
+bool Reader::seek(std::size_t n)
+{
+    try {
+        m_pimpl->Seek(n, m_header);
+        return true;
+    } catch (std::out_of_range) {
+        m_point = 0;
+        return false;
+    }
+
+}
 Point const& Reader::operator[](std::size_t n)
 {
     if (m_header.GetPointRecordsCount() <= n)
diff -r 4b5523931254 -r b86e82366a19 test/unit/lasreader_test.cpp
--- a/test/unit/lasreader_test.cpp	Wed May 26 22:34:57 2010 -0500
+++ b/test/unit/lasreader_test.cpp	Sun Jun 06 14:17:03 2010 -0500
@@ -158,5 +158,29 @@
 
         ensure_equals(ifs, is);
     }
+
+
+    // Test seek nd GetPoint pair
+    template<>


More information about the Liblas-commits mailing list