[Liblas-commits] r1054 - in trunk: include/liblas
include/liblas/capi src
liblas-commits at liblas.org
liblas-commits at liblas.org
Thu Feb 19 23:19:21 EST 2009
Author: hobu
Date: Thu Feb 19 23:19:21 2009
New Revision: 1054
URL: http://liblas.org/changeset/1054
Log:
C API for LASSRS
Modified:
trunk/include/liblas/capi/liblas.h
trunk/include/liblas/lassrs.hpp
trunk/src/las_c_api.cpp
trunk/src/lassrs.cpp
Modified: trunk/include/liblas/capi/liblas.h
==============================================================================
--- trunk/include/liblas/capi/liblas.h (original)
+++ trunk/include/liblas/capi/liblas.h Thu Feb 19 23:19:21 2009
@@ -60,6 +60,16 @@
typedef struct LASGuidHS *LASGuidH;
typedef struct LASVLRHS *LASVLRH;
typedef struct LASColorHS *LASColorH;
+typedef struct LASSRSHS *LASSRSH;
+
+
+/* Fake out the compiler if we don't have libgeotiff */
+#ifndef HAVE_LIBGEOTIFF
+ typedef struct GTIFS * GTIF;
+#else
+#include <geotiff.h>
+#endif
+
LAS_C_START
@@ -1056,6 +1066,23 @@
LAS_DLL LASError LASPoint_SetColor(LASPointH hPoint, const LASColorH hColor);
+/****************************************************************************/
+/* SRS Operations */
+/****************************************************************************/
+
+/** Creates a new SRS
+ * @return a new SRS
+*/
+LAS_DLL LASSRSH LASSRS_Create(void);
+
+
+LAS_DLL const GTIF* LASSRS_GetGTIF(LASSRSH hSRS);
+LAS_DLL char* LASSRS_GetWKT(LASSRSH hSRS);
+LAS_DLL LASError LASSRS_SetWKT(LASSRSH hSRS, const char* value);
+LAS_DLL char* LASSRS_GetProj4(LASSRSH hSRS);
+LAS_DLL LASError LASSRS_SetProj4(LASSRSH hSRS, const char* value);
+
+
LAS_C_END
#endif
Modified: trunk/include/liblas/lassrs.hpp
==============================================================================
--- trunk/include/liblas/lassrs.hpp (original)
+++ trunk/include/liblas/lassrs.hpp Thu Feb 19 23:19:21 2009
@@ -146,6 +146,9 @@
/// \param vlrs - A list of VLRs that contains VLRs describing GeoTIFF keys
void SetVLRs(const std::vector<LASVLR>& vlrs);
+ /// Add a VLR representing GeoTIFF keys to the SRS
+ void AddVLR(const LASVLR& vlr);
+
/// Return a copy of the LASVLRs that LASSRS maintains
std::vector<LASVLR> GetVLRs() const;
@@ -156,6 +159,8 @@
ST_TIFF* m_tiff;
std::vector<LASVLR> m_vlrs;
+ bool IsGeoVLR(const LASVLR& vlr) const;
+
protected:
Modified: trunk/src/las_c_api.cpp
==============================================================================
--- trunk/src/las_c_api.cpp (original)
+++ trunk/src/las_c_api.cpp Thu Feb 19 23:19:21 2009
@@ -49,6 +49,7 @@
#include <liblas/exception.hpp>
#include <liblas/lasrecordheader.hpp>
#include <liblas/guid.hpp>
+#include <liblas/lassrs.hpp>
#include <liblas/capi/las_config.h>
#include <liblas/capi/las_version.h>
@@ -59,7 +60,7 @@
typedef struct LASGuidHS *LASGuidH;
typedef struct LASVLRHS *LASVLRH;
typedef struct LASColorHS *LASColorH;
-
+typedef struct LASSRSHS *LASSRSH;
#include <exception>
@@ -72,6 +73,7 @@
#include <typeinfo>
#include <vector>
#include <cstdio>
+
using namespace liblas;
LAS_C_START
@@ -1673,6 +1675,111 @@
return LE_None;
}
+LAS_DLL LASSRSH LASSRS_Create(void) {
+ return (LASSRSH) new LASSRS();
+}
+
+LAS_DLL void LASSRS_Destroy(LASSRSH hSRS){
+ VALIDATE_POINTER0(hSRS, "LASSRS_Destroy");
+ delete (LASSRS*)hSRS;
+ hSRS = NULL;
+}
+
+LAS_DLL const GTIF* LASSRS_GetGTIF(LASSRSH hSRS) {
+ VALIDATE_POINTER1(hSRS, "LASSRS_GetGTIF", 0);
+
+ try {
+ return ((LASSRS*) hSRS)->GetGTIF();
+ }
+ catch (std::exception const& e) {
+ LASError_PushError(LE_Failure, e.what(), "LASSRS_GetGTIF");
+ return 0;
+ }
+}
+
+LAS_DLL char* LASSRS_GetProj4(LASSRSH hSRS)
+{
+ VALIDATE_POINTER1(hSRS, "LASSRS_GetProj4", NULL);
+ LASSRS* srs = (LASSRS*)hSRS;
+
+ return strdup((srs)->GetProj4().c_str());
+
+}
+
+LAS_DLL LASErrorEnum LASSRS_SetProj4(LASSRSH hSRS, const char* value)
+{
+ VALIDATE_POINTER1(hSRS, "LASSRS_SetProj4", LE_Failure);
+ VALIDATE_POINTER1(value, "LASSRS_SetProj4", LE_Failure);
+
+ try {
+ ((LASSRS*) hSRS)->SetProj4(value);
+ }
+ catch (std::exception const& e) {
+ LASError_PushError(LE_Failure, e.what(), "LASSRS_SetProj4");
+ return LE_Failure;
+ }
+
+ return LE_None;
+}
+
+LAS_DLL char* LASSRS_GetWKT(LASSRSH hSRS)
+{
+ VALIDATE_POINTER1(hSRS, "LASSRS_GetWKT", NULL);
+ LASSRS* srs = (LASSRS*)hSRS;
+
+ return strdup((srs)->GetWKT().c_str());
+
+}
+
+LAS_DLL LASErrorEnum LASSRS_SetWKT(LASSRSH hSRS, const char* value)
+{
+ VALIDATE_POINTER1(hSRS, "LASSRS_SetWKT", LE_Failure);
+ VALIDATE_POINTER1(value, "LASSRS_SetWKT", LE_Failure);
+
+ try {
+ ((LASSRS*) hSRS)->SetWKT(value);
+ }
+ catch (std::exception const& e) {
+ LASError_PushError(LE_Failure, e.what(), "LASSRS_SetWKT");
+ return LE_Failure;
+ }
+
+ return LE_None;
+}
+
+LAS_DLL LASErrorEnum LASSRS_AddVLR(LASSRSH hSRS, const LASVLRH hVLR) {
+
+ VALIDATE_POINTER1(hSRS, "LASSRS_AddVLR", LE_Failure);
+ VALIDATE_POINTER1(hVLR, "LASSRS_AddVLR", LE_Failure);
+
+ try {
+ ((LASSRS*) hSRS)->AddVLR(*((LASVLR*)hVLR));
+ }
+ catch (std::exception const& e) {
+ LASError_PushError(LE_Failure, e.what(), "LASSRS_AddVLR");
+ return LE_Failure;
+ }
+
+
+ return LE_None;
+}
+
+LAS_DLL LASErrorEnum LASSRS_ResetVLRs(LASSRSH hSRS) {
+
+ VALIDATE_POINTER1(hSRS, "LASSRS_ResetVLRs", LE_Failure);
+
+ try {
+ ((LASSRS*) hSRS)->ResetVLRs();
+ }
+ catch (std::exception const& e) {
+ LASError_PushError(LE_Failure, e.what(), "LASSRS_ResetVLRs");
+ return LE_Failure;
+ }
+
+
+ return LE_None;
+}
+
LAS_C_END
#ifdef _MSC_VER
Modified: trunk/src/lassrs.cpp
==============================================================================
--- trunk/src/lassrs.cpp (original)
+++ trunk/src/lassrs.cpp Thu Feb 19 23:19:21 2009
@@ -113,21 +113,49 @@
// They must have an id of "LASF_Projection" and a record id that's related.
for (i = vlrs.begin(); i != vlrs.end(); ++i)
{
- //GTIFF_GEOKEYDIRECTORY == 34735
- if (uid == (*i).GetUserId(true).c_str() && 34735 == (*i).GetRecordId()) {
- m_vlrs.push_back(*i);
- }
-
- // GTIFF_DOUBLEPARAMS == 34736
- if (uid == (*i).GetUserId(true).c_str() && 34736 == (*i).GetRecordId()) {
- m_vlrs.push_back(*i);
- }
-
- // GTIFF_ASCIIPARAMS == 34737
- if (uid == (*i).GetUserId(true).c_str() && 34737 == (*i).GetRecordId()) {
+ if (IsGeoVLR(*i)) {
m_vlrs.push_back(*i);
}
+ // //GTIFF_GEOKEYDIRECTORY == 34735
+ // if (uid == (*i).GetUserId(true).c_str() && 34735 == (*i).GetRecordId()) {
+ // m_vlrs.push_back(*i);
+ // }
+ //
+ // // GTIFF_DOUBLEPARAMS == 34736
+ // if (uid == (*i).GetUserId(true).c_str() && 34736 == (*i).GetRecordId()) {
+ // m_vlrs.push_back(*i);
+ // }
+ //
+ // // GTIFF_ASCIIPARAMS == 34737
+ // if (uid == (*i).GetUserId(true).c_str() && 34737 == (*i).GetRecordId()) {
+ // m_vlrs.push_back(*i);
+ // }
+ }
+}
+
+void LASSRS::AddVLR(const LASVLR& vlr)
+{
+ if (IsGeoVLR(vlr)) {
+ m_vlrs.push_back(vlr);
+ }
+}
+bool LASSRS::IsGeoVLR(const LASVLR& vlr) const
+{
+ std::string const uid("LASF_Projection");
+ if (uid == vlr.GetUserId(true).c_str() && 34735 == vlr.GetRecordId()) {
+ return true;
+ }
+
+ // GTIFF_DOUBLEPARAMS == 34736
+ if (uid == vlr.GetUserId(true).c_str() && 34736 == vlr.GetRecordId()) {
+ return true;
+ }
+
+ // GTIFF_ASCIIPARAMS == 34737
+ if (uid == vlr.GetUserId(true).c_str() && 34737 == vlr.GetRecordId()) {
+ return true;
}
+ return false;
}
std::vector<LASVLR> LASSRS::GetVLRs() const
@@ -375,8 +403,7 @@
if( poSRS->importFromWkt((char **) &poWKT) != OGRERR_NONE )
{
delete poSRS;
- throw std::invalid_argument("could not import proj4 into OSRSpatialReference GetProj4");
- return FALSE;
+ return std::string("");
}
char* proj4;
More information about the Liblas-commits
mailing list