Skip to content

Commit

Permalink
Geometry collection layer type (#94)
Browse files Browse the repository at this point in the history
Closes #89
  • Loading branch information
index-git authored Aug 19, 2020
1 parent 6cd860c commit 3702b1e
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
- Undocumented authentication module `layman.authn.url_path.py` that was unused for a long time, was removed.
- Python setting [`PG_NON_USER_SCHEMAS`](src/layman_settings.py) is now more explicit about forbidden schema names.
- [#73](https://github.com/jirik/layman/issues/73) Layman users are automatically created on GeoServer (either at start up of Layman or when reserved) with separate role and workspace. Username is the same as in Layman, name of role is `"USER_"+username`, name of workspace is the same as username. Read and write permissions for workspace are set according to Layman's authorization (as of now read-everyone-write-everyone or read-everyone-write-owner).
- [#83](https://github.com/jirik/layman/issues/89) All layers are created as `GEOMETRY` type, so any other type can be added (for example polygons can be added to points).

## v1.5.0
2020-06-18
Expand Down
2 changes: 1 addition & 1 deletion src/layman/layer/db/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ def import_layer_vector_file_async(username, layername, main_filepath,
'ogr2ogr',
'-t_srs', 'EPSG:3857',
'-nln', layername,
'-nlt', 'GEOMETRY',
'--config', 'OGR_ENABLE_PARTIAL_REPROJECTION', 'TRUE',
'-lco', f'SCHEMA={username}',
# '-clipsrc', '-180', '-85.06', '180', '85.06',
Expand All @@ -119,7 +120,6 @@ def import_layer_vector_file_async(username, layername, main_filepath,
])
if os.path.splitext(main_filepath)[1] == '.shp':
bash_args.extend([
'-nlt', 'PROMOTE_TO_MULTI',
'-lco', 'PRECISION=NO',
])
bash_args.extend([
Expand Down
115 changes: 115 additions & 0 deletions src/layman/layer/rest_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1128,3 +1128,118 @@ def test_get_layers_testuser2(client):
uuid.check_redis_consistency(expected_publ_num_by_type={
f'{LAYER_TYPE}': num_layers_before_test + 2
})


@pytest.mark.usefixtures('app_context')
def test_layer_with_different_geometry(client):
username = 'testgeometryuser1'
layername = 'layer_with_different_geometry'
rest_path = url_for('rest_layers.post', username=username)
file_paths = [
'tmp/naturalearth/110m/cultural/ne_110m_populated_places.geojson',
]
for fp in file_paths:
assert os.path.isfile(fp)
files = []
try:
files = [(open(fp, 'rb'), os.path.basename(fp)) for fp in file_paths]
rv = client.post(rest_path, data={
'file': files,
'name': layername
})
assert rv.status_code == 200
finally:
for fp in files:
fp[0].close()

wait_till_ready(username, layername)

url_path_ows = urljoin(urljoin(settings.LAYMAN_GS_URL, username), 'ows?service=WFS&request=Transaction')
url_path_wfs = urljoin(urljoin(settings.LAYMAN_GS_URL, username), 'wfs?request=Transaction')

headers_wfs = {
'Accept': 'text/xml',
'Content-type': 'text/xml',
}

data_xml = '''<?xml version="1.0"?>
<wfs:Transaction
version="2.0.0"
service="WFS"
xmlns:testgeometryuser1="http://testgeometryuser1"
xmlns:fes="http://www.opengis.net/fes/2.0"
xmlns:gml="http://www.opengis.net/gml/3.2"
xmlns:wfs="http://www.opengis.net/wfs/2.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.opengis.net/wfs/2.0
http://schemas.opengis.net/wfs/2.0/wfs.xsd
http://www.opengis.net/gml/3.2
http://schemas.opengis.net/gml/3.2.1/gml.xsd">
<wfs:Insert>
<testgeometryuser1:layer_with_different_geometry>
<testgeometryuser1:wkb_geometry>
<gml:Point srsName="urn:ogc:def:crs:EPSG::3857" srsDimension="2">
<gml:pos>1.27108004304E7 2548415.5977</gml:pos>
</gml:Point>
</testgeometryuser1:wkb_geometry>
</testgeometryuser1:layer_with_different_geometry>
</wfs:Insert>
</wfs:Transaction>'''

r = requests.post(url_path_ows,
data=data_xml,
headers=headers_wfs,
auth=settings.LAYMAN_GS_AUTH
)
r.raise_for_status()

r = requests.post(url_path_wfs,
data=data_xml,
headers=headers_wfs,
auth=settings.LAYMAN_GS_AUTH
)
assert r.status_code == 200, f"HTTP Error {r.status_code}\n{r.text}"

data_xml2 = '''<?xml version="1.0"?>
<wfs:Transaction
version="2.0.0"
service="WFS"
xmlns:testgeometryuser1="http://testgeometryuser1"
xmlns:fes="http://www.opengis.net/fes/2.0"
xmlns:gml="http://www.opengis.net/gml/3.2"
xmlns:wfs="http://www.opengis.net/wfs/2.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.opengis.net/wfs/2.0
http://schemas.opengis.net/wfs/2.0/wfs.xsd
http://www.opengis.net/gml/3.2
http://schemas.opengis.net/gml/3.2.1/gml.xsd">
<wfs:Insert>
<testgeometryuser1:layer_with_different_geometry>
<testgeometryuser1:wkb_geometry>
<gml:MultiCurve srsName="urn:ogc:def:crs:EPSG::3857" srsDimension="2">
<gml:curveMember>
<gml:LineString>
<gml:posList>3722077.1689 5775850.1007 3751406.9331 5815606.0102 3830548.3984 5781176.5357
3866350.4899 5774848.8358 3880796.9478 5743277.797 3897591.3679 5738418.6547
</gml:posList>
</gml:LineString>
</gml:curveMember>
</gml:MultiCurve>
</testgeometryuser1:wkb_geometry>
</testgeometryuser1:layer_with_different_geometry>
</wfs:Insert>
</wfs:Transaction>'''

r = requests.post(url_path_ows,
data=data_xml2,
headers=headers_wfs,
auth=settings.LAYMAN_GS_AUTH
)
assert r.status_code == 200, f"HTTP Error {r.status_code}\n{r.text}"

r = requests.post(url_path_wfs,
data=data_xml2,
headers=headers_wfs,
auth=settings.LAYMAN_GS_AUTH
)
assert r.status_code == 200, f"HTTP Error {r.status_code}\n{r.text}"

0 comments on commit 3702b1e

Please sign in to comment.