-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_data_pgis_rect
More file actions
executable file
·161 lines (131 loc) · 5.49 KB
/
Copy pathget_data_pgis_rect
File metadata and controls
executable file
·161 lines (131 loc) · 5.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#!/usr/bin/env bash
MARGIN_LAT_SIZE=0.05
MARGIN_LON_SIZE=0.15
LON_START=$1
LAT_START=$2
LON_END=$3
LAT_END=$4
LON_START=$(bc -l <<< "$LON_START-($LON_END - $LON_START)*$MARGIN_LON_SIZE")
LAT_START=$(bc -l <<< "$LAT_START-($LAT_END - $LAT_START)*$MARGIN_LAT_SIZE")
LON_END=$(bc -l <<< "$LON_END + ($LON_END - $LON_START)*$MARGIN_LON_SIZE")
LAT_END=$(bc -l <<< "$LAT_END + ($LAT_END - $LAT_START)*$MARGIN_LAT_SIZE")
function download {
OVERPASS_SERVERS=( "http://overpass-api.de/api" "http://overpass.osm.rambler.ru/cgi" )
OVERPASS_SERVERS_COUNT=${#OVERPASS_SERVERS[@]}
DB=gis_eu
LAT_STEP=2
LON_STEP=2
LAT_STEP2=$(python <<< "print ($LAT_END - $LAT_START)*(1+2*$MARGIN_LAT_SIZE)/$LAT_STEP")
LON_STEP2=$(python <<< "print ($LON_END - $LON_START)*(1+2*$MARGIN_LON_SIZE)/$LON_STEP")
i=0
str=""
#qs="${1}"
OLD_IFS=$IFS
IFS=''
qs="$1[*]"
qs=(${!qs})
IFS=$OLD_IFS
#echo $qs2
#qs=("raz" "dva" "tri" )
for qq in "${qs[@]}"; do
for i_lat_index in $(eval echo "{1..$LAT_STEP}"); do
i_lat=$(bc -l <<< "$LAT_START+($i_lat_index-1)*$LAT_STEP2")
echo $i_lat
lat_from=$i_lat
lat_to=$(python <<< "print min($LAT_END,$i_lat+$LAT_STEP2)")
for i_lon_index in $(eval echo "{1..$LON_STEP}"); do
i_lon=$(bc -l <<< "$LON_START+($i_lon_index-1)*$LON_STEP2")
echo $i_lon
lon_from=$i_lon
lon_to=$(python <<< "print min($LON_END,$i_lon+$LON_STEP2)")
q=${qq//%lon1%/$lon_from}
q=${q//%lon2%/$lon_to}
q=${q//%lat1%/$lat_from}
q=${q//%lat2%/$lat_to}
i=$(($i+1))
server=${OVERPASS_SERVERS[$(($i % $OVERPASS_SERVERS_COUNT))]}
wget -T 86400 -O - "$server/interpreter?data=[timeout:86400];$q;out;" | /home/klinger/mymap/osm/osmconvert - --out-o5m > "/tmp/~$2.$i_lon.$i_lat.o5m"
while [ $? -ne 0 ]; do
i=$(($i+1))
server=${OVERPASS_SERVERS[$(($i % $OVERPASS_SERVERS_COUNT))]}
wget -T 86400 -O - "$server/interpreter?data=[timeout:86400];$q;out;" | /home/klinger/mymap/osm/osmconvert - --out-o5m > "/tmp/~$2.$i_lon.$i_lat.o5m"
done
if [ -f "/tmp/$2.o5m" ]; then
/home/klinger/mymap/osm/osmconvert "/tmp/$2.o5m" "/tmp/~$2.$i_lon.$i_lat.o5m" --out-o5m > "/tmp/~$2.o5m"
FS1=$(stat -c%s "/tmp/~$2.$i_lon.$i_lat.o5m")
FS2=$(stat -c%s "/tmp/~$2.o5m")
if [ $FS1 -ge $FS2 ]; then
unlink "/tmp/~$2.o5m"
else
unlink "/tmp/$2.o5m"
mv "/tmp/~$2.o5m" "/tmp/$2.o5m"
fi
unlink "/tmp/~$2.$i_lon.$i_lat.o5m"
else
mv "/tmp/~$2.$i_lon.$i_lat.o5m" "/tmp/$2.o5m"
fi
done
done
done
/home/klinger/mymap/osm/osmconvert "/tmp/$2.o5m" --out-osm | bzip2 > "/tmp/$2.osm.bz2"
unlink "/tmp/$2.o5m"
case "$3" in
point)
echo "DROP TABLE $2; DROP INDEX $2_point_pkey,$2_point_index;" | psql -d $DB
;;
pointex)
echo "DROP TABLE $2; DROP INDEX $2_point_pkey,$2_point_index;" | psql -d $DB
;;
line)
echo "DROP TABLE $2; DROP INDEX $2_line_pkey,$2_line_index;" | psql -d $DB
;;
route)
echo "DROP TABLE $2; DROP INDEX $2_line_pkey,$2_line_index;" | psql -d $DB
;;
polygon)
echo "DROP TABLE $2; DROP INDEX $2_polygon_pkey,$2_polygon_index;" | psql -d $DB
;;
esac
/usr/local/bin/osm2pgsql \
-d $DB \
--style "/home/klinger/mymap/osm2pgsql/$2.style" \
--create \
--slim --cache 30 \
--prefix $2 \
/tmp/$2.osm.bz2
unlink /tmp/$2.osm.bz2
case "$3" in
point)
echo "ALTER TABLE $2_point RENAME TO $2; DROP TABLE $2_polygon; DROP TABLE $2_line,$2_nodes,$2_rels,$2_roads,$2_ways;" | psql -d $DB
;;
pointex)
echo "CREATE TABLE $2 AS $4; DROP TABLE $2_point,$2_polygon,$2_line,$2_nodes,$2_rels,$2_roads,$2_ways; DROP TABLE $2_point,$2_polygon,$2_line,$2_nodes,$2_rels,$2_roads,$2_ways;" | psql -d $DB
;;
line)
echo "ALTER TABLE $2_line RENAME TO $2; DROP TABLE $2_polygon; DROP TABLE $2_point,$2_nodes,$2_rels,$2_roads,$2_ways;" | psql -d $DB
;;
route)
echo "ALTER TABLE $2_line RENAME TO $2; DROP TABLE $2_polygon;" | psql -d $DB
;;
polygon)
echo "ALTER TABLE $2_polygon RENAME TO $2; DROP TABLE $2_line; DROP TABLE $2_point,$2_nodes,$2_rels,$2_roads,$2_ways;" | psql -d $DB
;;
esac
}
q=( "node(%lat1%,%lon1%,%lat2%,%lon2%)[place~\"city|town|village|hamlet|isolated_dwelling|farm|suburb|neighbourhood|locality|island|islet\"]" )
download q places point
q=(
"node(%lat1%,%lon1%,%lat2%,%lon2%)[historic]"
"node(%lat1%,%lon1%,%lat2%,%lon2%)[man_made]"
"node(%lat1%,%lon1%,%lat2%,%lon2%)[leisure]"
"node(%lat1%,%lon1%,%lat2%,%lon2%)[tourism]"
"node(%lat1%,%lon1%,%lat2%,%lon2%)[amenity]"
"node(%lat1%,%lon1%,%lat2%,%lon2%)[natural=\"cave_entrance\"]"
"(rel(%lat1%,%lon1%,%lat2%,%lon2%)[building~\"church|chapel\"];);(._;way(r););(._;node(w););(way(%lat1%,%lon1%,%lat2%,%lon2%)[building~\"church|chapel\"];);(._;node(w);)"
)
download q symbol pointex \
"SELECT osm_id,name,int_name,\"name:en\",\"name:de\",\"name:cs\",historic,leisure,man_made,tourism,amenity,ruins,castle_type,building,\"natural\",\"tower:type\",information,place_of_worship,\"place_of_worship:type\",z_order,way FROM symbol_point UNION SELECT osm_id,name,int_name,\"name:en\",\"name:de\",\"name:cs\",historic,leisure,man_made,tourism,amenity,ruins,castle_type,building,\"natural\",\"tower:type\",information,place_of_worship,\"place_of_worship:type\",z_order,ST_Centroid(way) AS way FROM symbol_polygon"
q=(
"(rel(%lat1%,%lon1%,%lat2%,%lon2%)[route~\"mtb|horse|ski|bicycle|horse|hiking|foot\"];);(._;way(r););(._;node(w);)"
)
#download q route route