Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Dynamic Exposure
OpenBuildingMap
rabotnik-obm
Commits
08f9effb
Commit
08f9effb
authored
Sep 17, 2021
by
Marius Kriegerowski
Browse files
Changed to return results from rules instead of async yielding
parent
b0b010cd
Pipeline
#27986
passed with stage
in 2 minutes and 19 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
rabotnikobm/rules/get_building_land_use.py
View file @
08f9effb
...
...
@@ -16,7 +16,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see http://www.gnu.org/licenses/.
import
logging
from
typing
import
Tuple
,
Iterator
from
typing
import
Optional
from
rabotnik
import
Rule
...
...
@@ -25,21 +25,23 @@ logger = logging.getLogger(__name__)
class
GetBuildingLandUse
(
Rule
):
"""A rule to get the land use of a building."""
"""A rule to get the land use of a building. If more than one land
use is found, returns None."""
def
__init__
(
self
,
storage
):
self
.
storage
=
storage
async
def
evaluate
(
self
,
payload
:
dict
)
->
Iterator
[
Tuple
[
int
]
]:
async
def
evaluate
(
self
,
payload
:
dict
)
->
Optional
[
str
]:
building_id
=
payload
[
"building_id"
]
logger
.
debug
(
"evaluating %s"
,
building_id
)
async
for
land_use
in
self
.
storage
.
iter_results
(
land_use
=
await
self
.
storage
.
expect_one
(
f
"""SELECT land.class
FROM osm_building_relations AS building, osm_lands AS land
WHERE
{
building_id
}
= building.id
AND ST_INTERSECTS(land.geometry, building.geometry);
"""
)
:
)
yield
land_use
logger
.
info
(
"Land use of %s: %s"
,
building_id
,
land_use
)
return
land_use
rabotnikobm/rules/get_floorspace.py
View file @
08f9effb
...
...
@@ -47,4 +47,9 @@ class GetFloorspace(Rule):
"""
floorspace
=
await
self
.
storage
.
expect_one
(
query_floorspace
)
logger
.
info
(
"building %s floorspace: %s."
,
building_id
,
floorspace
)
if
floorspace
is
None
:
return
await
upsert
(
self
.
storage_target
,
building_id
,
floorspace
)
rabotnikobm/rules/get_points_in_building.py
View file @
08f9effb
...
...
@@ -16,7 +16,6 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see http://www.gnu.org/licenses/.
import
logging
from
typing
import
Tuple
,
Iterator
from
rabotnik
import
Rule
...
...
@@ -29,10 +28,11 @@ class GetPointsInBuilding(Rule):
def
__init__
(
self
,
storage
):
self
.
storage
=
storage
async
def
evaluate
(
self
,
payload
:
dict
)
->
Iterator
[
Tuple
[
int
]]
:
async
def
evaluate
(
self
,
payload
:
dict
)
->
int
:
building_id
=
payload
[
"building_id"
]
logger
.
debug
(
"evaluating %s"
,
building_id
)
n_points_total
=
0
async
for
n_points
,
_
in
self
.
storage
.
iter_results
(
f
"""SELECT COUNT(ST_NPOINTS(spots.geometry)), buildings.osm_id
FROM OSM_SPOTS as spots, OSM_Building_polygons as buildings
...
...
@@ -42,4 +42,6 @@ class GetPointsInBuilding(Rule):
"""
):
yield
n_points
n_points_total
+=
n_points
return
n_points_total
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment