Skip to content

Commit

Permalink
Merge pull request #282 from gadomski/pointcloud-without-statistics
Browse files Browse the repository at this point in the history
Don't error when pointcloud statistics are missing
  • Loading branch information
matthewhanson authored Mar 11, 2021
2 parents 01b8ce6 + d88f1de commit 5a492ca
Show file tree
Hide file tree
Showing 4 changed files with 152 additions and 3 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

### Fixed

- 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))

### Changed

### Removed
Expand All @@ -20,8 +22,6 @@

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


### Changed

Expand Down
5 changes: 4 additions & 1 deletion pystac/extensions/pointcloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,10 @@ def get_statistics(self, asset=None):
"""
if asset is None or 'pc:statistics' not in asset.properties:
stats = self.item.properties.get('pc:statistics')
return [PointcloudStatistic(s) for s in stats]
if stats:
return [PointcloudStatistic(s) for s in stats]
else:
return None
else:
return [PointcloudStatistic.create(s) for s in asset.properties.get('pc:statistics')]

Expand Down
140 changes: 140 additions & 0 deletions tests/data-files/pointcloud/example-laz-no-statistics.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
{
"stac_version": "1.0.0-beta.2",
"stac_extensions": [
"pointcloud"
],
"assets": {},
"bbox": [
-123.0755422,
44.04971882,
123.791472,
-123.0619599,
44.06278031,
187.531248
],
"geometry": {
"coordinates": [
[
[
-123.07498674,
44.04971882
],
[
-123.07554223,
44.06248623
],
[
-123.0625126,
44.06278031
],
[
-123.06195992,
44.05001283
],
[
-123.07498674,
44.04971882
]
]
],
"type": "Polygon"
},
"id": "autzen-full.laz",
"links": [
{
"href": "/Users/hobu/dev/git/pdal/test/data/autzen/autzen-full.laz",
"rel": "self"
}
],
"properties": {
"datetime": "2013-07-17T00:00:00Z",
"pc:count": 10653336,
"pc:density": 0,
"pc:encoding": "LASzip",
"pc:schemas": [
{
"name": "X",
"size": 8,
"type": "floating"
},
{
"name": "Y",
"size": 8,
"type": "floating"
},
{
"name": "Z",
"size": 8,
"type": "floating"
},
{
"name": "Intensity",
"size": 2,
"type": "unsigned"
},
{
"name": "ReturnNumber",
"size": 1,
"type": "unsigned"
},
{
"name": "NumberOfReturns",
"size": 1,
"type": "unsigned"
},
{
"name": "ScanDirectionFlag",
"size": 1,
"type": "unsigned"
},
{
"name": "EdgeOfFlightLine",
"size": 1,
"type": "unsigned"
},
{
"name": "Classification",
"size": 1,
"type": "unsigned"
},
{
"name": "ScanAngleRank",
"size": 4,
"type": "floating"
},
{
"name": "UserData",
"size": 1,
"type": "unsigned"
},
{
"name": "PointSourceId",
"size": 2,
"type": "unsigned"
},
{
"name": "GpsTime",
"size": 8,
"type": "floating"
},
{
"name": "Red",
"size": 2,
"type": "unsigned"
},
{
"name": "Green",
"size": 2,
"type": "unsigned"
},
{
"name": "Blue",
"size": 2,
"type": "unsigned"
}
],
"pc:type": "lidar",
"title": "USGS 3DEP LiDAR"
},
"type": "Feature"
}
6 changes: 6 additions & 0 deletions tests/extensions/test_pointcloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ class PointcloudTest(unittest.TestCase):
def setUp(self):
self.maxDiff = None
self.example_uri = TestCases.get_path('data-files/pointcloud/example-laz.json')
self.example_uri_no_statistics = TestCases.get_path(
'data-files/pointcloud/example-laz-no-statistics.json')

def test_to_from_dict(self):
with open(self.example_uri) as f:
Expand Down Expand Up @@ -184,3 +186,7 @@ def test_pointcloud_statistics(self):
val = props[k] + 1
setattr(stat, k, val)
self.assertEqual(getattr(stat, k), val)

def test_statistics_accessor_when_no_stats(self):
pc_item = pystac.read_file(self.example_uri_no_statistics)
self.assertEqual(pc_item.ext.pointcloud.statistics, None)

0 comments on commit 5a492ca

Please sign in to comment.