Changeset 654:39a2acc6caa2


Ignore:
Timestamp:
05/16/08 22:24:46 (2 years ago)
Author:
Howard Butler <hobu.inc@…>
Branch:
default
Convert:
svn:1766ff46-f334-0410-ab20-d63176f87757/trunk@721
Message:

support getting the proj4 string from the header and use it to report the spatial reference in the apps header summary

Files:
11 edited

Legend:

Unmodified
Added
Removed
  • apps/lascommon.c

    r574 r654  
    338338    char *pszSystemId = NULL; 
    339339    char *pszSoftwareId = NULL; 
     340    char *pszProj4 = NULL; 
    340341 
    341342    pszSignature = LASHeader_GetFileSignature(header); 
     
    343344    pszSystemId = LASHeader_GetSystemId(header); 
    344345    pszSoftwareId = LASHeader_GetSoftwareId(header); 
    345  
     346    pszProj4 = LASHeader_GetProj4(header); 
     347     
    346348    fprintf(stderr, "\n---------------------------------------------------------\n"); 
    347349    fprintf(stderr, "  Header Summary\n"); 
     
    422424                    LASHeader_GetMaxY(header),  
    423425                    LASHeader_GetMaxZ(header)); 
     426     
     427    fprintf(stderr, " Spatial Reference           %s\n", 
     428                    pszProj4); 
    424429 
    425430    free(pszSignature); 
     
    427432    free(pszSystemId); 
    428433    free(pszSoftwareId); 
    429      
     434    free(pszProj4); 
    430435} 
    431436 
  • include/liblas/capi/liblas.h

    r647 r654  
    743743LAS_DLL LASError LASHeader_SetMax(LASHeaderH hHeader, double x, double y, double z); 
    744744 
     745/** Returns the proj.4 string describing the spatial reference of the  
     746 *  header if it is available 
     747 *  @param hHeader LASHeaderH instance 
     748 *  @return the proj.4 string or NULL if none is available.  The caller 
     749 *  owns the string. 
     750*/ 
     751LAS_DLL char* LASHeader_GetProj4(LASHeaderH hHeader); 
     752 
     753/** Sets the proj4 stirng describing the spatial reference of the header. 
     754 *  @param hHeader LASHeaderH instance 
     755 *  @param value the proj4 string to set for the header 
     756 *  @return LASError enum 
     757*/ 
     758LAS_DLL LASError LASHeader_SetProj4(LASHeaderH hHeader, const char* value); 
     759 
    745760/****************************************************************************/ 
    746761/* Writer Operations                                                        */ 
  • include/liblas/detail/reader.hpp

    r641 r654  
    6565    virtual bool ReadPointAt(std::size_t n, PointRecord& record, double& time) = 0; 
    6666    virtual bool ReadVLR(LASHeader& header) = 0; 
     67    virtual bool ReadGeoreference(LASHeader& header) = 0;  
    6768 
    6869    virtual std::istream& GetStream() = 0; 
  • include/liblas/detail/reader10.hpp

    r641 r654  
    5959    std::size_t GetVersion() const; 
    6060    bool ReadHeader(LASHeader& header); 
    61     bool ReadGeoreference(LASHeader const& header); // TODO: Under construction 
    6261    bool ReadNextPoint(PointRecord& record); 
    6362    bool ReadNextPoint(PointRecord& record, double& time); 
    6463    bool ReadPointAt(std::size_t n, PointRecord& record); 
    6564    bool ReadPointAt(std::size_t n, PointRecord& record, double& time); 
     65 
    6666    bool ReadVLR(LASHeader& header); 
     67    bool ReadGeoreference(LASHeader& header);  
    6768 
    6869    std::istream& GetStream(); 
  • include/liblas/detail/reader11.hpp

    r641 r654  
    6363    bool ReadPointAt(std::size_t n, PointRecord& record); 
    6464    bool ReadPointAt(std::size_t n, PointRecord& record, double& time); 
     65 
     66    bool ReadGeoreference(LASHeader& header);  
    6567    bool ReadVLR(LASHeader& header); 
    6668 
  • include/liblas/lasheader.hpp

    r646 r654  
    292292    void SetMin(double x, double y, double z); 
    293293 
     294    /// Adds a variable length record to the header 
    294295    void AddVLR(LASVLR const& v); 
     296     
     297    /// Returns a VLR  
    295298    LASVLR const& GetVLR(uint32_t index) const; 
     299 
     300    /// Removes a VLR from the the header 
    296301    void DeleteVLR(uint32_t index); 
     302     
     303    /// Fetch the Georeference as a proj.4 string 
     304    std::string GetProj4() const; 
     305     
     306    /// Set the Georeference as a proj.4 string 
     307    void SetProj4(std::string const& v); 
    297308     
    298309private: 
     
    349360    PointExtents m_extents; 
    350361    std::vector<LASVLR> m_vlrs; 
     362    std::string m_proj4; 
    351363}; 
    352364 
  • src/detail/reader10.cpp

    r652 r654  
    244244    // TODO: Under construction 
    245245    //       Testing reading of VLRecords with GeoKeys 
    246     ReadGeoreference(header); 
    247246    return true; 
    248247} 
    249 bool ReaderImpl::ReadGeoreference(LASHeader const& header) 
     248bool ReaderImpl::ReadGeoreference(LASHeader& header) 
    250249{ 
    251250#ifndef HAVE_LIBGEOTIFF 
     
    284283    } 
    285284 
    286     GTIF *gtif = GTIFNewSimpleTags( st ); 
    287     GTIFDefn defn; 
    288     if (GTIFGetDefn(gtif, &defn))  
    289     { 
    290          printf( "char PROJ.4 Definition: %s\n", GTIFGetProj4Defn(&defn)); 
    291     } 
    292     GTIFFree( gtif ); 
    293     ST_Destroy( st ); 
    294      
    295     return true; 
     285    if (st->key_count) { 
     286        GTIF *gtif = GTIFNewSimpleTags( st ); 
     287        GTIFDefn defn; 
     288        if (GTIFGetDefn(gtif, &defn))  
     289        { 
     290            header.SetProj4(std::string(GTIFGetProj4Defn(&defn))); 
     291        } 
     292        GTIFFree( gtif ); 
     293        ST_Destroy( st ); 
     294        return true; 
     295    } else { 
     296        return false; 
     297    } 
    296298#endif /* def HAVE_LIBGEOTIFF */ 
    297299} 
  • src/detail/reader11.cpp

    r652 r654  
    4747#include <liblas/lasrecordheader.hpp> 
    4848 
     49 
     50#ifdef HAVE_LIBGEOTIFF 
     51#include <geotiff.h> 
     52#include <geo_simpletags.h> 
     53#include "geo_normalize.h" 
     54#include "geo_simpletags.h" 
     55#include "geovalues.h" 
     56#endif /* HAVE_LIBGEOTIFF */ 
     57 
    4958// std 
    5059#include <fstream> 
     
    328337} 
    329338 
     339bool ReaderImpl::ReadGeoreference(LASHeader& header) 
     340{ 
     341#ifndef HAVE_LIBGEOTIFF 
     342    UNREFERENCED_PARAMETER(header); 
     343    return false; 
     344#else 
     345    // TODO: Under construction 
     346 
     347    std::string const uid("LASF_Projection"); 
     348    ST_TIFF *st = ST_Create(); 
     349 
     350    for (uint16_t i = 0; i < header.GetRecordsCount(); ++i) 
     351    { 
     352        LASVLR record = header.GetVLR(i); 
     353        std::vector<uint8_t> data = record.GetData(); 
     354        if (uid == record.GetUserId(true).c_str() && 34735 == record.GetRecordId()) 
     355        { 
     356            int16_t count = data.size()/sizeof(int16_t); 
     357            ST_SetKey( st, record.GetRecordId(), count, STT_SHORT,  
     358                       &(data[0]) ); 
     359        } 
     360 
     361        if (uid == record.GetUserId(true).c_str() && 34736 == record.GetRecordId()) 
     362        { 
     363            int count = data.size() / sizeof(double); 
     364            ST_SetKey( st, record.GetRecordId(), count, STT_DOUBLE,  
     365                       &(data[0]) ); 
     366        }         
     367 
     368        if (uid == record.GetUserId(true).c_str() && 34737 == record.GetRecordId()) 
     369        { 
     370            uint8_t count = data.size()/sizeof(uint8_t); 
     371            ST_SetKey( st, record.GetRecordId(), count, STT_ASCII,  
     372                       &(data[0]) ); 
     373        } 
     374    } 
     375 
     376    if (st->key_count) { 
     377        GTIF *gtif = GTIFNewSimpleTags( st ); 
     378        GTIFDefn defn; 
     379        if (GTIFGetDefn(gtif, &defn))  
     380        { 
     381            header.SetProj4(std::string(GTIFGetProj4Defn(&defn))); 
     382        } 
     383        GTIFFree( gtif ); 
     384        ST_Destroy( st ); 
     385        return true; 
     386    } else { 
     387        return false; 
     388    } 
     389#endif /* def HAVE_LIBGEOTIFF */ 
     390} 
     391 
    330392}}} // namespace liblas::detail::v11 
  • src/las_c_api.cpp

    r649 r654  
    11411141    return LE_None; 
    11421142} 
     1143 
     1144LAS_DLL char* LASHeader_GetProj4(LASHeaderH hHeader)  
     1145{ 
     1146    VALIDATE_POINTER1(hHeader, "LASHeader_GetProj4", NULL); 
     1147    LASHeader* header = (LASHeader*)hHeader; 
     1148 
     1149    return strdup((header)->GetProj4().c_str()); 
     1150     
     1151} 
     1152LAS_DLL LASErrorEnum LASHeader_SetProj4(LASHeaderH hHeader, const char* value) 
     1153{ 
     1154    VALIDATE_POINTER1(hHeader, "LASHeader_SetProj4", LE_Failure); 
     1155    VALIDATE_POINTER1(value, "LASHeader_SetProj4", LE_Failure); 
     1156 
     1157    try { 
     1158         ((LASHeader*) hHeader)->SetProj4(value); 
     1159    } 
     1160    catch (std::exception const& e) { 
     1161        LASError_PushError(LE_Failure, e.what(), "LASHeader_SetProj4"); 
     1162        return LE_Failure; 
     1163    } 
     1164 
     1165    return LE_None; 
     1166} 
     1167 
     1168 
    11431169LAS_DLL LASWriterH LASWriter_Create(const char* filename, const LASHeaderH hHeader, int mode) { 
    11441170    VALIDATE_POINTER1(hHeader, "LASWriter_Create", NULL);  
  • src/lasheader.cpp

    r653 r654  
    8484    m_scales(other.m_scales), 
    8585    m_offsets(other.m_offsets), 
    86  
    87     m_extents(other.m_extents) 
     86    m_extents(other.m_extents), 
     87    m_proj4(other.m_proj4) 
    8888{ 
    8989    void* p = 0; 
     
    141141        m_offsets = rhs.m_offsets; 
    142142        m_extents = rhs.m_extents; 
     143        m_proj4 = rhs.m_proj4; 
    143144    } 
    144145    return *this; 
     
    172173    if (m_offsets != other.m_offsets) return false; 
    173174    if (m_extents != other.m_extents) return false; 
     175    if (m_proj4 != other.m_proj4) return false; 
    174176     
    175177    return true; 
     
    507509} 
    508510 
    509 LASVLR const& LASHeader::GetVLR(uint32_t index) const { 
     511LASVLR const& LASHeader::GetVLR(uint32_t index) const  
     512{ 
    510513    return m_vlrs[index]; 
    511514} 
    512515 
    513 void LASHeader::DeleteVLR(uint32_t index) { 
     516void LASHeader::DeleteVLR(uint32_t index)  
     517{ 
    514518     
    515519    if (index >= m_vlrs.size()) 
     
    520524     
    521525} 
     526 
     527    /// Fetch the Georeference as a proj.4 string 
     528std::string LASHeader::GetProj4() const  
     529{ 
     530    return m_proj4; 
     531} 
     532     
     533void LASHeader::SetProj4(std::string const& v) 
     534{ 
     535    m_proj4 = v; 
     536} 
    522537void LASHeader::Init() 
    523538{ 
  • src/lasreader.cpp

    r641 r654  
    153153        throw std::runtime_error("public vlr header block reading failure"); 
    154154     
     155    m_pimpl->ReadGeoreference(m_header); 
     156     
    155157} 
    156158 
Note: See TracChangeset for help on using the changeset viewer.