Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
N
NLMaps Tools
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
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
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
Show more breadcrumbs
Simon Will
NLMaps Tools
Commits
a117e2bd
Commit
a117e2bd
authored
3 years ago
by
Simon Will
Browse files
Options
Downloads
Patches
Plain Diff
Add small demo script
parent
58157aeb
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
demo.py
+50
-0
50 additions, 0 deletions
demo.py
nlmaps_tools/answer_mrl.py
+0
-1
0 additions, 1 deletion
nlmaps_tools/answer_mrl.py
with
50 additions
and
1 deletion
demo.py
0 → 100644
+
50
−
0
View file @
a117e2bd
#!/usr/bin/env python3
from
nlmaps_tools.parse_mrl
import
MrlGrammar
,
Symbol
from
nlmaps_tools.answer_mrl
import
(
add_name_tags
,
canonicalize_nwr_features
,
ENV
as
overpass_ql_env
,
transform_features
)
MRL_IN
=
"
query(area(keyval(
'
name
'
,
'
berlin
'
)),nwr(keyval(
'
diet:vegan
'
,or(
'
only
'
,
'
yes
'
)),keyval(
'
shop
'
,
'
*
'
),keyval(
'
wheelchair
'
,
'
yes
'
)),qtype(latlong))
"
MRL_AROUND
=
"
query(around(center(nwr(keyval(
'
name
'
,
'
Camp Nou
'
))),search(nwr(keyval(
'
amenity
'
,or(
'
cafe
'
,
'
restaurant
'
)))),maxdist(1000)),qtype(count))
"
MRL_DIST_CLOSEST
=
"
dist(query(area(keyval(
'
name
'
,
'
Michelfeld
'
)),nwr(keyval(
'
name
'
,
'
Churr
'
)),qtype(latlong)),query(area(keyval(
'
name
'
,
'
Michelfeld
'
)),nwr(keyval(
'
name
'
,
'
Hagenmueller
'
),keyval(
'
shop
'
,
'
hairdresser
'
)),qtype(latlong)))
"
MRL_DIST_BETWEEN
=
"
dist(query(nwr(keyval(
'
name
'
,
'
HL College of commerce
'
)),qtype(latlong)),query(nwr(keyval(
'
name
'
,
'
Tapan Hospital
'
)),qtype(latlong)))
"
def
main
():
mrl
=
MRL_AROUND
print
(
mrl
)
print
()
# Parse MRL
grammar
=
MrlGrammar
()
# (MRLs in the NLMaps datasets are actually never “escaped”. See
# MrlGrammar.parseMrl for what that means.)
parse_result
=
grammar
.
parseMrl
(
mrl
,
is_escaped
=
False
)
features
=
parse_result
[
'
features
'
]
print
(
features
)
print
()
# Add tags like int_name and alt_name
features
=
transform_features
(
features
,
add_name_tags
)
print
(
features
)
print
()
# Canonicalize features, i.e. dissolve “or” around values into “or” around
# tags.
features
=
transform_features
(
features
,
canonicalize_nwr_features
)
print
(
features
)
print
()
# Render as Overpass QL
# Does not work for MRL_DIST_*
# For the DIST_BETWEEN, use in_query.jinja2 for each of the two sub-query
# For the DIST_CLOSEST, use around_query.jinja2 for the one sub-query
template_name
=
features
[
'
query_type
'
]
+
'
.jinja2
'
template
=
overpass_ql_env
.
get_template
(
template_name
)
ql
=
template
.
render
(
features
=
features
)
print
(
ql
)
if
__name__
==
'
__main__
'
:
main
()
This diff is collapsed.
Click to expand it.
nlmaps_tools/answer_mrl.py
+
0
−
1
View file @
a117e2bd
...
...
@@ -10,7 +10,6 @@ from urllib.error import HTTPError
from
geopy.distance
import
geodesic
import
jinja2
from
OSMPythonTools.nominatim
import
Nominatim
from
OSMPythonTools.overpass
import
Overpass
from
nlmaps_tools.parse_mrl
import
MrlGrammar
,
Symbol
from
nlmaps_tools.overpass_round_robin
import
OverpassRoundRobin
...
...
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