Skip to content

Commit 5a492ca

Browse files
Merge pull request #282 from gadomski/pointcloud-without-statistics
Don't error when pointcloud statistics are missing
2 parents 01b8ce6 + d88f1de commit 5a492ca

File tree

4 files changed

+152
-3
lines changed

4 files changed

+152
-3
lines changed

CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
### Fixed
88

9+
- Fixed error when accessing the statistics attribute of the pointcloud extension when no statistics were defined ([#282](https://github.com/stac-utils/pystac/pull/282))
10+
911
### Changed
1012

1113
### Removed
@@ -20,8 +22,6 @@
2022

2123
- Fix handling of optional properties when using apply on view extension ([#259](https://github.com/stac-utils/pystac/pull/259))
2224
- Fixed issue with setting None into projection extension fields that are not required breaking validation ([#269](https://github.com/stac-utils/pystac/pull/269))
23-
- Remove unnecessary `deepcopy` calls in `to_dict` methods to avoid costly overhead ([#273](https://github.com/stac-utils/pystac/pull/273))
24-
2525

2626
### Changed
2727

pystac/extensions/pointcloud.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,10 @@ def get_statistics(self, asset=None):
262262
"""
263263
if asset is None or 'pc:statistics' not in asset.properties:
264264
stats = self.item.properties.get('pc:statistics')
265-
return [PointcloudStatistic(s) for s in stats]
265+
if stats:
266+
return [PointcloudStatistic(s) for s in stats]
267+
else:
268+
return None
266269
else:
267270
return [PointcloudStatistic.create(s) for s in asset.properties.get('pc:statistics')]
268271

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
{
2+
"stac_version": "1.0.0-beta.2",
3+
"stac_extensions": [
4+
"pointcloud"
5+
],
6+
"assets": {},
7+
"bbox": [
8+
-123.0755422,
9+
44.04971882,
10+
123.791472,
11+
-123.0619599,
12+
44.06278031,
13+
187.531248
14+
],
15+
"geometry": {
16+
"coordinates": [
17+
[
18+
[
19+
-123.07498674,
20+
44.04971882
21+
],
22+
[
23+
-123.07554223,
24+
44.06248623
25+
],
26+
[
27+
-123.0625126,
28+
44.06278031
29+
],
30+
[
31+
-123.06195992,
32+
44.05001283
33+
],
34+
[
35+
-123.07498674,
36+
44.04971882
37+
]
38+
]
39+
],
40+
"type": "Polygon"
41+
},
42+
"id": "autzen-full.laz",
43+
"links": [
44+
{
45+
"href": "/Users/hobu/dev/git/pdal/test/data/autzen/autzen-full.laz",
46+
"rel": "self"
47+
}
48+
],
49+
"properties": {
50+
"datetime": "2013-07-17T00:00:00Z",
51+
"pc:count": 10653336,
52+
"pc:density": 0,
53+
"pc:encoding": "LASzip",
54+
"pc:schemas": [
55+
{
56+
"name": "X",
57+
"size": 8,
58+
"type": "floating"
59+
},
60+
{
61+
"name": "Y",
62+
"size": 8,
63+
"type": "floating"
64+
},
65+
{
66+
"name": "Z",
67+
"size": 8,
68+
"type": "floating"
69+
},
70+
{
71+
"name": "Intensity",
72+
"size": 2,
73+
"type": "unsigned"
74+
},
75+
{
76+
"name": "ReturnNumber",
77+
"size": 1,
78+
"type": "unsigned"
79+
},
80+
{
81+
"name": "NumberOfReturns",
82+
"size": 1,
83+
"type": "unsigned"
84+
},
85+
{
86+
"name": "ScanDirectionFlag",
87+
"size": 1,
88+
"type": "unsigned"
89+
},
90+
{
91+
"name": "EdgeOfFlightLine",
92+
"size": 1,
93+
"type": "unsigned"
94+
},
95+
{
96+
"name": "Classification",
97+
"size": 1,
98+
"type": "unsigned"
99+
},
100+
{
101+
"name": "ScanAngleRank",
102+
"size": 4,
103+
"type": "floating"
104+
},
105+
{
106+
"name": "UserData",
107+
"size": 1,
108+
"type": "unsigned"
109+
},
110+
{
111+
"name": "PointSourceId",
112+
"size": 2,
113+
"type": "unsigned"
114+
},
115+
{
116+
"name": "GpsTime",
117+
"size": 8,
118+
"type": "floating"
119+
},
120+
{
121+
"name": "Red",
122+
"size": 2,
123+
"type": "unsigned"
124+
},
125+
{
126+
"name": "Green",
127+
"size": 2,
128+
"type": "unsigned"
129+
},
130+
{
131+
"name": "Blue",
132+
"size": 2,
133+
"type": "unsigned"
134+
}
135+
],
136+
"pc:type": "lidar",
137+
"title": "USGS 3DEP LiDAR"
138+
},
139+
"type": "Feature"
140+
}

tests/extensions/test_pointcloud.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ class PointcloudTest(unittest.TestCase):
1313
def setUp(self):
1414
self.maxDiff = None
1515
self.example_uri = TestCases.get_path('data-files/pointcloud/example-laz.json')
16+
self.example_uri_no_statistics = TestCases.get_path(
17+
'data-files/pointcloud/example-laz-no-statistics.json')
1618

1719
def test_to_from_dict(self):
1820
with open(self.example_uri) as f:
@@ -184,3 +186,7 @@ def test_pointcloud_statistics(self):
184186
val = props[k] + 1
185187
setattr(stat, k, val)
186188
self.assertEqual(getattr(stat, k), val)
189+
190+
def test_statistics_accessor_when_no_stats(self):
191+
pc_item = pystac.read_file(self.example_uri_no_statistics)
192+
self.assertEqual(pc_item.ext.pointcloud.statistics, None)

0 commit comments

Comments
 (0)