Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
data-api-server
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Global Dynamic Exposure
OpenBuildingMap
data-api-server
Commits
c3023e57
Commit
c3023e57
authored
3 years ago
by
Felix Delattre
Browse files
Options
Downloads
Patches
Plain Diff
Added endpoint to query buildings by bounding box
parent
167f5275
No related branches found
No related tags found
1 merge request
!7
Added endpoint to query buildings by bounding box
Pipeline
#26427
passed
3 years ago
Stage: test
Changes
2
Pipelines
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
obmdataapi/__init__.py
+31
-3
31 additions, 3 deletions
obmdataapi/__init__.py
tests/test_obmdataapi.py
+2
-1
2 additions, 1 deletion
tests/test_obmdataapi.py
with
33 additions
and
4 deletions
obmdataapi/__init__.py
+
31
−
3
View file @
c3023e57
...
...
@@ -79,8 +79,36 @@ async def heartbeat() -> dict:
@app.api.add_function
async
def
get_building
(
osm_id
)
->
dict
:
building
=
await
app
.
db
.
fetch_
v
al
(
"
SELECT
osm_id
FROM osm_building_polygons WHERE osm_id = :osm_id
"
,
result
=
await
app
.
db
.
fetch_a
l
l
(
"
SELECT
*
FROM osm_building_polygons WHERE osm_id = :osm_id
"
,
values
=
{
"
osm_id
"
:
int
(
osm_id
)},
)
return
{
"
building
"
:
str
(
building
)}
values
=
{}
for
building
in
result
:
for
key
,
value
in
building
.
items
():
values
[
key
]
=
value
return
{
"
building
"
:
values
}
@app.api.add_function
async
def
get_buildings_by_bbox
(
xmin
,
ymin
,
xmax
,
ymax
)
->
dict
:
buildings
=
await
app
.
db
.
fetch_all
(
"
SELECT * FROM osm_building_polygons
\
WHERE geometry && ST_MakeEnvelope(:xmin, :ymin, :xmax, :ymax, 4326)
"
,
values
=
{
"
xmin
"
:
float
(
xmin
),
"
ymin
"
:
float
(
ymin
),
"
xmax
"
:
float
(
xmax
),
"
ymax
"
:
float
(
ymax
),
},
)
buildings_data_object
=
{}
for
building
in
buildings
:
osm_id
=
0
values
=
{}
for
key
,
value
in
building
.
items
():
values
[
key
]
=
value
if
key
==
"
osm_id
"
:
osm_id
=
value
buildings_data_object
[
osm_id
]
=
values
return
{
"
buildings
"
:
buildings_data_object
}
This diff is collapsed.
Click to expand it.
tests/test_obmdataapi.py
+
2
−
1
View file @
c3023e57
...
...
@@ -40,4 +40,5 @@ def test_heartbeat(client) -> None:
def
test_get_building
(
client
)
->
None
:
response
=
request
(
"
http://127.0.0.1:5000/v1
"
,
"
get_building
"
,
"
-12412416
"
).
data
.
result
assert
"
-12412416
"
in
response
[
"
building
"
]
print
(
response
[
"
building
"
][
"
osm_id
"
])
assert
-
12412416
==
response
[
"
building
"
][
"
osm_id
"
]
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment