Skip to content

Commit

Permalink
Landmark-Service v2 (#5)
Browse files Browse the repository at this point in the history
* fix faulty translations

* mention landmark first instead of last in gh instruction

* add blacklist

* first draft direction determination for landmark

* use threshold from request, if set

* save landmark meta data in gh response

* save osm tags for landmark for now

* add name to landmark model

* reduce threshold to 30m

* fix intervall index

* use blacklist for unhelpful osm tags

* add translations

* add translations

* add low priority tags

* remove redundant code

* sort osm-tags

* add low priority tags

* add translations

* add osm categories

* add new categories to low_priority and blacklist

* add new categories to low_priority and blacklist

* add query parameter to decide if graphhopper query should be replaced or extended

* polishing
  • Loading branch information
kruegercharles authored Jul 24, 2024
1 parent f1d0963 commit dd39a41
Show file tree
Hide file tree
Showing 6 changed files with 1,647 additions and 736 deletions.
84 changes: 51 additions & 33 deletions backend/pois/management/commands/import_landmarks.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,31 @@
"public_transport",
"man_made",
"railway",
"bridge", # => no results in Dresden
"sport",
"water", # => no results in Dresden
# additions
"aerialway",
"aeroway",
"barrier",
"craft",
"emergency",
"healthcare",
"landuse",
"miliary",
"power",
]

# OSM Tags that are not useful and therefore discarded
BLACKLIST = [
"Bahnübergang",
"Eisenbahnübergang",
"Gleisweiche",
"Straßenbahnübergang",
"Hydrant", # man könnte dabei eventuell noch unterscheiden nach "fire_hydrant:type",
"Randstein",
"Tor",
]
# Tags "Bahnübergang" und "Eisenbahnübergang" sind häufig nicht hilfreich, da man bei vielen Straßen parallel zu Bahnstrecke fährt


def build_overpass_query(bounding_box: str) -> str:
"""
Expand Down Expand Up @@ -94,45 +114,43 @@ def import_from_overpass(bounding_box: str):
# type = i.e. "Kino"
# category = i.e. "amenity" (the category used by openstreetmap/overpass)

# Preferentially use the name tag as type
# Always preferentially use the name tag as type
if "name" in element["tags"]:
type = element["tags"]["name"]
for category in OSM_CATEGORIES:
if category in element["tags"]:
category = translate_tag(category, "")
break

if not category:
category = "Landmarke"
name = element["tags"]["name"]
else:
for category in OSM_CATEGORIES:
if category in element["tags"]:
type = translate_tag(category, element["tags"][category])
category = translate_tag(category, "")
break

if not category or not type:
type = "Landmarke"
category = "Landmarke"

# Print debug message if no category was found
tags = ""
for key in element["tags"]:
tags += key + " = " + element["tags"][key] + ","
print(
"No category found for element with id",
str(element["id"]),
"and tags '" + tags + "' using default category",
)
name = ""

for category in OSM_CATEGORIES:
if category in element["tags"]:
type = translate_tag(category, element["tags"][category])
category = translate_tag(category, "")
break

if not category or not type:
type = "Landmarke"
category = "Landmarke"

# Print debug message if no category was found
tags = ""
for key in element["tags"]:
tags += key + " = " + element["tags"][key] + ","
print(
"No category found for element with id",
str(element["id"]),
"and tags '" + tags + "' using default category",
)

# TODO: I could also just discard the landmarks if I have no valid translation
if type in BLACKLIST:
continue

# Create a Landmark object
landmark = Landmark(
id=element["id"],
name=name,
coordinate=Point(element["lon"], element["lat"], srid=4326),
type=type,
category=category,
tags=json.dumps(element["tags"]),
)
landmark_points.append(landmark)

Expand Down Expand Up @@ -219,7 +237,7 @@ def handle(self, *args, **options):
global translation_table

# load translation table for osm tags
PATH = "backend/pois/openstreetbrowser-osm-tags-de.json"
PATH = "backend/pois/osm-tags-de.json"
with open(PATH, "r") as file:
translation_table = json.load(file)

Expand All @@ -242,4 +260,4 @@ def handle(self, *args, **options):
)

for category in unknown_tags:
print("Unknown OSM tags for translation:", category)
print(category)
24 changes: 24 additions & 0 deletions backend/pois/migrations/0004_landmark_tags_alter_landmark_id.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Generated by Django 4.2.13 on 2024-07-12 09:12

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('pois', '0003_landmark'),
]

operations = [
migrations.AddField(
model_name='landmark',
name='tags',
field=models.TextField(default='none'),
preserve_default=False,
),
migrations.AlterField(
model_name='landmark',
name='id',
field=models.TextField(primary_key=True, serialize=False),
),
]
19 changes: 19 additions & 0 deletions backend/pois/migrations/0005_landmark_name.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 4.2.13 on 2024-07-12 09:27

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('pois', '0004_landmark_tags_alter_landmark_id'),
]

operations = [
migrations.AddField(
model_name='landmark',
name='name',
field=models.TextField(default=''),
preserve_default=False,
),
]
7 changes: 7 additions & 0 deletions backend/pois/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,19 @@ class Landmark(models.Model):
# The unique identifier of the landmark, given by OSM.
id = models.TextField(primary_key=True)

# The name of the landmark, if available.
name = models.TextField()

# Landmark.
category = models.TextField()

# The kind of landmark.
type = models.TextField()

# The osm tags of the landmark.
# TODO: maybe remove later
tags = models.TextField()

# The coordinate of the point of interest.
coordinate = models.PointField(srid=settings.LONLAT, geography=True)

Expand Down
Loading

0 comments on commit dd39a41

Please sign in to comment.