Skip to content

Commit 7cb8a4d

Browse files
WIP
1 parent f8f03fa commit 7cb8a4d

File tree

6 files changed

+48
-85
lines changed

6 files changed

+48
-85
lines changed

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ data: data/hiking-trails.geojson \
203203
data/hiking-trails-eisacktal.geojson \
204204
data/hiking-trails-pustertal.geojson \
205205
data/hiking-trails-salten-schlern.geojson \
206+
data/hiking-trails-unterland.geojson \
206207
data/mtb-tours.json \
207208
data/bicycle-lanes.json \
208209
data/ski-pistes.json \
@@ -217,6 +218,9 @@ data/hiking-trails-%.geojson: downloadService/HikingTrails.geojson data/%.extent
217218
$(RM) $@
218219
$(OGR2_BASE) -spat $(file < data/$*.extent) -nlt LINESTRING $@ $<
219220

221+
# write extent files with:
222+
# scripts/check_routes_order.py -a 6536736 --write-areas-bbox data/unterland.extent
223+
220224
# get SkiPistes manually from http://geokatalog.buergernetz.bz.it/geokatalog/
221225
# use this as data layer in JOSM
222226
data/ski-pistes.json: downloadService/dataset/SkiPistes_polygon.shp

areas.unterland.args

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
--areas
2+
6536736 # Überetsch-Unterland
3+
47207 # Bozen
4+
5+
--geokatalog
6+
data/hiking-trails-unterland.geojson
7+
8+
--osm-ignore
9+
3182798 # Boymont
10+
2172730 # Katzenleiter
11+
1524702 # O500
12+
7077998 # O502A
13+
6899726 # SI C06
14+
10551322 # Weinlehrpfad (Sallegg)
15+
16+
--gk-warn
17+
502
18+
513
19+
Trimm dich Pfad

scripts/check_routes_order.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def check_osmc_symbol (rtags, errors):
4848
if m:
4949
rx = '^red:red:white_bar:%s:black$' % m.group (1)
5050

51-
m = re.match (r'E([0-9]{3}[ABC]?)$', ref) # Trentino Est
51+
m = re.match (r'(?:E|O)([0-9]{3}[ABC]?)$', ref) # Trentino Est / Ovest
5252
if m:
5353
rx = '^red:red:white_stripe:%s:black$' % m.group (1)
5454

@@ -346,15 +346,15 @@ def build_parser ():
346346
parser.add_argument ('-g', '--geokatalog', nargs='*',
347347
metavar='path/to/geokatalog.geojson',
348348
help="load geokatalog geojson file")
349-
parser.add_argument ('--osm-ignore', nargs='*', type=int, dest='osm_ignore',
349+
parser.add_argument ('--osm-ignore', nargs="*", type=int, dest='osm_ignore', action='extend',
350350
metavar='OSM_RELID',
351351
default = [],
352352
help="ignore these OSM routes")
353-
parser.add_argument ('--osm-warn', nargs='*', type=int, dest='osm_warn',
353+
parser.add_argument ('--osm-warn', nargs='*', type=int, dest='osm_warn', action='extend',
354354
metavar='OSM_RELID',
355355
default = [],
356356
help="convert errors into warnings for these OSM routes")
357-
parser.add_argument ('--gk-warn', nargs='*', dest='gk_warn',
357+
parser.add_argument ('--gk-warn', nargs='*', dest='gk_warn', action='extend',
358358
metavar='GEOKATALOG_ID',
359359
default = [],
360360
help="convert errors into warnings for these geokatalog routes")
@@ -435,7 +435,7 @@ def osm_route_key (i):
435435
and rtags['type'] == 'route' # not abandoned etc.
436436
and route in connect.HIKING_TYPES
437437
and 'buffered' in osm_route
438-
and not re.match (r'E|SI|VA', rtags.get ('ref', ''))
438+
and not re.match (r'E|O|SI|VA', rtags.get ('ref', ''))
439439
and not 'via_ferrata_scale' in rtags
440440
and not rtags.get ('hiking') == 'via_ferrata'):
441441

scripts/connect.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from multiprocessing import Pool
1010

1111
import requests
12-
import osmapi
12+
# import osmapi
1313

1414
import shapely.ops
1515
from shapely.geometry import MultiLineString, LineString, MultiPoint, Point, MultiPolygon, Polygon, LinearRing, box
@@ -21,10 +21,6 @@
2121

2222
MY_UID = 8199540
2323

24-
BOUNDARY_ST = (
25-
47046, # South Tyrol
26-
)
27-
2824
CHUNKS = {
2925
934999 : 2, # Hike: "Sentiero Europeo E5, Italia", Gap @ Bolzano
3026
959876 : 2, # Road: LS64 Gap @ Kastelruth
@@ -39,6 +35,8 @@
3935
CHECKED_TYPES = HIKING_TYPES + ('bicycle', 'mtb', 'piste', 'ski', 'bus', 'road')
4036
""" Route types we check. """
4137

38+
DISUSED_TYPES = ('disused', 'abandoned', 'rased')
39+
4240

4341
# Transform a string so that numbers in the string sort naturally.
4442
#
@@ -53,6 +51,17 @@ def f (m):
5351
return str (len (s)) + s
5452
return re.sub ('\d+', f, s)
5553

54+
WAY_TAGS = set ((
55+
'highway',
56+
'disused:highway',
57+
'abandoned:highway',
58+
'demolished:highway',
59+
'removed:highway',
60+
'razed:highway',
61+
'railway',
62+
'aerialway',
63+
'piste:type',
64+
))
5665

5766
def way_is_way (way, clip_exceptions = False):
5867
# only consider these kinds of ways
@@ -61,11 +70,7 @@ def way_is_way (way, clip_exceptions = False):
6170
if clip_exceptions and 'geokatalog:exception' in wtags:
6271
return False
6372

64-
return wtags and ('highway' in wtags or
65-
'razed:highway' in wtags or
66-
'railway' in wtags or
67-
'aerialway' in wtags or
68-
'piste:type' in wtags)
73+
return wtags and WAY_TAGS.intersection (wtags.keys ())
6974

7075

7176
def way_is_area (way):
@@ -223,9 +228,7 @@ def relation_full (rel_id):
223228

224229
def init ():
225230
connect.log = logging.getLogger ().log
226-
connect.api = osmapi.OsmApi (passwordfile = Path ("~/.osmpass").expanduser ())
227231

228-
# area_ids = BOUNDARY_ST + tuple (sys.args.areas)
229232
area_ids = tuple (sys.args.areas)
230233
with Pool () as p:
231234
polys = list (tqdm (
@@ -235,5 +238,4 @@ def init ():
235238
))
236239

237240
polys = [p for sublist in polys for p in sublist] # flatten list of lists
238-
# connect.boundary_south_tyrol = polys.pop (0)
239241
connect.boundary = shapely.ops.unary_union (polys)

scripts/geokatalog.py

Lines changed: 1 addition & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@
4949
matched = 0
5050

5151
BUFFER = 100.0
52-
# RESAMPLE = 100.0
5352

5453
# SRS_BZIT = EPSG:25832 # ETRS89 / UTM zone 32N used by provinz.bz.it
5554
# SRS_WGS = EPSG:4326 # WGS84
@@ -60,69 +59,6 @@
6059
transformer = Transformer.from_crs ("EPSG:4326", "EPSG:25832", always_xy = True)
6160
itransformer = Transformer.from_crs ("EPSG:25832", "EPSG:4326", always_xy = True)
6261

63-
# def dist (a, b):
64-
# """ Since we are using UTM we can use a simple euclidean distance. """
65-
# return math.sqrt ((b[0] - a[0]) ** 2 + (b[1] - a[1]) ** 2)
66-
67-
68-
# def _distance (coords1, coords2):
69-
# """ Return Hausdorff distance in m """
70-
71-
# hd1 = scipy.spatial.distance.directed_hausdorff (coords1, coords2)
72-
73-
# # hd2 = scipy.spatial.distance.directed_hausdorff (coords2, coords1)
74-
# # hd = max (hd1[0], hd2[0])
75-
76-
# a = coords1[hd1[1]]
77-
# b = coords2[hd1[2]]
78-
# return dist (a, b)
79-
80-
81-
# def coords (geom):
82-
# if geom.is_empty:
83-
# return []
84-
# if geom.type in ('LineString', 'LinearRing'):
85-
# return geom.coords
86-
# if geom.type.startswith ('Multi') or geom.type == 'GeometryCollection':
87-
# return [c for l in geom for c in l.coords ]
88-
# return []
89-
90-
91-
# def resample (geom, threshold):
92-
# """Resample the linestrings in geometry.
93-
94-
# After resampling the distance between consecutive points in a linestring
95-
# will be no longer than threshold.
96-
97-
# """
98-
99-
# if geom.is_empty:
100-
# return geom
101-
102-
# if geom.type in ('LineString', 'LinearRing'):
103-
# pts = []
104-
# last_pt = geom.coords[0]
105-
106-
# for pt in geom.coords:
107-
# d = dist (pt, last_pt)
108-
# if d > threshold:
109-
# # add some points in between
110-
# long_line = LineString ([last_pt, pt])
111-
# i = threshold
112-
# while i <= d:
113-
# pts.append (long_line.interpolate (i))
114-
# i += threshold
115-
# pts.append (pt)
116-
# last_pt = pt
117-
118-
# return type (geom) (pts)
119-
120-
# elif geom.type.startswith ('Multi') or geom.type == 'GeometryCollection':
121-
# return type (geom) ([ resample (part, threshold) for part in geom.geoms])
122-
123-
# return geom
124-
125-
12662
gk_routes = dict ()
12763
osm_routes = dict ()
12864
gk_routes_by_id = dict () # needed for STRtree
@@ -154,7 +90,7 @@ def match_route (rtags, gk_props):
15490
return True
15591

15692
# special case for CAI Trentino Est
157-
m = re.match (r'^E(\d\d\d)$', ref)
93+
m = re.match (r'^(?:E|O)([0-9]{3}[ABC]?)$', ref)
15894
if m and gk_ref == m.group (1):
15995
return True
16096

@@ -186,15 +122,13 @@ def get_relation (osm_relation):
186122

187123
geom = connect.osm_relation_as_multilinestring (rfull)
188124
geom = shapely.ops.transform (transformer.transform, geom)
189-
# geom = resample (geom, RESAMPLE)
190125

191126
res['geometry'] = geom
192127
res['geometry'].id = rel_id
193128

194129
clipped = connect.osm_relation_as_multilinestring (rfull, True)
195130
clipped = shapely.ops.transform (transformer.transform, clipped)
196131

197-
# clipped = resample (clipped, RESAMPLE)
198132
clipped = clip_area (clipped)
199133

200134
if not clipped.is_empty:

scripts/requirements.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
pyproj
2+
requests
3+
shapely
4+
tqdm

0 commit comments

Comments
 (0)