source: subversion/applications/rendering/toposm/import_planet @ 34399

Last change on this file since 34399 was 23114, checked in by ahlzen, 9 years ago

Work on highway shields. Minor style fixes.

  • Property svn:executable set to *
File size: 5.8 KB
Line 
1#!/bin/bash
2
3# Imports one or more planet dumps (*.osm.bz2, *.osm) or
4# planet diffs (*.osc.gz, *.osc).
5
6if [[ -z $TOPOSM_ENV_SET ]]; then
7    echo "Error: TopOSM environment not set."
8    exit 1
9fi
10
11#if [ -z "$1" ]; then
12#    echo "Syntax: import_planet <file> [<file> ...]"
13#    exit 2
14#fi
15
16
17DBCMD="psql -q -p $DB_PORT $DB_NAME $DB_USER"
18
19# Import data files.
20while [ $# -gt 0 ]; do
21    SRCFILE="$1"
22   
23    # Find out whether to append to or create a new database.
24    OPERATOR=""
25    CAT=""
26    case "$SRCFILE"
27    in
28        *.osm.bz2 | *.osm)
29            echo "Importing planet dump $SRCFILE..."
30            OPERATOR="-c" # (re)create tables
31            CAT="bzcat"
32                ;;
33            *.osc.gz | *.osc)
34                echo "Applying diff $SRCFILE..."
35                OPERATOR="-a" # append
36                CAT="zcat"
37                ;;
38            *)
39                echo "Unknown file type: $SRCFILE"
40                exit 1
41                ;;
42        esac
43       
44    # Make sure that the file exists.
45        if [ ! -f "$SRCFILE" ]; then
46            echo "File not found: $SRCFILE"
47            exit 2
48        fi
49
50    # Import the file.
51        $CAT "$SRCFILE" | \
52        sed "s/v=\"coastline\"/v=\"cXline\"/g" | \
53        osm2pgsql -m $OPERATOR --bbox "$EXTENTS_LATLON" \
54          --style "$OSM2PGSQL_STYLE_FILE" -P $DB_PORT -d "$DB_NAME" \
55          -U "$DB_USER" --prefix "$DB_PREFIX" \
56          --slim -C 2000 -     
57
58        shift
59done
60
61# Rename coastline tags back.
62for SUFFIX in line point polygon roads; do
63    echo "Renaming coastlines in ${DB_PREFIX}_${SUFFIX}..."
64    echo "UPDATE ${DB_PREFIX}_${SUFFIX} SET \"natural\"='coastline' WHERE \"natural\"='cXline'" | $DBCMD
65done
66
67
68
69# Extract road/route numbers from the 'ref' or 'name' tags.
70
71# TODO: This fails if columns exist. Not a problem, but should be
72# handled more gracefully.
73# NOTE: We're updating both *roads and *lines tables, since *roads doesn't
74# contain all road classes.
75echo "Adding road number/type columns..."
76echo "ALTER TABLE ${DB_PREFIX}_roads ADD COLUMN roadnumber VARCHAR(10);" | $DBCMD
77echo "ALTER TABLE ${DB_PREFIX}_line  ADD COLUMN roadnumber VARCHAR(10);" | $DBCMD
78echo "ALTER TABLE ${DB_PREFIX}_roads ADD COLUMN roadtype CHAR(1);" | $DBCMD
79echo "ALTER TABLE ${DB_PREFIX}_line  ADD COLUMN roadtype CHAR(1);" | $DBCMD
80
81echo "Extracting road numbers..."
82echo "UPDATE ${DB_PREFIX}_roads SET roadtype = NULL, roadnumber = NULL" | $DBCMD
83echo "UPDATE ${DB_PREFIX}_line  SET roadtype = NULL, roadnumber = NULL" | $DBCMD
84# Interstates
85echo "UPDATE ${DB_PREFIX}_roads SET roadtype = 'I', roadnumber = SUBSTRING(ref FROM 'I[ -]([0-9]+)') WHERE (highway = 'motorway' OR highway = 'trunk') AND (ref LIKE 'I %' OR ref LIKE 'I-%')" | $DBCMD
86echo "UPDATE ${DB_PREFIX}_line  SET roadtype = 'I', roadnumber = SUBSTRING(ref FROM 'I[ -]([0-9]+)') WHERE (highway = 'motorway' OR highway = 'trunk') AND (ref LIKE 'I %' OR ref LIKE 'I-%')" | $DBCMD
87# US routes
88echo "UPDATE ${DB_PREFIX}_roads SET roadtype = 'U', roadnumber = SUBSTRING(ref FROM 'US ([0-9A-Z]+)') WHERE (highway <> '' AND highway IS NOT NULL) AND ref LIKE 'US %'" | $DBCMD
89echo "UPDATE ${DB_PREFIX}_line  SET roadtype = 'U', roadnumber = SUBSTRING(ref FROM 'US ([0-9A-Z]+)') WHERE (highway <> '' AND highway IS NOT NULL) AND ref LIKE 'US %'" | $DBCMD
90# State routes
91echo "UPDATE ${DB_PREFIX}_roads SET roadtype = 'S', roadnumber = SUBSTRING(ref FROM 'SR ([0-9A-Z]+)') WHERE (highway <> '' AND highway IS NOT NULL) AND ref LIKE 'SR %'" | $DBCMD
92echo "UPDATE ${DB_PREFIX}_line  SET roadtype = 'S', roadnumber = SUBSTRING(ref FROM 'SR ([0-9A-Z]+)') WHERE (highway <> '' AND highway IS NOT NULL) AND ref LIKE 'SR %'" | $DBCMD
93echo "UPDATE ${DB_PREFIX}_roads SET roadtype = 'S', roadnumber = SUBSTRING(name FROM 'State Highway ([0-9A-Z]+)') WHERE (highway <> '' AND highway IS NOT NULL) AND name LIKE 'State Highway %'" | $DBCMD
94echo "UPDATE ${DB_PREFIX}_line  SET roadtype = 'S', roadnumber = SUBSTRING(name FROM 'State Highway ([0-9A-Z]+)') WHERE (highway <> '' AND highway IS NOT NULL) AND name LIKE 'State Highway %'" | $DBCMD
95echo "UPDATE ${DB_PREFIX}_roads SET roadtype = 'S', roadnumber = SUBSTRING(ref FROM '[A-Z] ([0-9A-Z-]+)') WHERE ref SIMILAR TO '[A-Z] [0-9-]%' AND ref NOT LIKE 'I %' AND highway IN ('motorway', 'trunk', 'primary', 'secondary', 'tertiary')" | $DBCMD
96echo "UPDATE ${DB_PREFIX}_line  SET roadtype = 'S', roadnumber = SUBSTRING(ref FROM '[A-Z] ([0-9A-Z-]+)') WHERE ref SIMILAR TO '[A-Z] [0-9-]%' AND ref NOT LIKE 'I %' AND highway IN ('motorway', 'trunk', 'primary', 'secondary', 'tertiary')" | $DBCMD
97echo "UPDATE ${DB_PREFIX}_roads SET roadtype = 'S', roadnumber = SUBSTRING(ref FROM '[A-Z]-([0-9A-Z-]+)') WHERE ref SIMILAR TO '[A-Z]-[0-9-]%' AND ref NOT LIKE 'I-%' AND highway IN ('motorway', 'trunk', 'primary', 'secondary', 'tertiary')" | $DBCMD
98echo "UPDATE ${DB_PREFIX}_line  SET roadtype = 'S', roadnumber = SUBSTRING(ref FROM '[A-Z]-([0-9A-Z-]+)') WHERE ref SIMILAR TO '[A-Z]-[0-9-]%' AND ref NOT LIKE 'I-%' AND highway IN ('motorway', 'trunk', 'primary', 'secondary', 'tertiary')" | $DBCMD
99echo "UPDATE ${DB_PREFIX}_roads SET roadtype = 'S', roadnumber = SUBSTRING(ref FROM '[A-Z][A-Z] ([0-9A-Z-]+)') WHERE ref SIMILAR TO '[A-Z][A-Z] [0-9-]%' AND ref NOT LIKE 'US %' AND highway IN ('motorway', 'trunk', 'primary', 'secondary', 'tertiary')" | $DBCMD
100echo "UPDATE ${DB_PREFIX}_line  SET roadtype = 'S', roadnumber = SUBSTRING(ref FROM '[A-Z][A-Z] ([0-9A-Z-]+)') WHERE ref SIMILAR TO '[A-Z][A-Z] [0-9-]%' AND ref NOT LIKE 'US %' AND highway IN ('motorway', 'trunk', 'primary', 'secondary', 'tertiary')" | $DBCMD
101echo "UPDATE ${DB_PREFIX}_roads SET roadtype = 'S', roadnumber = SUBSTRING(ref FROM '[A-Z][A-Z]-([0-9A-Z-]+)') WHERE ref SIMILAR TO '[A-Z][A-Z]-[0-9-]%' AND ref NOT LIKE 'US-%' AND highway IN ('motorway', 'trunk', 'primary', 'secondary', 'tertiary')" | $DBCMD
102echo "UPDATE ${DB_PREFIX}_line  SET roadtype = 'S', roadnumber = SUBSTRING(ref FROM '[A-Z][A-Z]-([0-9A-Z-]+)') WHERE ref SIMILAR TO '[A-Z][A-Z]-[0-9-]%' AND ref NOT LIKE 'US-%' AND highway IN ('motorway', 'trunk', 'primary', 'secondary', 'tertiary')" | $DBCMD
103
Note: See TracBrowser for help on using the repository browser.