Skip to content

Commit

Permalink
Merge pull request #34 from jdreaver/master
Browse files Browse the repository at this point in the history
Added Python 3 support
  • Loading branch information
hobu committed May 1, 2014
2 parents e36b4e9 + a4f2e39 commit 37c04ca
Show file tree
Hide file tree
Showing 17 changed files with 327 additions and 339 deletions.
16 changes: 8 additions & 8 deletions python/liblas/__init__.py
@@ -1,6 +1,6 @@
#from .core import *
from core import get_version
from core import las
from .core import get_version
from .core import las
version = get_version()
HAVE_GDAL = bool(las.LAS_IsGDALEnabled())
HAVE_LIBGEOTIFF = bool(las.LAS_IsLibGeoTIFFEnabled())
Expand All @@ -9,9 +9,9 @@

version = sys.version_info[:3]

import file
import point
import header
import vlr
import color
import srs
from . import file
from . import point
from . import header
from . import vlr
from . import color
from . import srs
2 changes: 1 addition & 1 deletion python/liblas/color.py
Expand Up @@ -40,7 +40,7 @@
* OF SUCH DAMAGE.
****************************************************************************/
"""
import core
from . import core
import ctypes


Expand Down
17 changes: 10 additions & 7 deletions python/liblas/file.py
Expand Up @@ -41,9 +41,9 @@
****************************************************************************/
"""

import core
import header as lasheader
import point
from . import core
from . import header as lasheader
from . import point

import os
import types
Expand Down Expand Up @@ -93,16 +93,19 @@ def __init__(self, filename,
... f2.write(p)
>>> f2.close()
"""
self.filename = os.path.abspath(filename)
if sys.version_info.major == 3:
self.filename = bytes(os.path.abspath(filename), "ascii")
else:
self.filename = filename
self._header = None
self.ownheader = True

# import pdb;pdb.set_trace()
if header != None:

self.ownheader = False
self._header = header.handle

self.handle = None
self._mode = mode.lower()
self.in_srs = in_srs
Expand All @@ -119,7 +122,7 @@ def __init__(self, filename,
else:
# we're in some kind of write mode, and if we already have the
# file open, complain to the user.
for f in files['read'].keys() + files['append'] + files['write']:
for f in list(files['read'].keys()) + files['append'] + files['write']:
if f == self.filename:
raise core.LASException("File %s is already open. "
"Close the file or delete the "
Expand Down
4 changes: 2 additions & 2 deletions python/liblas/guid.py
Expand Up @@ -41,7 +41,7 @@
****************************************************************************/
"""

import core
from . import core


class GUID(object):
Expand Down Expand Up @@ -89,7 +89,7 @@ def __del__(self):

def __str__(self):
"""String representation of the GUID"""
return core.las.LASGuid_AsString(self.handle)
return core.las.LASGuid_AsString(self.handle).decode()

def __eq__(self, other):
"""Test GUID for equality against another :obj:`liblas.guid.GUID`
Expand Down
26 changes: 13 additions & 13 deletions python/liblas/header.py
Expand Up @@ -42,12 +42,12 @@
****************************************************************************/
"""

import core
from . import core
import datetime
import guid
import vlr
import srs
import schema
from . import guid
from . import vlr
from . import srs
from . import schema


def leap_year(year):
Expand Down Expand Up @@ -237,12 +237,12 @@ def get_version(self):

def get_systemid(self):
"""Returns the system identifier specified in the file"""
return core.las.LASHeader_GetSystemId(self.handle)
return str(core.las.LASHeader_GetSystemId(self.handle).decode())

def set_systemid(self, value):
"""Sets the system identifier. The value is truncated to 31
characters"""
return core.las.LASHeader_SetSystemId(self.handle, value[0:31])
return core.las.LASHeader_SetSystemId(self.handle, value[0:31].encode())
doc = """The system identifier. The value is truncated to 31 characters and
defaults to 'libLAS'
Expand Down Expand Up @@ -275,12 +275,12 @@ def set_systemid(self, value):

def get_softwareid(self):
"""Returns the software identifier specified in the file"""
return core.las.LASHeader_GetSoftwareId(self.handle)
return str(core.las.LASHeader_GetSoftwareId(self.handle).decode())

def set_softwareid(self, value):
"""Sets the software identifier.
"""
return core.las.LASHeader_SetSoftwareId(self.handle, value[0:31])
return core.las.LASHeader_SetSoftwareId(self.handle, value[0:31].encode())
doc = """The software identifier. The value is truncated to 31 characters
and defaults to 'libLAS 1.LASVERSION' (ie, libLAS 1.6 for the 1.6
release)
Expand Down Expand Up @@ -389,7 +389,7 @@ def set_dataoffset(self, value):
data_offset = property(get_dataoffset, set_dataoffset, None, doc)

def get_padding(self):
"""Returns number of bytes between the end of the VLRs and the
"""Returns number of bytes between the end of the VLRs and the
beginning of the point data."""
return core.las.LASHeader_GetHeaderPadding(self.handle)

Expand All @@ -398,7 +398,7 @@ def set_padding(self, value):
"""
return core.las.LASHeader_SetHeaderPadding(self.handle, value)
doc = """The number of bytes between the end of the VLRs and the
doc = """The number of bytes between the end of the VLRs and the
beginning of the point data.
"""
padding = property(get_padding, set_padding, None, doc)
Expand Down Expand Up @@ -794,5 +794,5 @@ def set_srs(self, value):

def get_xml(self):
return core.las.LASHeader_GetXML(self.handle)
xml = property(get_xml, None, None, None)

xml = property(get_xml, None, None, None)
68 changes: 34 additions & 34 deletions python/liblas/point.py
Expand Up @@ -41,14 +41,14 @@
****************************************************************************/
"""

import core
from . import core
import datetime
import time
import math
import color
from . import color
import ctypes

import header
from . import header

class Point(object):
def __init__(self, owned=True, handle=None, copy=False):
Expand Down Expand Up @@ -94,10 +94,10 @@ def get_x(self):

def set_x(self, value):
"""Sets the X coordinate of the LAS point to a floating point
value.
..note::
The point will be descaled according to the :obj:`liblas.point.Point.header`'s
value.
..note::
The point will be descaled according to the :obj:`liblas.point.Point.header`'s
scale value for the X dimension.
"""

Expand All @@ -114,10 +114,10 @@ def get_raw_x(self):

def set_raw_x(self, value):
"""Sets the X coordinate of the LAS point to an integer value
value.
..note::
The point will be scaled according to the obj:`liblas.point.Point.header`'s
value.
..note::
The point will be scaled according to the obj:`liblas.point.Point.header`'s
scale value for the X dimension when returned as a double obj:`liblas.point.Point.x`.
"""
return core.las.LASPoint_SetRawX(self.handle, value)
Expand All @@ -137,10 +137,10 @@ def get_y(self):

def set_y(self, value):
"""Sets the Y coordinate of the LAS point to a floating point
value.
..note::
The point will be descaled according to the :obj:`liblas.point.Point.header`'s
value.
..note::
The point will be descaled according to the :obj:`liblas.point.Point.header`'s
scale value for the Y dimension.
"""
return core.las.LASPoint_SetY(self.handle, value)
Expand All @@ -158,10 +158,10 @@ def get_raw_y(self):

def set_raw_y(self, value):
"""Sets the Y coordinate of the LAS point to an integer value
value.
..note::
The point will be scaled according to the obj:`liblas.point.Point.header`'s
value.
..note::
The point will be scaled according to the obj:`liblas.point.Point.header`'s
scale value for the Y dimension when returned as a double obj:`liblas.point.Point.y`.
"""
return core.las.LASPoint_SetRawY(self.handle, value)
Expand All @@ -179,10 +179,10 @@ def get_z(self):

def set_z(self, value):
"""Sets the Z coordinate of the LAS point to a floating point
value.
..note::
The point will be descaled according to the obj:`liblas.point.Point.header`'s
value.
..note::
The point will be descaled according to the obj:`liblas.point.Point.header`'s
scale value for the Z dimension.
"""
return core.las.LASPoint_SetZ(self.handle, value)
Expand All @@ -199,10 +199,10 @@ def get_raw_z(self):

def set_raw_z(self, value):
"""Sets the Z coordinate of the LAS point to an integer value
value.
..note::
The point will be scaled according to the obj:`liblas.point.Point.header`'s
value.
..note::
The point will be scaled according to the obj:`liblas.point.Point.header`'s
scale value for the Z dimension when returned as a double obj:`liblas.point.Point.y`.
"""
return core.las.LASPoint_SetRawZ(self.handle, value)
Expand All @@ -214,7 +214,7 @@ def set_raw_z(self, value):
Use obj:`liblas.point.Point.z` if you want the scaled ``z`` data.
"""
raw_z = property(get_raw_z, set_raw_z, None, doc)

def get_return_number(self):
"""Returns the return number of the point"""
return core.las.LASPoint_GetReturnNumber(self.handle)
Expand Down Expand Up @@ -544,15 +544,15 @@ def set_color(self, value):

def get_header(self):
return header.Header(handle=core.las.LASPoint_GetHeader(self.handle))

def set_header(self, value):
return core.las.LASPoint_SetHeader(self.handle, value.handle)
header = property(get_header, set_header, None, None)


def get_xml(self):
return core.las.LASPoint_GetXML(self.handle)
return str(core.las.LASPoint_GetXML(self.handle).decode())

xml = property(get_xml, None, None, None)


Expand All @@ -562,12 +562,12 @@ def get_data(self):
d2 = ctypes.cast(d, ctypes.POINTER(ctypes.c_ubyte))
core.las.LASPoint_GetData(self.handle, d2)
return d

def set_data(self, data):
d = ctypes.cast(data, ctypes.POINTER(ctypes.c_ubyte))

core.las.LASPoint_SetData(self.handle, d, len(data))

doc = """Raw data for the point. Shoot yourself in the foot if you must!
"""
data = property(get_data, set_data, None, doc)
2 changes: 1 addition & 1 deletion python/liblas/schema.py
Expand Up @@ -41,7 +41,7 @@
****************************************************************************/
"""

import core
from . import core


class Schema(object):
Expand Down
6 changes: 3 additions & 3 deletions python/liblas/srs.py
Expand Up @@ -41,9 +41,9 @@
****************************************************************************/
"""

import core
from . import core
import ctypes
import vlr
from . import vlr


class SRS(object):
Expand Down Expand Up @@ -115,7 +115,7 @@ def set_userinput(self, value):

def get_proj4(self):
"""Returns a Proj.4_ string that describes the SRS"""
return core.las.LASSRS_GetProj4(self.handle)
return str(core.las.LASSRS_GetProj4(self.handle).decode())

def set_proj4(self, value):
"""Sets the SRS description with a given Proj.4_ string"""
Expand Down
2 changes: 1 addition & 1 deletion python/liblas/vlr.py
Expand Up @@ -41,7 +41,7 @@
****************************************************************************/
"""

import core
from . import core
import ctypes


Expand Down
8 changes: 4 additions & 4 deletions python/tests/Color.txt
Expand Up @@ -6,7 +6,7 @@
0
>>> c.blue
0

>>> c = color.Color(red = 123, blue = 125, green = 124)
>>> c.red
123
Expand All @@ -17,10 +17,10 @@


>>> for i in c:
... print i
... print(i)
123
124
125

>>> list(c)
[123, 124, 125]
[123, 124, 125]

0 comments on commit 37c04ca

Please sign in to comment.