5
5
# from copy import deepcopy
6
6
7
7
import pystac
8
+ from pystac .asset import Asset
9
+ from pystac .errors import ExtensionTypeError , STACError
8
10
from pystac .extensions .pointcloud import (
11
+ AssetPointcloudExtension ,
9
12
PointcloudExtension ,
10
13
PointcloudSchema ,
11
14
PointcloudStatistic ,
@@ -178,6 +181,22 @@ def test_pointcloud_schema(self):
178
181
setattr (schema , k , val )
179
182
self .assertEqual (getattr (schema , k ), val )
180
183
184
+ schema = PointcloudSchema .create ("intensity" , 16 , "unsigned" )
185
+ self .assertEqual (schema .name , "intensity" )
186
+ self .assertEqual (schema .size , 16 )
187
+ self .assertEqual (schema .type , "unsigned" )
188
+
189
+ with self .assertRaises (STACError ):
190
+ schema .size = 0.5 # type: ignore
191
+
192
+ empty_schema = PointcloudSchema ({})
193
+ with self .assertRaises (STACError ):
194
+ empty_schema .size
195
+ with self .assertRaises (STACError ):
196
+ empty_schema .name
197
+ with self .assertRaises (STACError ):
198
+ empty_schema .type
199
+
181
200
def test_pointcloud_statistics (self ):
182
201
props : Dict [str , Any ] = {
183
202
"average" : 1 ,
@@ -201,6 +220,76 @@ def test_pointcloud_statistics(self):
201
220
setattr (stat , k , val )
202
221
self .assertEqual (getattr (stat , k ), val )
203
222
223
+ stat = PointcloudStatistic .create ("foo" , 1 , 2 , 3 , 4 , 5 , 6 , 7 )
224
+ self .assertEqual (stat .name , "foo" )
225
+ self .assertEqual (stat .position , 1 )
226
+ self .assertEqual (stat .average , 2 )
227
+ self .assertEqual (stat .count , 3 )
228
+ self .assertEqual (stat .maximum , 4 )
229
+ self .assertEqual (stat .minimum , 5 )
230
+ self .assertEqual (stat .stddev , 6 )
231
+ self .assertEqual (stat .variance , 7 )
232
+
233
+ stat .name = None # type: ignore
234
+ self .assertNotIn ("name" , stat .properties )
235
+ stat .position = None
236
+ self .assertNotIn ("position" , stat .properties )
237
+ stat .average = None
238
+ self .assertNotIn ("average" , stat .properties )
239
+ stat .count = None
240
+ self .assertNotIn ("count" , stat .properties )
241
+ stat .maximum = None
242
+ self .assertNotIn ("maximum" , stat .properties )
243
+ stat .minimum = None
244
+ self .assertNotIn ("minimum" , stat .properties )
245
+ stat .stddev = None
246
+ self .assertNotIn ("stddev" , stat .properties )
247
+ stat .variance = None
248
+ self .assertNotIn ("variance" , stat .properties )
249
+
250
+ empty_stat = PointcloudStatistic ({})
251
+ with self .assertRaises (STACError ):
252
+ empty_stat .name
253
+
204
254
def test_statistics_accessor_when_no_stats (self ):
205
255
pc_item = pystac .Item .from_file (self .example_uri_no_statistics )
206
256
self .assertEqual (PointcloudExtension .ext (pc_item ).statistics , None )
257
+
258
+ def test_asset_extension (self ):
259
+ asset = Asset (
260
+ "https://github.com/PDAL/PDAL/blob"
261
+ "/a6c986f68458e92414a66c664408bee4737bbb08/test/data/laz"
262
+ "/autzen_trim.laz" ,
263
+ "laz file" ,
264
+ "The laz data" ,
265
+ "application/octet-stream" ,
266
+ ["data" ],
267
+ {"foo" : "bar" },
268
+ )
269
+ pc_item = pystac .Item .from_file (self .example_uri_no_statistics )
270
+ pc_item .add_asset ("data" , asset )
271
+ ext = AssetPointcloudExtension (asset )
272
+ self .assertEqual (ext .asset_href , asset .href )
273
+ self .assertEqual (ext .properties , asset .properties )
274
+ self .assertEqual (ext .additional_read_properties , [pc_item .properties ])
275
+
276
+ def test_ext (self ):
277
+ pc_item = pystac .Item .from_file (self .example_uri_no_statistics )
278
+ PointcloudExtension .ext (pc_item )
279
+ asset = Asset (
280
+ "https://github.com/PDAL/PDAL/blob"
281
+ "/a6c986f68458e92414a66c664408bee4737bbb08/test/data/laz"
282
+ "/autzen_trim.laz" ,
283
+ "laz file" ,
284
+ "The laz data" ,
285
+ "application/octet-stream" ,
286
+ ["data" ],
287
+ {"foo" : "bar" },
288
+ )
289
+ PointcloudExtension .ext (asset )
290
+
291
+ class RandomObject :
292
+ pass
293
+
294
+ with self .assertRaises (ExtensionTypeError ):
295
+ PointcloudExtension .ext (RandomObject ()) # type: ignore
0 commit comments