def test_load_osm(): outfile = 'tmp-file.osm' data = etl2osm.extract(roads['geojson']) data.save(outfile) assert os.path.exists(outfile) os.remove(outfile) data = etl2osm.extract(addresses['geojson']) data.save(outfile) assert os.path.exists(outfile) os.remove(outfile)
def test_load_geojson(): outfile = 'tmp-file.geojson' data = etl2osm.extract(roads['lake_county']) data.transform(config={'foo': {'text': 'bar'}}) data.save(outfile) assert os.path.exists(outfile) os.remove(outfile)
def test_extract_geojson(): data = etl2osm.extract(roads['geojson']) assert data.crs == crs assert data.epsg == 'EPSG:4326' assert data.geojson assert 'LineString' in data.geometry assert data.properties assert len(data)
def test_load_no_geometry(): outfile = 'tmp-file.osm' data = etl2osm.extract(geojson['no-geometry']) data.save(outfile) assert os.path.exists(outfile) os.remove(outfile) # ---------->>>>>>>>>------------------- # TO-DO: Find corrupt Shapefile # This shapefile does contain all it's goemetry # Coverage: extract.py LINE 93 # Trigger: logging.warning('Could not find [geometry] in feature.') # ---------->>>>>>>>>------------------- data = etl2osm.extract(shapefile['no-geometry']) data.save(outfile) assert os.path.exists(outfile) os.remove(outfile)
def test_extract_point(): feature = { "type": "Feature", "geometry": { "type": "Point", "coordinates": [100.0, 0.0] } } data = etl2osm.extract(feature) assert data[0]['geometry']['type'] == 'Point'
def test_extract_multi_point(): feature = { "type": "Feature", "geometry": { "type": "MultiPoint", "coordinates": [[100.0, 0.0], [101.0, 1.0]] } } data = etl2osm.extract(feature) assert data[0]['geometry']['type'] == 'MultiPoint'
def test_load_shapefile(): outfile = 'tmp-file.shp' basename = os.path.splitext(outfile)[0] data = etl2osm.extract(roads['lake_county']) data.transform(config={'foo': {'text': 'bar'}}) data.save(outfile) for ext in ['.shp', '.cpg', '.dbf', '.prj', '.shx']: filepath = ''.join((basename, ext)) assert os.path.exists(filepath) os.remove(filepath)
def test_speed_extract_shapefile(infile=roads['shp']): """ Geometry: set(['LineString']) | count: 3 | time: 302 ms/feature Geometry: set(['Polygon']) | count: 106218 | time: 1 ms/feature """ before = datetime.now() data = etl2osm.extract(infile) microseconds = (datetime.now() - before).microseconds print 'Geometry: {} | count: {} | time: {} ms/feature'.format( data.geometry, len(data), microseconds / len(data) )
def test_speed_extract_geojson(infile=roads['geojson']): """ Geometry: set([u'LineString']) | count: 17057 | time: 36 ms/feature Geometry: set([u'LineString']) | count: 3 | time: 55 ms/feature """ before = datetime.now() data = etl2osm.extract(infile) microseconds = (datetime.now() - before).microseconds print 'Geometry: {} | count: {} | time: {} ms/feature'.format( data.geometry, len(data), microseconds / len(data) )
def test_speed_transform_false(infile=roads['geojson']): """ Geometry: set(['LineString']) | Reproject: False | count: 18809 | time: 1 ms/feature Geometry: set(['Point']) | Reproject: False | count: 31478 | time: 1 ms/feature Geometry: set(['Polygon']) | Reproject: False | count: 106218 | time: 1 ms/feature """ data = etl2osm.extract(infile) before = datetime.now() data.transform(reproject=False) microseconds = (datetime.now() - before).microseconds print 'Geometry: {} | Reproject: False | count: {} | time: {} ms/feature'.format( data.geometry, len(data), microseconds / len(data) )
def test_extract_blank(): with pytest.raises(ValueError): etl2osm.extract(roads['geojson-blank'])
def test_extract_file_extension(): with pytest.raises(ValueError): etl2osm.extract("/path-not-exist.topojson") with pytest.raises(ValueError): etl2osm.extract("/path-not-exist.shp")
def test_extract_zero(): with pytest.raises(ValueError): etl2osm.extract(roads['geojson-zero'])
def test_extract_unknown(): with pytest.raises(ValueError): etl2osm.extract(roads['unknown'])
def test_extract_shapefile(): data = etl2osm.extract(roads['shp']) assert data.epsg == 'EPSG:4326' assert data.crs assert data.geojson assert len(data)
def test_extract_lookup(): data = etl2osm.extract(roads['geojson']) assert data[0]
def test_overlapping_osm_nodes(): outfile = 'tmp-file.osm' data = etl2osm.extract(geojson['overlapping']) data.save(outfile) assert os.path.exists(outfile) os.remove(outfile)
def test_load_kml(): outfile = 'tmp-file.kml' data = etl2osm.extract(roads['geojson']) with pytest.raises(ValueError): data.save(outfile)
def test_extract_add(): data1 = etl2osm.extract(roads['geojson']) data2 = etl2osm.extract(roads['geojson']) assert len(data1) == 3 assert len(data2) == 3 assert len(data1 + data2) == 6
def test_extract_kml(): with pytest.raises(ValueError): etl2osm.extract(roads['kml'])
def test_extract_topojson(): with pytest.raises(ValueError): etl2osm.extract(roads['topojson'])
def test_extract_shapefile_utm(): data = etl2osm.extract(shapefile['utm_projection']) assert data.epsg != 'EPSG:4326' data.transform() assert data.epsg == 'EPSG:4326'
def test_extract_lake_county_roads(): data = etl2osm.extract(roads['lake_county']) assert data.geojson assert len(data)
def test_extract_osm(): with pytest.raises(ValueError): etl2osm.extract(roads['osm'])
def test_api_extract(): data = etl2osm.extract(roads['geojson']) assert data.geojson assert data.epsg
def test_transform_geojson(): data = etl2osm.extract(roads['geojson']) data.transform() assert data.epsg == 'EPSG:4326'