def srs_msk23_id(): with transaction.manager: obj = SRS( display_name="MSK23", wkt= 'PROJCS["МСК 23 зона 1",GEOGCS["GCS_Pulkovo_1942",DATUM["Pulkovo_1942",SPHEROID["Krassowsky_1940",6378245.0,298.3]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Transverse_Mercator"],PARAMETER["False_Easting",1300000.0],PARAMETER["False_Northing",-4511057.628],PARAMETER["Central_Meridian",37.98333333333],PARAMETER["Scale_Factor",1.0],PARAMETER["Latitude_Of_Origin",0.0],UNIT["Meter",1.0]]', # NOQA: E501 ).persist() DBSession.flush() DBSession.expunge(obj) yield obj.id with transaction.manager: DBSession.delete(SRS.filter_by(id=obj.id).one())
def vector_layer_id(ngw_resource_group): with transaction.manager: obj = VectorLayer( parent_id=ngw_resource_group, display_name='vector_layer', owner_user=User.by_keyname('administrator'), srs=SRS.filter_by(id=3857).one(), tbl_uuid=uuid4().hex, ).persist() geojson = { 'type': 'FeatureCollection', 'features': get_features_for_orderby_test() } dsource = ogr.Open(json.dumps(geojson)) layer = dsource.GetLayer(0) obj.setup_from_ogr(layer) obj.load_from_ogr(layer) DBSession.flush() DBSession.expunge(obj) yield obj.id with transaction.manager: DBSession.delete(VectorLayer.filter_by(id=obj.id).one())
def test_point_tilexy(ngw_txn): zoom = 12 vdk_x, vdk_y = 14681475, 5329463 srs_3857 = SRS.filter_by(id=3857).one() assert list(map(int, srs_3857._point_tilexy(vdk_x, vdk_y, zoom))) == [3548, 1503] srs_3395 = SRS( wkt=WKT_EPSG_3395, minx=-20037508.342789244, miny=-20037508.342789244, maxx=20037508.342789244, maxy=20037508.342789244, ) vdk_x, vdk_y = 14681475, 5300249 assert list(map(int, srs_3395._point_tilexy(vdk_x, vdk_y, zoom))) == [3548, 1506]
def vector_layer_id(ngw_resource_group): with transaction.manager: obj = VectorLayer( parent_id=ngw_resource_group, display_name='vector_layer', owner_user=User.by_keyname('administrator'), srs=SRS.filter_by(id=3857).one(), tbl_uuid=uuid4().hex, ).persist() geojson = { "type": "FeatureCollection", "name": "polygon_extent", "crs": {"type": "name", "properties": {"name": "urn:ogc:def:crs:EPSG::3857"}}, "features": [ { "type": "Feature", "properties": {"name": "west"}, "geometry": { "type": "Polygon", "coordinates": [[ [5542180, 8799167], [6191082, 7551279], [4668659, 7126998], [5542180, 8799167], ]], }, }, { "type": "Feature", "properties": {"name": "east"}, "geometry": { "type": "Polygon", "coordinates": [[ [15100999, 10396463], [16498633, 10546209], [16673337, 9223449], [15175872, 8948913], [15100999, 10396463], ]], }, }, ], } dsource = ogr.Open(json.dumps(geojson)) layer = dsource.GetLayer(0) obj.setup_from_ogr(layer) obj.load_from_ogr(layer) DBSession.flush() DBSession.expunge(obj) yield obj.id with transaction.manager: DBSession.delete(VectorLayer.filter_by(id=obj.id).one())
def vector_layer_id(ngw_resource_group): with transaction.manager: obj = VectorLayer( parent_id=ngw_resource_group, display_name='vector_layer', owner_user=User.by_keyname('administrator'), srs=SRS.filter_by(id=3857).one(), tbl_uuid=uuid4().hex, ).persist() geojson = { 'type': 'FeatureCollection', 'crs': { 'type': 'name', 'properties': { 'name': 'urn:ogc:def:crs:EPSG::3857' } }, 'features': [{ 'type': 'Feature', 'properties': { 'price': -1, 'name': 'feature1' }, 'geometry': { 'type': 'Point', 'coordinates': [0, 0] } }, { 'type': 'Feature', 'properties': { 'price': -2, 'name': 'feature2' }, 'geometry': { 'type': 'Point', 'coordinates': [0, 0] } }] } dsource = ogr.Open(json.dumps(geojson)) layer = dsource.GetLayer(0) obj.setup_from_ogr(layer) obj.load_from_ogr(layer) DBSession.flush() DBSession.expunge(obj) yield obj.id with transaction.manager: DBSession.delete(VectorLayer.filter_by(id=obj.id).one())
def test_layer(ngw_webtest_app, ngw_auth_administrator, ngw_resource_group): data = dict( resource=dict( cls='tmsclient_connection', display_name='test-tms_connection', parent=dict(id=ngw_resource_group), ), tmsclient_connection=dict( url_template= 'https://tile-c.openstreetmap.fr/{layer}/{z}/{x}/{y}.png', scheme='xyz', ), ) resp = ngw_webtest_app.post_json('/api/resource/', data, status=201) connection_id = resp.json['id'] maxzoom = 3 data = dict( resource=dict( cls='tmsclient_layer', display_name='test-tms_layer', parent=dict(id=ngw_resource_group), ), tmsclient_layer=dict( connection=dict(id=connection_id), srs=dict(id=3857), layer_name='hot', minzoom=0, maxzoom=maxzoom, ), ) resp = ngw_webtest_app.post_json('/api/resource/', data, status=201) layer_id = resp.json['id'] ngw_webtest_app.get('/api/component/render/tile?z=%d&x=0&y=0&resource=%d' % (maxzoom + 1, layer_id), status=422) layer = Layer.filter_by(id=layer_id).one() srs = SRS.filter_by(id=3857).one() req = layer.render_request(srs) image1 = req.render_tile((0, 0, 0), 256) image2 = req.render_extent(BOUNDS_EPSG_3857, (256, 256)) assert image_compare(image1, image2) image1 = req.render_tile((1, 0, 0), 256) image2 = req.render_extent(BOUNDS_EPSG_3857, (512, 512)) assert image_compare(image1, image2.crop((0, 0, 256, 256))) ngw_webtest_app.delete('/api/resource/%d' % layer_id, status=200) ngw_webtest_app.delete('/api/resource/%d' % connection_id, status=200)
def test_postgis_sync(txn): obj = SRS(wkt=WKT_ESPG_4326, display_name='') obj.persist() DBSession.flush() assert obj.id >= SRID_LOCAL qpg = db.text('SELECT srtext FROM spatial_ref_sys WHERE srid = :id') srtext, = DBSession.connection().execute(qpg, id=obj.id).fetchone() assert obj.wkt == srtext obj.wkt = WKT_ESPG_3857 DBSession.flush() srtext, = DBSession.connection().execute(qpg, id=obj.id).fetchone() assert obj.wkt == srtext DBSession.delete(obj) DBSession.flush() assert DBSession.connection().execute(qpg, id=obj.id).fetchone() is None
def test_wkt_invalid(): with pytest.raises(ValidationError): SRS(wkt='INVALID')
def test_wkt_valid(): SRS(wkt=WKT_ESPG_4326)
def test_render_zoom(ngw_txn, srs_id, extent, size, tilesize, expected): srs = SRS.filter_by(id=srs_id).one() zoom = render_zoom(srs, extent, size, tilesize) assert zoom == expected
def test_extent_tile_range(ngw_txn, srs_id, extent, z, expected): srs = SRS.filter_by(id=srs_id).one() tile_range = srs.extent_tile_range(tuple(map(float, extent)), z) assert tile_range == expected
def test_tile_extent(ngw_txn, srs_id, tile, expected): srs = SRS.filter_by(id=srs_id).one() extent = tuple([round(c, 2) for c in srs.tile_extent(tile)]) assert extent == expected