Skip to content

Commit d9e4968

Browse files
Merge pull request #106 from Geode-solutions/feat/get_polygon_attributes
Feat/get polygon attributes
2 parents 4ceba96 + bbb48cd commit d9e4968

14 files changed

+291
-79
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
.pytest_cache
2-
./data
2+
/data
33
dist
44
venv
55
output

pytest.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[pytest]
2+
addopts = --ignore=src/opengeodeweb_back/

requirements.txt

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,22 @@ attrs==24.2.0
1010
# via
1111
# jsonschema
1212
# referencing
13-
blinker==1.8.2
13+
blinker==1.9.0
1414
# via flask
1515
click==8.1.7
1616
# via flask
17-
flask[async]==3.0.3
17+
flask[async]==3.1.0
1818
# via
1919
# -r requirements.in
2020
# flask-cors
2121
flask-cors==5.0.0
2222
# via -r requirements.in
23-
geode-background==8.7.0
23+
geode-background==8.7.5
2424
# via
2525
# geode-explicit
2626
# geode-implicit
2727
# geode-simplex
28-
geode-common==33.0.9
28+
geode-common==33.1.3
2929
# via
3030
# -r requirements.in
3131
# geode-background
@@ -35,26 +35,26 @@ geode-common==33.0.9
3535
# geode-numerics
3636
# geode-simplex
3737
# geode-viewables
38-
geode-conversion==6.0.14
38+
geode-conversion==6.0.18
3939
# via
4040
# geode-explicit
4141
# geode-implicit
42-
geode-explicit==6.1.14
42+
geode-explicit==6.1.17
4343
# via
4444
# -r requirements.in
4545
# geode-implicit
46-
geode-implicit==3.3.2
46+
geode-implicit==3.3.5
4747
# via -r requirements.in
48-
geode-numerics==5.1.8
48+
geode-numerics==5.2.0
4949
# via
5050
# -r requirements.in
5151
# geode-implicit
5252
# geode-simplex
53-
geode-simplex==8.2.15
53+
geode-simplex==8.2.18
5454
# via
5555
# -r requirements.in
5656
# geode-implicit
57-
geode-viewables==3.0.6
57+
geode-viewables==3.0.8
5858
# via -r requirements.in
5959
itsdangerous==2.2.0
6060
# via flask
@@ -68,7 +68,7 @@ markupsafe==3.0.2
6868
# via
6969
# jinja2
7070
# werkzeug
71-
opengeode-core==15.6.3
71+
opengeode-core==15.6.7
7272
# via
7373
# -r requirements.in
7474
# geode-background
@@ -83,23 +83,23 @@ opengeode-core==15.6.3
8383
# opengeode-geosciencesio
8484
# opengeode-inspector
8585
# opengeode-io
86-
opengeode-geosciences==8.1.1
86+
opengeode-geosciences==8.2.0
8787
# via
8888
# -r requirements.in
8989
# geode-implicit
9090
# geode-viewables
9191
# opengeode-geosciencesio
92-
opengeode-geosciencesio==5.2.3
92+
opengeode-geosciencesio==5.3.2
9393
# via
9494
# -r requirements.in
9595
# geode-implicit
96-
opengeode-inspector==6.1.12
96+
opengeode-inspector==6.1.15
9797
# via
9898
# -r requirements.in
9999
# geode-explicit
100100
# geode-implicit
101101
# geode-simplex
102-
opengeode-io==7.0.5
102+
opengeode-io==7.0.7
103103
# via
104104
# -r requirements.in
105105
# geode-implicit
@@ -115,7 +115,7 @@ rpds-py==0.21.0
115115
# referencing
116116
typing-extensions==4.12.2
117117
# via asgiref
118-
werkzeug==3.1.2
118+
werkzeug==3.1.3
119119
# via
120120
# -r requirements.in
121121
# flask

src/opengeodeweb_back/geode_objects.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1+
# Standard library imports
2+
3+
# Third party imports
14
import opengeode as og
25
import opengeode_io as og_io
36
import opengeode_inspector as og_inspector
47
import opengeode_geosciences as og_gs
58
import opengeode_geosciencesio as og_gs_io
69
import geode_viewables as g_v
710

11+
# Local application imports
12+
813

914
def geode_objects_dict():
1015
return {

src/opengeodeweb_back/routes/blueprint_routes.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,68 @@ def create_point():
304304
)
305305

306306

307+
with open(
308+
os.path.join(schemas, "vertex_attribute_names.json"),
309+
"r",
310+
) as file:
311+
vertex_attribute_names_json = json.load(file)
312+
313+
314+
@routes.route(
315+
vertex_attribute_names_json["route"],
316+
methods=vertex_attribute_names_json["methods"],
317+
)
318+
def vertex_attribute_names():
319+
320+
UPLOAD_FOLDER = flask.current_app.config["UPLOAD_FOLDER"]
321+
utils_functions.validate_request(flask.request, vertex_attribute_names_json)
322+
file_absolute_path = os.path.join(
323+
UPLOAD_FOLDER, werkzeug.utils.secure_filename(flask.request.json["filename"])
324+
)
325+
data = geode_functions.load(
326+
flask.request.json["input_geode_object"], file_absolute_path
327+
)
328+
vertex_attribute_names = data.vertex_attribute_manager().attribute_names()
329+
330+
return flask.make_response(
331+
{
332+
"vertex_attribute_names": vertex_attribute_names,
333+
},
334+
200,
335+
)
336+
337+
338+
with open(
339+
os.path.join(schemas, "polygon_attribute_names.json"),
340+
"r",
341+
) as file:
342+
polygon_attribute_names_json = json.load(file)
343+
344+
345+
@routes.route(
346+
polygon_attribute_names_json["route"],
347+
methods=polygon_attribute_names_json["methods"],
348+
)
349+
def polygon_attribute_names():
350+
351+
UPLOAD_FOLDER = flask.current_app.config["UPLOAD_FOLDER"]
352+
utils_functions.validate_request(flask.request, vertex_attribute_names_json)
353+
file_absolute_path = os.path.join(
354+
UPLOAD_FOLDER, werkzeug.utils.secure_filename(flask.request.json["filename"])
355+
)
356+
data = geode_functions.load(
357+
flask.request.json["input_geode_object"], file_absolute_path
358+
)
359+
polygon_attribute_names = data.polygon_attribute_manager().attribute_names()
360+
361+
return flask.make_response(
362+
{
363+
"polygon_attribute_names": polygon_attribute_names,
364+
},
365+
200,
366+
)
367+
368+
307369
with open(
308370
os.path.join(schemas, "ping.json"),
309371
"r",
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"route": "/polygon_attribute_names",
3+
"methods": ["POST"],
4+
"type": "object",
5+
"properties": {
6+
"input_geode_object": {
7+
"type": "string"
8+
},
9+
"filename": {
10+
"type": "string"
11+
}
12+
},
13+
"required": ["input_geode_object", "filename"],
14+
"additionalProperties": false
15+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"route": "/vertex_attribute_names",
3+
"methods": ["POST"],
4+
"type": "object",
5+
"properties": {
6+
"input_geode_object": {
7+
"type": "string"
8+
},
9+
"filename": {
10+
"type": "string"
11+
}
12+
},
13+
"required": ["input_geode_object", "filename"],
14+
"additionalProperties": false
15+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Standard library imports
2+
3+
# Third party imports
4+
5+
# Local application imports
6+
7+
8+
def test_route_wrong_params(client, route, get_full_data):
9+
for key, value in get_full_data().items():
10+
json = get_full_data()
11+
json.pop(key)
12+
response = client.post(route, json=json)
13+
assert response.status_code == 400
14+
error_description = response.json["description"]
15+
assert error_description == f"Validation error: '{key}' is a required property"
16+
17+
json = get_full_data()
18+
json["dumb_key"] = "dumb_value"
19+
response = client.post(route, json=json)
20+
assert response.status_code == 400
21+
error_description = response.json["description"]
22+
assert (
23+
error_description
24+
== "Validation error: Additional properties are not allowed ('dumb_key' was unexpected)"
25+
)

tests/conftest.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1+
# Standard library imports
2+
import time
3+
4+
# Third party imports
15
import pytest
6+
7+
# Local application imports
28
from app import app
3-
import time
49

510

611
@pytest.fixture

tests/polygon_attribute.vtp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0"?>
2+
<VTKFile type="PolyData" version="1.0" byte_order="LittleEndian" header_type="UInt32" compressor="vtkZLibDataCompressor">
3+
<PolyData>
4+
<Piece NumberOfPoints="14" NumberOfPolys="14">
5+
<PointData>
6+
<DataArray type="Float64" Name="geode_implicit_attribute" format="ascii" NumberOfComponents="1" RangeMin="-5.03872538" RangeMax="2.56229305">-5.03873 -3.56819 -3.29213 -0.379219 0.386424 -1.97966 -0.310684 1.50807 1.80048 2.25409 2.56229 0.235826 -0.162775 -1.4339 </DataArray>
7+
<DataArray type="Float64" Name="points" format="ascii" NumberOfComponents="2" RangeMin="1.10000002" RangeMax="10">1.1 4.5 3 5 1.2 6 3 8 5 8.2 5 5.5 1.1 8.3 2 10 4 10 6 10 7 10 5.9 7.7 6.1 7 5.8 5.8 </DataArray>
8+
<DataArray type="Float64" Name="unique vertices" format="ascii" NumberOfComponents="1" RangeMin="32" RangeMax="45">32 33 36 37 42 34 38 39 40 41 43 44 45 35 </DataArray>
9+
<DataArray type="Float64" Name="gradient_3d_attribute" format="ascii" NumberOfComponents="3" RangeMin="0" RangeMax="1.2239517">0.441452 1.06497 0 0.509268 1.09401 0 0.451134 1.22395 0 0.244789 1.03019 0 0.306431 0.898241 0 0.520398 0.854144 0 0.0558145 0.936744 0 0.17577 1.03026 0 0.179188 0.94981 0 0.242737 0.863881 0 0.312089 0.886676 0 0.328556 0.855054 0 nan nan nan 0.353402 0.897993 0 </DataArray>
10+
</PointData>
11+
<Points>
12+
<DataArray type="Float64" Name="Points" format="ascii" NumberOfComponents="3" RangeMin="1.1000000000000001" RangeMax="10">1.1 4.5 0 3 5 0 1.2 6 0 3 8 0 5 8.2 0 5 5.5 0 1.1 8.3 0 2 10 0 4 10 0 6 10 0 7 10 0 5.9 7.7 0 6.1 7 0 5.8 5.8 0 </DataArray>
13+
</Points>
14+
<CellData>
15+
<DataArray type="Float64" Name="triangle_vertices" format="ascii" NumberOfComponents="3" RangeMin="0" RangeMax="13">0 1 2 1 3 2 1 4 3 1 5 4 2 3 6 3 7 6 3 8 7 3 4 8 4 9 8 4 10 9 4 11 10 4 12 11 5 12 4 5 13 12 </DataArray>
16+
<DataArray type="Float64" Name="triangle_adjacents" format="ascii" NumberOfComponents="3" RangeMin="0" RangeMax="4.2949673e+09">4.29497e+09 1 4.29497e+09 2 4 0 3 7 1 4.29497e+09 12 2 1 5 4.29497e+09 6 4.29497e+09 4 7 4.29497e+09 5 2 8 6 9 4.29497e+09 7 10 4.29497e+09 8 11 4.29497e+09 9 12 4.29497e+09 10 13 11 3 4.29497e+09 4.29497e+09 12 </DataArray>
17+
<DataArray type="Float64" Name="implicit_on_polygons" format="ascii" NumberOfComponents="1" RangeMin="-3.96634865" RangeMax="1.73426831">-3.96635 -2.41318 -1.18699 -1.72048 -1.32735 0.272721 0.976443 0.602562 1.48033 1.73427 1.06151 0.153159 -0.585337 -1.19211 </DataArray>
18+
</CellData>
19+
<Polys>
20+
<DataArray type="Int64" Name="connectivity" format="ascii" RangeMin="0" RangeMax="13">0 1 2 1 3 2 1 4 3 1 5 4 2 3 6 3 7 6 3 8 7 3 4 8 4 9 8 4 10 9 4 11 10 4 12 11 5 12 4 5 13 12 </DataArray>
21+
<DataArray type="Int64" Name="offsets" format="ascii" RangeMin="0" RangeMax="14">3 6 9 12 15 18 21 24 27 30 33 36 39 42 </DataArray>
22+
</Polys>
23+
</Piece>
24+
</PolyData>
25+
</VTKFile>

0 commit comments

Comments
 (0)