Beispiel #1
0
void LasHeader::setSrsFromGeotiff()
{
#ifdef PDAL_HAVE_LIBGEOTIFF

// These are defined in geo_simpletags.h
// We're not including that file because it includes
// geotiff.h, which includes a ton of other stuff
// that might conflict with the messy libgeotiff/GDAL
// symbol mess

#define STT_SHORT   1
#define STT_DOUBLE  2
#define STT_ASCII   3

    GeotiffSupport geotiff;
    geotiff.resetTags();

    VariableLengthRecord *vlr;

    vlr = findVlr(TRANSFORM_USER_ID, GEOTIFF_DIRECTORY_RECORD_ID);
    // We must have a directory entry.
    if (!vlr)
        return;
    if (!geotiff.setShortKeys(vlr->recordId(), (void *)vlr->data(),
        (int)vlr->dataLen()))
    {
        std::ostringstream oss;

        oss << "Invalid GeoTIFF directory record.  Can't "
            "interpret spatial reference.";
        throw pdal_error(oss.str());
    }

    vlr = findVlr(TRANSFORM_USER_ID, GEOTIFF_DOUBLES_RECORD_ID);
    if (vlr)
        geotiff.setDoubleKeys(vlr->recordId(), (void *)vlr->data(),
            (int)vlr->dataLen());
    vlr = findVlr(TRANSFORM_USER_ID, GEOTIFF_ASCII_RECORD_ID);
    if (vlr)
        geotiff.setAsciiKeys(vlr->recordId(), (void *)vlr->data(),
            (int)vlr->dataLen());

    geotiff.setTags();
    std::string wkt(geotiff.getWkt(false, false));
    if (wkt.size())
        m_srs.setFromUserInput(geotiff.getWkt(false, false));

    m_log->get(LogLevel::Debug5) << "GeoTIFF keys: " << geotiff.getText() <<
        std::endl;
#else
    if (findVlr(TRANSFORM_USER_ID, GEOTIFF_DIRECTORY_RECORD_ID))
        m_log->get(LogLevel::Error) << "Can't decode LAS GeoTiff VLR to "
            "SRS - PDAL not built with GeoTiff." << std::endl;
#endif
}
Beispiel #2
0
/// Set VLRs from the active spatial reference.
/// \param  srs - Active spatial reference.
void LasWriter::setVlrsFromSpatialRef(const SpatialReference& srs)
{
    VlrList vlrs;

#ifdef PDAL_HAVE_LIBGEOTIFF
    GeotiffSupport geotiff;
    geotiff.resetTags();

    std::string wkt = srs.getWKT(SpatialReference::eCompoundOK, false);
    geotiff.setWkt(wkt);

    addGeotiffVlr(geotiff, GEOTIFF_DIRECTORY_RECORD_ID,
        "GeoTiff GeoKeyDirectoryTag");
    addGeotiffVlr(geotiff, GEOTIFF_DOUBLES_RECORD_ID,
        "GeoTiff GeoDoubleParamsTag");
    addGeotiffVlr(geotiff, GEOTIFF_ASCII_RECORD_ID,
        "GeoTiff GeoAsciiParamsTag");
    addWktVlr(srs);
#endif // PDAL_HAVE_LIBGEOTIFF
}
Beispiel #3
0
/// Add a geotiff VLR from the information associated with the record ID.
/// \param  geotiff - Geotiff support structure reference.
/// \param  recordId - Record ID associated with the VLR/Geotiff ref.
/// \param  description - Description to use with the VLR
/// \return  Whether the VLR was added.
bool LasWriter::addGeotiffVlr(GeotiffSupport& geotiff, uint16_t recordId,
    const std::string& description)
{
#ifdef PDAL_HAVE_LIBGEOTIFF
    void *data;
    int count;

    size_t size = geotiff.getKey(recordId, &count, &data);
    if (size == 0)
        return false;

    std::vector<uint8_t> buf(size);
    memcpy(buf.data(), data, size);
    addVlr(TRANSFORM_USER_ID, recordId, description, buf);
    return true;
#else
    return false;
#endif // PDAL_HAVE_LIBGEOTIFF
}