def test_osm_pointcloud(self): '''osm layer cannot be added to scene with pointcloud feature''' scene = Scene() feature_layer = scene.create_layer('feature') filename = os.path.join(utils.data_folder, '100-points.las') feature_layer.create_feature('pointcloud', data=filename) self.assertRaises(Exception, scene.create_layer, 'osm')
def test_las_100points(self): '''Test creating pointcloud feature''' filename = os.path.join(utils.data_folder, '100-points.las') scene = Scene() feature_layer = scene.create_layer('feature') pointcloud = feature_layer.create_feature('pointcloud', data=filename) self.assertEqual(pointcloud.get_point_count(), 100) self.assertEqual(pointcloud.get_point_data_record_formats(), {3: 100}) self.assertEqual(pointcloud.get_point_count_by_return(), (89, 10, 1, 0, 0)) self.assertIsNone(pointcloud.get_wkt_string()) bounds = pointcloud.get_bounds() min_x = 635717.85 max_z = 530.61 self.assertAlmostEqual(bounds[0], min_x) self.assertAlmostEqual(bounds[5], max_z) # atts = pointcloud.get_point_attributes() # print(atts) display_model = scene._build_display_model() utils.write_model(display_model, 'pointcloud-100_model.json') utils.validate_model(display_model) # data should contain "data" field layers = display_model.get('layers', {}) features = layers[0].get('features') feature = features[0] self.assertIsNotNone(feature) self.assertTrue('data' in feature)
def test_pointcloud_point(self): '''pointcloud cannot be used in scene with point feature''' scene = Scene() feature_layer = scene.create_layer('feature') feature_layer.create_feature('point', data=[]) filename = os.path.join(utils.data_folder, '100-points.las') #feature_layer.create_feature('pointcloud', data=filename) self.assertRaises(Exception, feature_layer.create_feature, 'pointcloud', data=filename)
def test_shpfile_features(self): '''Test creating geojson feature from shp file''' scene = Scene() osm_layer = scene.create_layer('osm') feature_layer = scene.create_layer('feature', features=['polygon']) filename = os.path.join(utils.data_folder, 'polygons.shp') feature = feature_layer.create_feature('polygon', filename) display_model = scene._build_display_model() utils.validate_model(display_model) utils.write_model(display_model, 'shpfile_model.json')
def test_las_v14(self): '''Test that creating LAS version 1.4 not supported''' # Load as data instead of filename filename = os.path.join(utils.data_folder, 'test1_4.las') with open(filename, 'rb') as f: data = f.read() self.assertGreater(len(data), 30000) # (sanity check) scene = Scene() feature_layer = scene.create_layer('feature') #pointcloud = feature_layer.create_feature('pointcloud', data=data) self.assertRaises(Exception, feature_layer.create_feature, 'pointcloud', data=data)
def test_utm_image(self): filename = os.path.join(utils.data_folder, 'utm.tif') scene = Scene() scene.center = { 'x': -74.5, 'y': 6.0 } scene.zoom = 10 scene.create_layer('osm') feature_layer = scene.create_layer('feature', features=['quad.image']) quad = feature_layer.create_feature('raster', data=filename) quad.style = {'opacity': 0.8} display_model = scene._build_display_model() #print(display_model) # Write display model (don't need to validate again) utils.write_model(display_model, 'raster-utm_model.json')
def test_rgb_image(self): '''Test creating raster feature''' filename = os.path.join(utils.data_folder, 'rasterwithpalette.tif') scene = Scene() # scene.center = {'x': -76.5, 'y': 43.0}; # scene.zoom = 7; scene.create_layer('osm') feature_layer = scene.create_layer('feature', features=['quad.image']) quad = feature_layer.create_feature('raster', data=filename) quad.style = {'opacity': 0.5} corners = quad.get_corner_points() scene.set_zoom_and_center(corners=corners) display_model = scene._build_display_model() #print(display_model) utils.validate_model(display_model) utils.write_model(display_model, 'raster-rgb_model.json')
def test_geojson_features(self): '''Test creating geojson features''' scene = Scene() scene.center = { 'x': -76.5, 'y': 43.0 } scene.zoom = 7 scene.create_layer('osm', renderer='canvas') feature_layer = scene.create_layer( 'feature', features=['point', 'line', 'polygon']) feature_layer.create_feature('geojson', data=ny_polygons) display_model = scene._build_display_model() #print(data) # Validate display model against schema utils.validate_model(display_model) # Optionally write result to model file utils.write_model(display_model, 'geojson_model.json')
def test_basic_model(self): '''Test creating simple map with osm and feature layer''' scene = Scene(zoom=10) # pass in option to constructor scene.center = {'x': -73, 'y': 42.5} # set option as public member osm_layer = scene.create_layer('osm') feature_layer = scene.create_layer('feature') display_model = scene._build_display_model() #print(display_model) utils.validate_model(display_model) self.assertIsInstance(display_model, dict) self.assertTrue('options' in display_model) self.assertTrue('layers' in display_model) utils.write_model(display_model, 'basic_model.json')
def test_quad_feature(self): '''Test creating simple map with osm and feature layer''' scene = Scene(zoom=10) # pass in option to constructor scene.center = {'x': -97.67, 'y': 31.80} # set option as public member scene.zoom = 4 osm_layer = scene.create_layer(LayerType.OSM) feature_layer = scene.create_layer( LayerType.FEATURE, features=[FeatureType.POINT, FeatureType.QUAD]) # Point data cities = [{ 'lon': -74.0059413, 'lat': 40.7127837, 'name': "New York", 'population': 8405837 }, { 'lon': -118.2436849, 'lat': 34.0522342, 'name': "Los Angeles", 'population': 3884307 }, { 'lon': -87.6297982, 'lat': 41.8781136, 'name': "Chicago", 'population': 2718782 }, { 'lon': -95.3698028, 'lat': 29.7604267, 'name': "Houston", 'population': 2195914 }, { 'lon': -75.1652215, 'lat': 39.9525839, 'name': "Philadelphia", 'population': 1553165 }, { 'lon': -112.0740373, 'lat': 33.4483771, 'name': "Phoenix", 'population': 1513367 }] # Use lambda function to set point positions position = lambda city: {'x': city['lon'], 'y': city['lat']} style = {'strokeColor': 'black', 'strokeWidth': 2} # Use lambda function to set point radius populations = [city['population'] for city in cities] pmin = min(populations) # Scale area proportional to population rmin = 8 # minimum radius style['radius'] = lambda city: int( math.sqrt(rmin * rmin * city['population'] / pmin)) point_feature = feature_layer.create_feature(FeatureType.POINT, cities, position=position, style=style) point_feature.enableTooltip = True # adds ui layer in JS but NOT in python # Apply colormap to longitude if MPL_LOADED: cmap = mpl.cm.get_cmap('Spectral') lons = [city['lon'] for city in cities] lon_norm = mpl.colors.Normalize(vmin=min(lons), vmax=max(lons)) style['fillColor'] = lambda city: cmap(lon_norm(city['lon'])) point_feature.style = style else: point_feature.colormap = { 'colorseries': 'rainbow', 'field': 'lon', 'range': [-118.2436849, -74.0059413] } # Quad data feature_data = [{ # Copied from http://opengeoscience.github.io/geojs/tutorials/video_on_map/ 'ul': { 'x': -129.0625, 'y': 42.13468456089552 }, 'lr': { 'x': -100.9375, 'y': 29.348416310781797 } }] quad = feature_layer.create_feature(FeatureType.QUAD, feature_data) quad.style = {'color': 'magenta', 'opacity': 0.2} # Build display model display_model = scene._build_display_model() print(display_model) # Validate display model against schema utils.validate_model(display_model) # Optionally write result to model file utils.write_model(display_model, 'basic-features_model.json')