[Liblas-commits] r1103 - in trunk: include/liblas/capi
include/liblas/detail python/liblas python/tests src src/detail
liblas-commits at liblas.org
liblas-commits at liblas.org
Tue Mar 17 00:05:27 EDT 2009
Author: hobu
Date: Tue Mar 17 00:05:27 2009
New Revision: 1103
URL: http://liblas.org/changeset/1103
Log:
start fixing LASReader/LASWriter SetSRS methods
Modified:
trunk/include/liblas/capi/liblas.h
trunk/include/liblas/detail/reader.hpp
trunk/python/liblas/core.py
trunk/python/liblas/file.py
trunk/python/tests/SRS.txt
trunk/src/detail/reader.cpp
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 Tue Mar 17 00:05:27 2009
@@ -221,6 +221,10 @@
*/
LAS_DLL LASHeaderH LASReader_GetHeader(const LASReaderH hReader);
+
+LAS_DLL LASError LASReader_SetSRS(LASHeaderH hReader, const LASSRSH hSRS);
+
+
/****************************************************************************/
/* Point operations */
/****************************************************************************/
@@ -851,6 +855,9 @@
*/
LAS_DLL void LASWriter_Destroy(LASWriterH hWriter);
+
+LAS_DLL LASError LASWriter_SetSRS(LASWriterH hWriter, const LASSRSH hSRS);
+
/****************************************************************************/
/* GUID Operations */
/****************************************************************************/
Modified: trunk/include/liblas/detail/reader.hpp
==============================================================================
--- trunk/include/liblas/detail/reader.hpp (original)
+++ trunk/include/liblas/detail/reader.hpp Tue Mar 17 00:05:27 2009
@@ -48,6 +48,7 @@
#ifndef HAVE_GDAL
typedef struct OGRCoordinateTransformationHS *OGRCoordinateTransformationH;
+ typedef struct OGRSpatialReferenceHS *OGRSpatialReferenceH;
#endif
// std
@@ -87,8 +88,12 @@
LASSRS m_out_srs;
LASSRS m_in_srs;
+
+ OGRSpatialReferenceH m_in_ref;
+ OGRSpatialReferenceH m_out_ref;
OGRCoordinateTransformationH m_transform;
+
private:
// Blocked copying operations, declared but not defined.
Modified: trunk/python/liblas/core.py
==============================================================================
--- trunk/python/liblas/core.py (original)
+++ trunk/python/liblas/core.py Tue Mar 17 00:05:27 2009
@@ -175,6 +175,10 @@
las.LASReader_GetPointAt.argtypes = [ctypes.c_void_p, ctypes.c_ulong]
las.LASReader_GetPointAt.errcheck = check_void_done
+las.LASReader_SetSRS.argtypes = [ctypes.c_void_p, ctypes.c_void_p]
+las.LASReader_SetSRS.errcheck = check_return
+
+
las.LASPoint_GetX.restype = ctypes.c_double
las.LASPoint_GetX.argtypes = [ctypes.c_void_p]
las.LASPoint_GetX.errcheck = check_value
@@ -452,6 +456,9 @@
las.LASWriter_WriteHeader.argtypes = [ctypes.c_void_p, ctypes.c_void_p]
las.LASWriter_WriteHeader.errcheck = check_return
+las.LASWriter_SetSRS.argtypes = [ctypes.c_void_p, ctypes.c_void_p]
+las.LASWriter_SetSRS.errcheck = check_return
+
las.LASWriter_Destroy.argtypes = [ctypes.c_void_p]
las.LASWriter_Destroy.errcheck = check_void_done
Modified: trunk/python/liblas/file.py
==============================================================================
--- trunk/python/liblas/file.py (original)
+++ trunk/python/liblas/file.py Tue Mar 17 00:05:27 2009
@@ -94,7 +94,13 @@
files.remove(self.filename)
self._header = None
self.handle = None
-
+
+ def set_srs(self, value):
+ if self.mode == 0 :
+ return core.las.LASReader_SetSRS(self.handle, value.handle)
+ else:
+ return core.las.LASWriter_SetSRS(self.handle, value.handle)
+
def get_header(self):
"""Returns the liblas.header.Header for the file"""
return self._header
Modified: trunk/python/tests/SRS.txt
==============================================================================
--- trunk/python/tests/SRS.txt (original)
+++ trunk/python/tests/SRS.txt Tue Mar 17 00:05:27 2009
@@ -13,4 +13,32 @@
... return False
>>> test_srs()
+ True
+
+ >>> from liblas import file
+ >>> f = file.File('../test/data/1.2_3.las',mode='r')
+ >>> s = f.header.srs
+ >>> def test_srs():
+ ... if not liblas.HAVE_GDAL:
+ ... return s.wkt == ''
+ ... if liblas.HAVE_GDAL:
+ ... return s.wkt == """PROJCS["NAD83 / UTM zone 15N",GEOGCS["NAD83",DATUM["North_American_Datum_1983",SPHEROID["GRS 1980",6378137,298.2572221010002,AUTHORITY["EPSG","7019"]],AUTHORITY["EPSG","6269"]],PRIMEM["Greenwich",0],UNIT["degree",0.0174532925199433],AUTHORITY["EPSG","4269"]],PROJECTION["Transverse_Mercator"],PARAMETER["latitude_of_origin",0],PARAMETER["central_meridian",-93],PARAMETER["scale_factor",0.9996],PARAMETER["false_easting",500000],PARAMETER["false_northing",0],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AUTHORITY["EPSG","26915"]]"""
+ ... return False
+
+ >>> test_srs()
+ True
+
+ >>> def test_srs():
+ ... if not liblas.HAVE_GDAL:
+ ... return True
+ ... if liblas.HAVE_GDAL:
+ ... s2 = srs.SRS()
+ ... s2.wkt = """GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.01745329251994328,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4326"]]"""
+ ... f.set_srs(s2)
+ ... p = f.get(0)
+ ... print p.x, p.y
+ ... return s.wkt == """PROJCS["WGS 84 / UTM zone 15N",GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0],UNIT["degree",0.0174532925199433],AUTHORITY["EPSG","4326"]],PROJECTION["Transverse_Mercator"],PARAMETER["latitude_of_origin",0],PARAMETER["central_meridian",-93],PARAMETER["scale_factor",0.9996],PARAMETER["false_easting",500000],PARAMETER["false_northing",0],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AUTHORITY["EPSG","32615"]]"""
+ ... return False
+
+ >>> test_srs()
True
\ No newline at end of file
Modified: trunk/src/detail/reader.cpp
==============================================================================
--- trunk/src/detail/reader.cpp (original)
+++ trunk/src/detail/reader.cpp Tue Mar 17 00:05:27 2009
@@ -67,7 +67,7 @@
namespace liblas { namespace detail {
-Reader::Reader(std::istream& ifs) : m_ifs(ifs), m_offset(0), m_current(0), m_transform(0)
+Reader::Reader(std::istream& ifs) : m_ifs(ifs), m_offset(0), m_current(0), m_transform(0), m_in_ref(0), m_out_ref(0)
{
}
@@ -162,22 +162,27 @@
{
m_out_srs = srs;
#ifdef HAVE_GDAL
- OGRSpatialReferenceH in_ref = OSRNewSpatialReference(0);
- OGRSpatialReferenceH out_ref = OSRNewSpatialReference(0);
+ m_in_ref = OSRNewSpatialReference(0);
+ m_out_ref = OSRNewSpatialReference(0);
const char* in_wkt = m_in_srs.GetWKT().c_str();
- if (OSRImportFromWkt(in_ref, (char**) &in_wkt) != OGRERR_NONE)
+ if (OSRImportFromWkt(m_in_ref, (char**) &in_wkt) != OGRERR_NONE)
{
throw std::runtime_error("Could not import input spatial reference for Reader::");
}
const char* out_wkt = m_out_srs.GetWKT().c_str();
- if (OSRImportFromWkt(out_ref, (char**) &out_wkt) != OGRERR_NONE)
+ printf("outwkt: %s", out_wkt);
+ int result = OSRImportFromWkt(m_out_ref, (char**) &out_wkt);
+ if (result!= OGRERR_NONE)
{
- throw std::runtime_error("Could not import output spatial reference for Reader::");
+ std::ostringstream msg;
+ msg << "Could not import output spatial reference for Reader::" << CPLGetLastErrorMsg() << result;
+ std::string message(msg.str());
+ throw std::runtime_error(message);
}
- m_transform = OCTNewCoordinateTransformation( in_ref, out_ref);
+ m_transform = OCTNewCoordinateTransformation( m_in_ref, m_out_ref);
#endif
}
Modified: trunk/src/las_c_api.cpp
==============================================================================
--- trunk/src/las_c_api.cpp (original)
+++ trunk/src/las_c_api.cpp Tue Mar 17 00:05:27 2009
@@ -323,6 +323,22 @@
return (LASHeaderH) new LASHeader( header );
}
+LAS_DLL LASErrorEnum LASReader_SetSRS(LASHeaderH hReader, const LASSRSH hSRS) {
+
+ VALIDATE_POINTER1(hReader, "LASReader_SetSRS", LE_Failure);
+ VALIDATE_POINTER1(hSRS, "LASReader_SetSRS", LE_Failure);
+
+ try {
+ ((LASReader*) hReader)->SetSRS(*((LASSRS*)hSRS));
+ }
+ catch (std::exception const& e) {
+ LASError_PushError(LE_Failure, e.what(), "LASReader_SetSRS");
+ return LE_Failure;
+ }
+
+ return LE_None;
+}
+
LAS_DLL LASHeaderH LASHeader_Create(void) {
return (LASHeaderH) new LASHeader();
}
@@ -1184,6 +1200,8 @@
}
+
+
LAS_DLL LASWriterH LASWriter_Create(const char* filename, const LASHeaderH hHeader, int mode) {
VALIDATE_POINTER1(hHeader, "LASWriter_Create", NULL);
@@ -1318,6 +1336,22 @@
hWriter=NULL;
}
+LAS_DLL LASErrorEnum LASWriter_SetSRS(LASWriterH hWriter, const LASSRSH hSRS) {
+
+ VALIDATE_POINTER1(hWriter, "LASWriter_SetSRS", LE_Failure);
+ VALIDATE_POINTER1(hSRS, "LASWriter_SetSRS", LE_Failure);
+
+ try {
+ ((LASWriter*) hWriter)->SetSRS(*((LASSRS*)hSRS));
+ }
+ catch (std::exception const& e) {
+ LASError_PushError(LE_Failure, e.what(), "LASWriter_SetSRS");
+ return LE_Failure;
+ }
+
+ return LE_None;
+}
+
LAS_DLL void LASError_Print(const char* message) {
char* errmsg= NULL;
Modified: trunk/src/lassrs.cpp
==============================================================================
--- trunk/src/lassrs.cpp (original)
+++ trunk/src/lassrs.cpp Tue Mar 17 00:05:27 2009
@@ -487,7 +487,6 @@
}
poSRS->exportToWkt(&poWKT);
- printf("wkt: %s\n", poWKT);
delete poSRS;
std::string tmp(poWKT);
@@ -499,7 +498,7 @@
{
throw std::invalid_argument("could not set m_gtiff from Proj4");
}
- GTIFPrint(m_gtiff, 0, 0);
+
ret = GTIFWriteKeys(m_gtiff);
if (!ret)
{
More information about the Liblas-commits
mailing list