[Liblas-commits] hg: 2 new changesets
liblas-commits at liblas.org
liblas-commits at liblas.org
Thu Oct 1 12:35:58 EDT 2009
changeset 8bffdcfc4197 in /home/www/liblas.org/hg
details: http://hg.liblas.org/main/hg?cmd=changeset;node=8bffdcfc4197
summary: make sure to update the header's dataoffset if we change it when we're writing the header for VLRs #136
changeset 94e8c45b4cb1 in /home/www/liblas.org/hg
details: http://hg.liblas.org/main/hg?cmd=changeset;node=94e8c45b4cb1
summary: fix up return types for check_value_free, srs setting for the reader/writer
diffstat:
python/liblas/core.py | 23 +++++++++++-
python/liblas/file.py | 60 +++++++++++++++++++++++++-----
python/tests/SRS.txt | 1 +
src/detail/writer10.cpp | 10 +++++
src/detail/writer11.cpp | 9 ++++
src/detail/writer12.cpp | 11 +++++-
6 files changed, 102 insertions(+), 12 deletions(-)
diffs (289 lines):
diff -r 7f7771fc2515 -r 94e8c45b4cb1 python/liblas/core.py
--- a/python/liblas/core.py Wed Sep 30 15:32:40 2009 -0500
+++ b/python/liblas/core.py Thu Oct 01 11:33:34 2009 -0500
@@ -92,8 +92,8 @@
msg = 'LASError in "%s": %s' % (func.__name__, las.LASError_GetLastErrorMsg() )
las.LASError_Reset()
raise LASException(msg)
+
retval = ctypes.string_at(result)[:]
- free(result)
return retval
def free_returned_char_p(result, func, cargs):
@@ -179,6 +179,12 @@
las.LASReader_SetSRS.argtypes = [ctypes.c_void_p, ctypes.c_void_p]
las.LASReader_SetSRS.errcheck = check_return
+las.LASReader_SetInputSRS.argtypes = [ctypes.c_void_p, ctypes.c_void_p]
+las.LASReader_SetInputSRS.errcheck = check_return
+
+las.LASReader_SetOutputSRS.argtypes = [ctypes.c_void_p, ctypes.c_void_p]
+las.LASReader_SetOutputSRS.errcheck = check_return
+
las.LASReader_Destroy.argtypes = [ctypes.c_void_p]
las.LASReader_Destroy.errcheck = check_void_done
las.LASReader_Destroy.restype = None
@@ -298,6 +304,7 @@
las.LASHeader_GetFileSignature.argtypes = [ctypes.c_void_p]
las.LASHeader_GetFileSignature.errcheck = check_value_free
+las.LASHeader_GetFileSignature.restype = ctypes.c_char_p
las.LASHeader_GetFileSourceId.restype = ctypes.c_ushort
las.LASHeader_GetFileSourceId.argtypes = [ctypes.c_void_p]
@@ -305,6 +312,7 @@
las.LASHeader_GetProjectId.argtypes = [ctypes.c_void_p]
las.LASHeader_GetProjectId.errcheck = check_value_free
+las.LASHeader_GetProjectId.restype = ctypes.c_char_p
las.LASHeader_GetVersionMajor.restype = ctypes.c_ubyte
las.LASHeader_GetVersionMajor.argtypes = [ctypes.c_void_p]
@@ -322,12 +330,14 @@
las.LASHeader_GetSystemId.argtypes = [ctypes.c_void_p]
las.LASHeader_GetSystemId.errcheck = check_value_free
+las.LASHeader_GetSystemId.restype = ctypes.c_char_p
las.LASHeader_SetSystemId.restype = ctypes.c_int
las.LASHeader_SetSystemId.argtypes = [ctypes.c_void_p, ctypes.c_char_p]
las.LASHeader_SetSystemId.errcheck = check_return
las.LASHeader_GetSoftwareId.argtypes = [ctypes.c_void_p]
las.LASHeader_GetSoftwareId.errcheck = check_value_free
+las.LASHeader_GetSoftwareId.restype = ctypes.c_char_p
las.LASHeader_SetSoftwareId.restype = ctypes.c_int
las.LASHeader_SetSoftwareId.argtypes = [ctypes.c_void_p, ctypes.c_char_p]
las.LASHeader_SetSoftwareId.errcheck = check_return
@@ -473,6 +483,12 @@
las.LASWriter_SetSRS.argtypes = [ctypes.c_void_p, ctypes.c_void_p]
las.LASWriter_SetSRS.errcheck = check_return
+las.LASWriter_SetInputSRS.argtypes = [ctypes.c_void_p, ctypes.c_void_p]
+las.LASWriter_SetInputSRS.errcheck = check_return
+
+las.LASWriter_SetOutputSRS.argtypes = [ctypes.c_void_p, ctypes.c_void_p]
+las.LASWriter_SetOutputSRS.errcheck = check_return
+
las.LASWriter_Destroy.argtypes = [ctypes.c_void_p]
las.LASWriter_Destroy.errcheck = check_void_done
las.LASWriter_Destroy.restype = None
@@ -483,6 +499,7 @@
las.LASGuid_AsString.argtypes = [ctypes.c_void_p]
las.LASGuid_AsString.errcheck = check_value_free
+las.LASGuid_AsString.restype = ctypes.c_char_p
las.LASGuid_Equals.argtypes = [ctypes.c_void_p, ctypes.c_void_p]
las.LASGuid_Equals.restype = ctypes.c_int
@@ -511,12 +528,14 @@
las.LASVLR_GetUserId.argtypes = [ctypes.c_void_p]
las.LASVLR_GetUserId.errcheck = check_value_free
+las.LASVLR_GetUserId.restype = ctypes.c_char_p
las.LASVLR_SetUserId.argtypes = [ctypes.c_void_p, ctypes.c_char_p]
las.LASVLR_SetUserId.errcheck = check_return
las.LASVLR_SetUserId.restype = ctypes.c_int
las.LASVLR_GetDescription.argtypes = [ctypes.c_void_p]
las.LASVLR_GetDescription.errcheck = check_value_free
+las.LASVLR_GetDescription.restype = ctypes.c_char_p
las.LASVLR_SetDescription.argtypes = [ctypes.c_void_p, ctypes.c_char_p]
las.LASVLR_SetDescription.errcheck = check_return
las.LASVLR_SetDescription.restype = ctypes.c_int
@@ -599,12 +618,14 @@
las.LASSRS_GetProj4.argtypes = [ctypes.c_void_p]
las.LASSRS_GetProj4.errcheck = check_value_free
+las.LASSRS_GetProj4.restype = ctypes.c_char_p
las.LASSRS_SetProj4.restype = ctypes.c_int
las.LASSRS_SetProj4.argtypes = [ctypes.c_void_p, ctypes.c_char_p]
las.LASSRS_SetProj4.errcheck = check_return
las.LASSRS_GetWKT.argtypes = [ctypes.c_void_p]
las.LASSRS_GetWKT.errcheck = check_value_free
+las.LASSRS_GetWKT.restype = ctypes.c_char_p
las.LASSRS_SetWKT.restype = ctypes.c_int
las.LASSRS_SetWKT.argtypes = [ctypes.c_void_p, ctypes.c_char_p]
las.LASSRS_SetWKT.errcheck = check_return
diff -r 7f7771fc2515 -r 94e8c45b4cb1 python/liblas/file.py
--- a/python/liblas/file.py Wed Sep 30 15:32:40 2009 -0500
+++ b/python/liblas/file.py Thu Oct 01 11:33:34 2009 -0500
@@ -51,24 +51,26 @@
import sys
class File(object):
- def __init__(self, filename, header=None, mode='r'):
+ def __init__(self, filename, header=None, mode='r', in_srs = None, out_srs = None):
+
self.filename = os.path.abspath(filename)
self._header = header
self.handle = None
self._mode = mode
-
- # print self.filename
- # print sys.stderr.write('%s %s %s'%(files, self.filename, mode))
- # sys.stderr.flush()
+ self.in_srs = in_srs
+ self.out_srs = out_srs
+
#check in the registry if we already have the file open
if mode=='r':
for f in files['write'] + files['append']:
if f == self.filename:
- raise core.LASException("File %s is already open for write. Close the file or delete the reference to it" % filename)
+ raise core.LASException("File %s is already open for write. "
+ "Close the file or delete the reference to it" % filename)
else:
for f in files['read']:
if f == self.filename:
- raise core.LASException("File %s is already open for read. Close the file or delete the reference to it" % filename)
+ raise core.LASException("File %s is already open for read. "
+ "Close the file or delete the reference to it" % filename)
self.open()
def open(self):
@@ -77,12 +79,24 @@
self.mode = 0
self._header = lasheader.Header(handle = core.las.LASReader_GetHeader(self.handle))
files['read'].append(self.filename)
+
+ if self.in_srs:
+ core.las.las.LASReader_SetInputSRS(self.handle, self.in_srs.handle)
+ if self.out_srs:
+ core.las.LASReader_SetOutputSRS(self.handle, self.out_srs.handle)
+
if self._mode == 'w' and '+' not in self._mode:
if not self._header:
self._header = lasheader.Header(handle = core.las.LASHeader_Create())
self.handle = core.las.LASWriter_Create(self.filename, self._header.handle, 1)
self.mode = 1
files['write'].append(self.filename)
+
+ if self.in_srs:
+ core.las.LASWriter_SetInputSRS(self.handle, self.in_srs.handle)
+ if self.out_srs:
+ core.las.LASWriter_SetOutputSRS(self.handle, self.out_srs.handle)
+
if '+' in self._mode and 'r' not in self._mode:
if not self._header:
reader = core.las.LASReader_Create(self.filename)
@@ -91,6 +105,12 @@
self.handle = core.las.LASWriter_Create(self.filename, self._header.handle, 2)
self.mode = 2
files['append'].append(self.filename)
+
+ if self.in_srs:
+ core.las.LASWriter_SetInputSRS(self.handle, self.in_srs.handle)
+ if self.out_srs:
+ core.las.LASWriter_SetOutputSRS(self.handle, self.out_srs.handle)
+
def __del__(self):
if not self.handle or not core: return
self.close()
@@ -110,11 +130,31 @@
self.handle = None
def set_srs(self, value):
+
+ return self.set_output_srs(value)
+
+ def set_output_srs(self, value):
if self.mode == 0 :
- return core.las.LASReader_SetSRS(self.handle, value.handle)
+ return core.las.LASReader_SetOutputSRS(self.handle, value.handle)
else:
- return core.las.LASWriter_SetSRS(self.handle, value.handle)
-
+ return core.las.LASWriter_SetOutputSRS(self.handle, value.handle)
+
+ def get_output_srs(self):
+ return self.out_srs
+
+ output_srs = property(get_output_srs, set_output_srs)
+
+ def set_input_srs(self, value):
+ if self.mode == 0 :
+ return core.las.LASReader_SetInputSRS(self.handle, value.handle)
+ else:
+ return core.las.LASWriter_SetInputSRS(self.handle, value.handle)
+
+ def get_input_srs(self):
+ return self.in_srs
+
+ input_srs = property(get_input_srs, set_input_srs)
+
def get_header(self):
"""Returns the liblas.header.Header for the file"""
return self._header
diff -r 7f7771fc2515 -r 94e8c45b4cb1 python/tests/SRS.txt
--- a/python/tests/SRS.txt Wed Sep 30 15:32:40 2009 -0500
+++ b/python/tests/SRS.txt Thu Oct 01 11:33:34 2009 -0500
@@ -101,6 +101,7 @@
>>> p3 = f3.read(0)
>>> p3.x,p3.y
(-92.999999000000003, 89.999999000000003)
+
>>> import os
>>> os.remove('junk_srs_project.las')
diff -r 7f7771fc2515 -r 94e8c45b4cb1 src/detail/writer10.cpp
--- a/src/detail/writer10.cpp Wed Sep 30 15:32:40 2009 -0500
+++ b/src/detail/writer10.cpp Thu Oct 01 11:33:34 2009 -0500
@@ -227,6 +227,16 @@
// the offset because we were too small to write the VLRs, this will
// end up being header.GetDataOffset() + difference + 2 (see above).
header.SetDataOffset(header.GetDataOffset() + 2);
+
+ // Make sure to rewrite the dataoffset in the header portion now that
+ // we've changed it.
+ std::streamsize const current_pos = m_ofs.tellp();
+ std::streamsize const offset_pos = 96;
+ m_ofs.seekp(offset_pos, std::ios::beg);
+ detail::write_n(m_ofs, header.GetDataOffset() , sizeof(header.GetDataOffset()));
+ m_ofs.seekp(current_pos, std::ios::beg);
+
+
// If we already have points, we're going to put it at the end of the file.
// If we don't have any points, we're going to leave it where it is.
diff -r 7f7771fc2515 -r 94e8c45b4cb1 src/detail/writer11.cpp
--- a/src/detail/writer11.cpp Wed Sep 30 15:32:40 2009 -0500
+++ b/src/detail/writer11.cpp Thu Oct 01 11:33:34 2009 -0500
@@ -216,6 +216,15 @@
if (difference < 0) {
header.SetDataOffset(header.GetDataOffset() + abs(difference) );
WriteVLR(header);
+
+ // Make sure to rewrite the dataoffset in the header portion now that
+ // we've changed it.
+ std::streamsize const current_pos = m_ofs.tellp();
+ std::streamsize const offset_pos = 96;
+ m_ofs.seekp(offset_pos, std::ios::beg);
+ detail::write_n(m_ofs, header.GetDataOffset() , sizeof(header.GetDataOffset()));
+ m_ofs.seekp(current_pos, std::ios::beg);
+
}
// If we already have points, we're going to put it at the end of the file.
diff -r 7f7771fc2515 -r 94e8c45b4cb1 src/detail/writer12.cpp
--- a/src/detail/writer12.cpp Wed Sep 30 15:32:40 2009 -0500
+++ b/src/detail/writer12.cpp Thu Oct 01 11:33:34 2009 -0500
@@ -217,7 +217,16 @@
int32_t difference = WriteVLR(header);
if (difference < 0) {
header.SetDataOffset(header.GetDataOffset() + abs(difference) );
- WriteVLR(header);
+ difference = WriteVLR(header);
+
+ // Make sure to rewrite the dataoffset in the header portion now that
+ // we've changed it.
+ std::streamsize const current_pos = m_ofs.tellp();
+ std::streamsize const offset_pos = 96;
+ m_ofs.seekp(offset_pos, std::ios::beg);
+ detail::write_n(m_ofs, header.GetDataOffset() , sizeof(header.GetDataOffset()));
+ m_ofs.seekp(current_pos, std::ios::beg);
+
}
// If we already have points, we're going to put it at the end of the file.
More information about the Liblas-commits
mailing list