[Liblas-commits] hg: make an explicit example

liblas-commits at liblas.org liblas-commits at liblas.org
Mon Jun 28 11:54:48 EDT 2010


changeset e56d75d202d0 in /Volumes/Data/www/liblas.org/hg
details: http://hg.liblas.orghg?cmd=changeset;node=e56d75d202d0
summary: make an explicit example

diffstat:

 schemas/LAS-example.dtd      |  105 +++++++++++++++++++++++++++++++++++++++++++
 schemas/las.xml              |    2 +-
 src/detail/reader/header.cpp |   74 ++++++++++++++++++-----------
 src/lasvariablerecord.cpp    |   10 ++-
 4 files changed, 159 insertions(+), 32 deletions(-)

diffs (250 lines):

diff -r 6bdf6773f8de -r e56d75d202d0 schemas/LAS-example.dtd
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/schemas/LAS-example.dtd	Mon Jun 28 10:54:42 2010 -0500
@@ -0,0 +1,105 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" 
+    xmlns:las="http://liblas.org/schemas/LAS/example" 
+    elementFormDefault="qualified" 
+    attributeFormDefault="unqualified" 
+    targetNamespace="http://liblas.org/schemas/LAS/example" version="1.0">
+
+    <xs:simpleType name="sizeType">
+        <xs:annotation><xs:documentation>
+            The storage size type of the dimension.
+        </xs:documentation></xs:annotation>   
+        <xs:restriction base="xs:string">
+            <xs:enumeration value="byte"></xs:enumeration>
+            <xs:enumeration value="bit"></xs:enumeration>
+        </xs:restriction>
+    </xs:simpleType>
+ 
+    <xs:simpleType name="interpretationType" >
+        <xs:annotation><xs:documentation>
+            Common interpretations of the data that may be used.  This 
+            type may be extended under the expectation that clients 
+            know how to consume the data.  In the case of string-like 
+            data, use uint8_t (common byte) as the interpretation 
+            and transform accordingly.  Because nulls (or even 
+            multi-byte strings) might be allowed, there are 
+            no common string interpretations provided by defaut.
+        </xs:documentation></xs:annotation>   
+        <xs:restriction base="xs:string">
+            <xs:enumeration value="int8_t"></xs:enumeration>
+            <xs:enumeration value="uint8_t"></xs:enumeration>
+            <xs:enumeration value="int16_t"></xs:enumeration>
+            <xs:enumeration value="uint16_t"></xs:enumeration>
+            <xs:enumeration value="int32_t"></xs:enumeration>
+            <xs:enumeration value="uint32_t"></xs:enumeration>
+            <xs:enumeration value="int64_t"></xs:enumeration>
+            <xs:enumeration value="uint64_t"></xs:enumeration>
+            <xs:enumeration value="double"></xs:enumeration>
+            <xs:enumeration value="float"></xs:enumeration>
+            <xs:enumeration value="unknown"></xs:enumeration>
+        </xs:restriction>
+    </xs:simpleType>
+
+    <xs:complexType name="rangeType">
+        <xs:attribute name="units" type="las:interpretationType"></xs:attribute>
+        <xs:attribute name="value" type="xs:decimal"></xs:attribute>
+    </xs:complexType>
+    
+    <xs:complexType name="dimensionType">
+        <xs:sequence>
+            <xs:element name="name" type="xs:string"  />
+            <xs:element name="description" type="xs:string" minOccurs="0"/>
+            
+            <xs:element name="position" type="xs:nonNegativeInteger" >
+                <xs:annotation><xs:documentation>
+                    The dimension's position in the block of point data (counting from 0)
+                </xs:documentation></xs:annotation>                
+            </xs:element>
+            
+
+            <xs:element name="active" type="xs:boolean">
+                <xs:annotation><xs:documentation>
+                    A dimension may have be holding its place in bytes but might not have actual
+                    values that mean anything.  This flag can be used to skip the dimension in
+                    that case.
+                </xs:documentation></xs:annotation>
+            </xs:element>
+            
+            <!--Specify the size and units of the dimension's storage-->
+            <xs:element name="size" type="xs:nonNegativeInteger"></xs:element>
+            <xs:element name="units" type="las:sizeType"></xs:element>
+            
+            <xs:element name="interpretation" type="las:interpretationType">
+                <xs:annotation><xs:documentation>
+                    This element describes how the data should be interpreted.  
+                    In the case of conflicting data, for example when then size is 2, the units "byte", 
+                    but the interpretation is "uint32_t", the size determines how much 
+                    precision is available.
+                </xs:documentation></xs:annotation>   
+            </xs:element>
+            
+            <xs:element name="minimum" type="las:rangeType" minOccurs="0">
+                <xs:annotation><xs:documentation>
+                    The minimum value of this dimension.
+                </xs:documentation></xs:annotation>                   
+            </xs:element>
+            <xs:element name="maximum" type="las:rangeType">
+                <xs:annotation><xs:documentation>
+                    The maximum value of this dimension.
+                </xs:documentation></xs:annotation>   
+            </xs:element>
+        </xs:sequence>
+    </xs:complexType>
+    
+  
+    <xs:element name="LASSchema" >
+        <xs:complexType>
+            <xs:sequence >
+                <xs:element name="dimension" type="las:dimesionType" minOccurs="1" maxOccurs="unbounded"></xs:element>
+            </xs:sequence>
+        </xs:complexType>
+    </xs:element>
+        
+              
+
+</xs:schema>
diff -r 6bdf6773f8de -r e56d75d202d0 schemas/las.xml
--- a/schemas/las.xml	Fri Jun 25 12:27:30 2010 -0500
+++ b/schemas/las.xml	Mon Jun 28 10:54:42 2010 -0500
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <ns1:LASSchema xmlns:ns1="http://liblas.org/schemas/LAS/example" 
                 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
-                xsi:schemaLocation="http://liblas.org/schemas/LAS/1.0 file:/Users/hobu/hg/liblas/schemas/LAS.xsd">
+                xsi:schemaLocation="http://liblas.org/schemas/LAS-example.dtd">
     <ns1:dimension>
         <name>X</name>
         <description>
diff -r 6bdf6773f8de -r e56d75d202d0 src/detail/reader/header.cpp
--- a/src/detail/reader/header.cpp	Fri Jun 25 12:27:30 2010 -0500
+++ b/src/detail/reader/header.cpp	Mon Jun 28 10:54:42 2010 -0500
@@ -128,9 +128,11 @@
     // 14. Header Size
     // NOTE: Size of the stanard header block must always be 227 bytes
     read_n(n2, m_ifs, sizeof(n2));
+    m_header.SetHeaderSize(n2);
 
     // 15. Offset to data
     read_n(n4, m_ifs, sizeof(n4));
+    
     if (n4 < m_header.GetHeaderSize())
     {
         std::ostringstream msg; 
@@ -169,6 +171,14 @@
     {
         m_header.SetDataFormatId(liblas::ePointFormat3);
     }
+    else if (n1 == liblas::ePointFormat4)
+    {
+        m_header.SetDataFormatId(liblas::ePointFormat4);
+    }
+    else if (n1 == liblas::ePointFormat5)
+    {
+        m_header.SetDataFormatId(liblas::ePointFormat5);
+    }
     else
     {
         throw std::domain_error("invalid point data format");
@@ -217,6 +227,8 @@
 
     m_header.SetMax(x1, y1, z1);
     m_header.SetMin(x2, y2, z2);
+    
+    
 
     // We're going to check the two bytes off the end of the header to 
     // see if they're pad bytes anyway.  Some softwares, notably older QTModeler, 
@@ -245,35 +257,41 @@
     // If we're eof, we need to reset the state
     if (m_ifs.eof())
         m_ifs.clear();
-        
-    // Seek to the beginning
-    m_ifs.seekg(0, std::ios::beg);
-    std::ios::pos_type beginning = m_ifs.tellg();
-
-    // Seek to the end
-    m_ifs.seekg(0, std::ios::end);
-    std::ios::pos_type end = m_ifs.tellg();
-    std::ios::off_type size = end - beginning;
-     
-    // Figure out how many points we have 
-    std::ios::off_type count = (end - static_cast<std::ios::off_type>(m_header.GetDataOffset())) / 
-                                 static_cast<std::ios::off_type>(m_header.GetDataRecordLength());
     
-    if ( m_header.GetPointRecordsCount() != static_cast<uint32_t>(count)) {
-        std::ostringstream msg; 
-        msg <<  "The number of points in the header that was set "
-                "by the software '" << m_header.GetSoftwareId() <<
-                "' does not match the actual number of points in the file "
-                "as determined by subtracting the data offset (" 
-                <<m_header.GetDataOffset() << ") from the file length (" 
-                << size <<  ") and dividing by the point record length(" 
-                << m_header.GetDataRecordLength() << "). "
-                " Actual number of points: " << count << 
-                " Header-specified number of points: " 
-                << m_header.GetPointRecordsCount() ;
-        throw std::runtime_error(msg.str());
-        
-    }
+    // NOTE: This section is commented out because we now have to believe 
+    // the header's GetPointRecordsCount due to the fact that the LAS 1.3 
+    // specification no longer mandates that the end of the file is the end
+    // of the points.  See http://trac.liblas.org/ticket/147 for more 
+    // details on this issue and why the seek is a problem in the windows 
+    // case.
+    // // Seek to the beginning
+    // m_ifs.seekg(0, std::ios::beg);
+    // std::ios::pos_type beginning = m_ifs.tellg();
+    // 
+    // // Seek to the end
+    // m_ifs.seekg(0, std::ios::end);
+    // std::ios::pos_type end = m_ifs.tellg();
+    // std::ios::off_type size = end - beginning;
+    //  
+    // // Figure out how many points we have 
+    // std::ios::off_type count = (end - static_cast<std::ios::off_type>(m_header.GetDataOffset())) / 
+    //                              static_cast<std::ios::off_type>(m_header.GetDataRecordLength());
+    // 
+    // if ( m_header.GetPointRecordsCount() != static_cast<uint32_t>(count)) {
+    //     std::ostringstream msg; 
+    //     msg <<  "The number of points in the header that was set "
+    //             "by the software '" << m_header.GetSoftwareId() <<
+    //             "' does not match the actual number of points in the file "
+    //             "as determined by subtracting the data offset (" 
+    //             <<m_header.GetDataOffset() << ") from the file length (" 
+    //             << size <<  ") and dividing by the point record length(" 
+    //             << m_header.GetDataRecordLength() << "). "
+    //             " Actual number of points: " << count << 
+    //             " Header-specified number of points: " 
+    //             << m_header.GetPointRecordsCount() ;
+    //     throw std::runtime_error(msg.str());
+    //     
+    // }
     
     // Seek to the data offset so we can start reading points
     m_ifs.seekg(m_header.GetDataOffset());
diff -r 6bdf6773f8de -r e56d75d202d0 src/lasvariablerecord.cpp
--- a/src/lasvariablerecord.cpp	Fri Jun 25 12:27:30 2010 -0500
+++ b/src/lasvariablerecord.cpp	Mon Jun 28 10:54:42 2010 -0500
@@ -132,9 +132,13 @@
 
 void VariableRecord::SetUserId(std::string const& v)
 {
-    if (v.size() > eUIDSize)
-        throw std::invalid_argument("user id too long");
-    
+    if (v.size() > eUIDSize) {
+        std::ostringstream output;
+        output << "User ID for VLR is too long: " << v.size() ;
+        std::string out(output.str());
+        throw std::invalid_argument(out);        
+    }
+
 
     std::fill(m_userId, m_userId + eUIDSize, 0);
     std::strncpy(m_userId, v.c_str(), eUIDSize);


More information about the Liblas-commits mailing list