Skip to content

Commit e50f3ff

Browse files
feat(polygon attribute): new route/schemas/test/data
1 parent c8142ad commit e50f3ff

File tree

4 files changed

+96
-1
lines changed

4 files changed

+96
-1
lines changed

src/opengeodeweb_back/routes/blueprint_routes.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ def vertex_attribute_names():
321321
file_absolute_path = os.path.join(UPLOAD_FOLDER, werkzeug.utils.secure_filename(flask.request.json["filename"]))
322322
data = geode_functions.load(flask.request.json["input_geode_object"], file_absolute_path)
323323
vertex_attribute_names = data.vertex_attribute_manager().attribute_names()
324-
print(f"vertex_attribute_names: {vertex_attribute_names}", flush=True)
324+
325325
return flask.make_response(
326326
{
327327
"vertex_attribute_names": vertex_attribute_names,
@@ -330,6 +330,33 @@ def vertex_attribute_names():
330330
)
331331

332332

333+
334+
with open(
335+
os.path.join(schemas, "polygon_attribute_names.json"),
336+
"r",
337+
) as file:
338+
polygon_attribute_names_json = json.load(file)
339+
340+
@routes.route(
341+
polygon_attribute_names_json["route"],
342+
methods=polygon_attribute_names_json["methods"],
343+
)
344+
def polygon_attribute_names():
345+
346+
UPLOAD_FOLDER = flask.current_app.config["UPLOAD_FOLDER"]
347+
utils_functions.validate_request(flask.request, vertex_attribute_names_json)
348+
file_absolute_path = os.path.join(UPLOAD_FOLDER, werkzeug.utils.secure_filename(flask.request.json["filename"]))
349+
data = geode_functions.load(flask.request.json["input_geode_object"], file_absolute_path)
350+
polygon_attribute_names = data.polygon_attribute_manager().attribute_names()
351+
352+
return flask.make_response(
353+
{
354+
"polygon_attribute_names": polygon_attribute_names,
355+
},
356+
200,
357+
)
358+
359+
333360
with open(
334361
os.path.join(schemas, "ping.json"),
335362
"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+
}

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>

tests/test_routes.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,34 @@ def get_full_data():
185185
test_utils.test_route_wrong_params(client, route, get_full_data)
186186

187187

188+
189+
def test_polygon_attribute_names(client):
190+
response = client.put(
191+
f"/upload_file",
192+
data={"file": FileStorage(open("./tests/polygon_attribute.vtp", "rb"))},
193+
)
194+
assert response.status_code == 201
195+
196+
route = f"/polygon_attribute_names"
197+
198+
def get_full_data():
199+
return {
200+
"input_geode_object": "PolygonalSurface3D",
201+
"filename": "polygon_attribute.vtp",
202+
}
203+
204+
# Normal test with filename 'vertex_attribute.vtp'
205+
response = client.post(route, json=get_full_data())
206+
assert response.status_code == 200
207+
polygon_attribute_names = response.json["polygon_attribute_names"]
208+
assert type(polygon_attribute_names) is list
209+
for polygon_attribute_name in polygon_attribute_names:
210+
assert type(polygon_attribute_name) is str
211+
212+
# Test all params
213+
test_utils.test_route_wrong_params(client, route, get_full_data)
214+
215+
188216
def test_create_point(client):
189217
route = f"/create_point"
190218
get_full_data = lambda: {"x": 1, "y": 2, "z": 3}

0 commit comments

Comments
 (0)