22PDAL
33================================================================================
44
5- The PDAL Python extension allows you to process data with PDAL into `Numpy `_
6- arrays. Additionally, you can use it to fetch `schema `_ and `metadata `_ from
5+ PDAL Python support allows you to process data with PDAL into `Numpy `_
6+ arrays. It supports embedding Python in PDAL pipelines with the `readers.numpy <https://pdal.io/stages/readers.numpy.html >`__
7+ and `filters.python <https://pdal.io/stages/filters.python.html >`__ stages, and it provides a PDAL extension module to control
8+ Python interaction with PDAL.
9+
10+ Additionally, you can use it to fetch `schema `_ and `metadata `_ from
711PDAL operations.
812
13+ Installation
14+ --------------------------------------------------------------------------------
15+
16+ PyPI
17+ ................................................................................
18+
19+ PDAL Python support is installable via PyPI:
20+
21+ .. code-block ::
22+
23+ pip install PDAL
24+
25+ GitHub
26+ ................................................................................
27+
928The repository for PDAL's Python extension is available at https://github.com/PDAL/python
1029
11- It is released independently from PDAL itself as of PDAL 1.7.
30+ Python support released independently from PDAL itself as of PDAL 1.7.
1231
1332Usage
1433--------------------------------------------------------------------------------
1534
35+ Simple
36+ ................................................................................
37+
1638Given the following pipeline, which simply reads an `ASPRS LAS `_ file and
1739sorts it by the ``X `` dimension:
1840
@@ -34,30 +56,107 @@ sorts it by the ``X`` dimension:
3456
3557 import pdal
3658 pipeline = pdal.Pipeline(json)
37- pipeline.validate() # check if our JSON and options were good
38- pipeline.loglevel = 8 # really noisy
3959 count = pipeline.execute()
4060 arrays = pipeline.arrays
4161 metadata = pipeline.metadata
4262 log = pipeline.log
4363
64+ Reading using Numpy Arrays
65+ ................................................................................
66+
67+ The following more complex scenario demonstrates the full cycling between
68+ PDAL and Python:
69+
70+ * Read a small testfile from GitHub into a Numpy array
71+ * Filters those arrays with Numpy for Intensity
72+ * Pass the filtered array to PDAL to be filtered again
73+ * Write the filtered array to an LAS file.
74+
75+ .. code-block :: python
76+
77+ data = " https://github.com/PDAL/PDAL/blob/master/test/data/las/1.2-with-color.las?raw=true"
78+
79+
80+ json = """
81+ {
82+ "pipeline": [
83+ {
84+ "type": "readers.las",
85+ "filename": "%s "
86+ }
87+ ]
88+ }"""
89+
90+ import pdal
91+ import numpy as np
92+ pipeline = pdal.Pipeline(json % data)
93+ count = pipeline.execute()
94+
95+ # get the data from the first array
96+ # [array([(637012.24, 849028.31, 431.66, 143, 1, 1, 1, 0, 1, -9., 132, 7326, 245380.78254963, 68, 77, 88),
97+ # dtype=[('X', '<f8'), ('Y', '<f8'), ('Z', '<f8'), ('Intensity', '<u2'), ('ReturnNumber', 'u1'), ('NumberOfReturns', 'u1'), ('ScanDirectionFlag', 'u1'), ('EdgeOfFlightLine', 'u1'), ('Classification', 'u1'), ('ScanAngleRank', '<f4'), ('UserData', 'u1'), ('PointSourceId', '<u2'), ('GpsTime', '<f8'), ('Red', '<u2'), ('Green', '<u2'), ('Blue', '<u2')])
98+
99+ arr = pipeline.arrays[0 ]
100+ print (len (arr)) # 1065 points
101+
102+
103+ # Filter out entries that have intensity < 50
104+ intensity = arr[arr[' Intensity' ] > 30 ]
105+ print (len (intensity)) # 704 points
106+
107+
108+ # Now use pdal to clamp points that have intensity
109+ # 100 <= v < 300, and there are 387
110+ clamp = u """ {
111+ "pipeline":[
112+ {
113+ "type":"filters.range",
114+ "limits":"Intensity[100:300)"
115+ }
116+ ]
117+ }"""
118+
119+ p = pdal.Pipeline(clamp, [intensity])
120+ count = p.execute()
121+ clamped = p.arrays[0 ]
122+ print (count)
123+
124+ # Write our intensity data to an LAS file
125+ output = u """ {
126+ "pipeline":[
127+ {
128+ "type":"writers.las",
129+ "filename":"clamped.las",
130+ "offset_x":"auto",
131+ "offset_y":"auto",
132+ "offset_z":"auto",
133+ "scale_x":0.01,
134+ "scale_y":0.01,
135+ "scale_z":0.01
136+ }
137+ ]
138+ }"""
139+
140+ p = pdal.Pipeline(output, [clamped])
141+ count = p.execute()
142+ print (count)
143+
144+
145+
44146
45147 .. _`Numpy` : http://www.numpy.org/
46148.. _`schema` : http://www.pdal.io/dimensions.html
47149.. _`metadata` : http://www.pdal.io/development/metadata.html
48150
49151
50- .. image :: https://travis-ci.org/PDAL/python.svg?branch=master
51- :target: https://travis-ci.org/PDAL/python
52-
53152.. image :: https://ci.appveyor.com/api/projects/status/of4kecyahpo8892d
54153 :target: https://ci.appveyor.com/project/hobu/python/
55154
56155Requirements
57156================================================================================
58157
59- * PDAL 1.7 +
60- * Python >=2.7 (including Python 3.x)
158+ * PDAL 2.1 +
159+ * Python >=3.6
61160* Cython (eg :code: `pip install cython `)
62161* Packaging (eg :code: `pip install packaging `)
63162
0 commit comments