Maxspeed Map für Mapserver&Postgres Besitzer
…oder ich bastel mir ein Overlay…
wget http://download.geofabrik.de/osm/europe.osm.pbf
osmosis --read-pbf europe.osm.pbf --tf accept-ways maxspeed=* maxspeed:forward=* maxspeed:backward=* --tf reject-relations --used-node --write-xml maxspeed.osm
sudo su postgres
createdb -E utf8 maxspeed
cat /usr/share/postgresql/9.0/contrib/postgis-1.5/postgis.sql | psql -d maxspeed
cat /usr/share/postgresql/9.0/contrib/postgis-1.5/spatial_ref_sys.sql | psql -d maxspeed
osm2pgsql -l -d maxspeed -p osm -s -S /usr/share/osm2pgsql/maxspeed.style -C 11000 maxspeed.osm
/usr/share/osm2pgsql/maxspeed.style ist
# OsmType Tag DataType Flags
way highway text linear
way maxspeed text linear
way maxspeed:forward text linear
way maxspeed:backward text linear
node,way z_order int4 linear # This is calculated during import
way way_area real # This is calculated during import
sudo su postgres
psql -d maxspeed
update osm_line set maxspeed = "maxspeed:forward" where "maxspeed:forward" is not null and maxspeed is null;
update osm_line set maxspeed = "maxspeed:backward" where "maxspeed:backward" is not null and maxspeed is null;
ALTER TABLE osm_line DROP COLUMN "maxspeed:forward";
ALTER TABLE osm_line DROP COLUMN "maxspeed:backward";
grant SELECT on osm_line to "www-data";
create index osm_line_highway_idx on osm_line(highway);
ALTER TABLE osm_line ADD COLUMN "speedclasss"
UPDATE osm_line set speedclass = '1' where to_number(maxspeed,'9999D99')>0 and to_number(maxspeed,'9999D99')<31 and textregexeq(maxspeed,'^[[:digit:]]+(\.[[:digit:]]+)?$')
UPDATE osm_line set speedclass = '2' where to_number(maxspeed,'9999D99')>30 and to_number(maxspeed,'9999D99')<61 and textregexeq(maxspeed,'^[[:digit:]]+(\.[[:digit:]]+)?$')
UPDATE osm_line set speedclass = '3' where to_number(maxspeed,'9999D99')>60 and to_number(maxspeed,'9999D99')<91 and textregexeq(maxspeed,'^[[:digit:]]+(\.[[:digit:]]+)?$')
UPDATE osm_line set speedclass = '4' where to_number(maxspeed,'9999D99')>90 and to_number(maxspeed,'9999D99')<121 and textregexeq(maxspeed,'^[[:digit:]]+(\.[[:digit:]]+)?$')
UPDATE osm_line set speedclass = '5' where (to_number(maxspeed,'9999D99')>120 and textregexeq(maxspeed,'^[[:digit:]]+(\.[[:digit:]]+)?$')) OR NOT textregexeq(maxspeed,'^[[:digit:]]+(\.[[:digit:]]+)?$')
danach legen wir die Rendering Regeln an, am besten da, wo die normale Mapfile ist, also bspw eine Datei maxspeed.map
LAYER
STATUS ON
GROUP "maxspeed"
PROJECTION
"init=epsg:4326"
END
CONNECTIONTYPE postgis
CONNECTION "host=localhost dbname=maxspeed user=www-data password=www-data port=5432"
PROCESSING "CLOSE_CONNECTION=DEFER"
maxscaledenom 54180
minscaledenom 0
TYPE LINE
NAME "maxspeedclosebunt"
DATA "way from (select way, osm_id ,highway,speedclass from osm_line where (highway in ('motorway','motorway_link','trunk','trunk_link','primary','primary_link','secondary','secondary_link','tertiary','unclassified','residential') and maxspeed is not null) order by z_order) as foo using unique osm_id using srid=4326"
CLASSITEM "speedclass"
CLASS
EXPRESSION "1"
STYLE
WIDTH 3
COLOR 0 255 0
END
END
CLASS
EXPRESSION "2"
STYLE
WIDTH 3
COLOR 255 240 0
END
END
CLASS
EXPRESSION "3"
STYLE
WIDTH 3
COLOR 255 136 0
END
END
CLASS
EXPRESSION "4"
STYLE
WIDTH 3
COLOR 255 0 0
END
END
CLASS
EXPRESSION "5"
STYLE
WIDTH 3
COLOR 0 0 0
END
END
END
LAYER
STATUS ON
GROUP "maxspeed"
PROJECTION
"init=epsg:4326"
END
CONNECTIONTYPE postgis
CONNECTION "host=localhost dbname=maxspeed user=www-data password=www-data port=5432"
PROCESSING "CLOSE_CONNECTION=DEFER"
maxscaledenom 1743443
minscaledenom 54180
TYPE LINE
NAME "maxspeedfarbunt"
DATA "way from (select way, osm_id ,highway,speedclass from osm_line where (highway in ('motorway','trunk','primary') and maxspeed is not null) order by z_order) as foo using unique osm_id using srid=4326"
CLASSITEM "speedclass"
CLASS
EXPRESSION "1"
STYLE
WIDTH 3
COLOR 0 255 0
END
END
CLASS
EXPRESSION "2"
STYLE
WIDTH 3
COLOR 255 255 0
END
END
CLASS
EXPRESSION "3"
STYLE
WIDTH 3
COLOR 255 136 0
END
END
CLASS
EXPRESSION "4"
STYLE
WIDTH 3
COLOR 255 0 0
END
END
CLASS
EXPRESSION "5"
STYLE
WIDTH 3
COLOR 0 0 0
END
END
END
LAYER
STATUS ON
GROUP "maxspeed"
PROJECTION
"init=epsg:4326"
END
CONNECTIONTYPE postgis
CONNECTION "host=localhost dbname=maxspeed user=www-data password=www-data port=5432"
PROCESSING "CLOSE_CONNECTION=DEFER"
minscaledenom 1743443
maxscaledenom 13867550
TYPE LINE
NAME "maxspeedwmbunt"
DATA "way from (select way, osm_id ,highway,speedclass from osm_line where highway='motorway' and maxspeed is not null order by z_order) as foo using unique osm_id using srid=4326"
CLASSITEM "speedclass"
CLASS
EXPRESSION "1"
STYLE
WIDTH 3
COLOR 0 255 0
END
END
CLASS
EXPRESSION "2"
STYLE
WIDTH 3
COLOR 255 255 0
END
END
CLASS
EXPRESSION "3"
STYLE
WIDTH 3
COLOR 255 136 0
END
END
CLASS
EXPRESSION "4"
STYLE
WIDTH 3
COLOR 255 0 0
END
END
CLASS
EXPRESSION "5"
STYLE
WIDTH 3
COLOR 0 0 0
END
END
END
Sodele, und zuletzt gehen wir in unsere “normale” Mapfile und binden die neue Datei ein. Bei mir sieht das so aus…ganz unten vorm letzten END
INCLUDE ‘/osm/mapserver/maxspeed.map’
Fertig. Jetzt kann man in OL das WMS Layer einbinden. Man kann sowohl die ganze Gruppe (maxspeed hier), also aich die einzelnen Layer einbinden. Bspw so
wms maxspeed = new OpenLayers.Layer.WMS("Maxspeed Layer","http://mein.server.de/wms?", {
layers: 'maxspeed', transparent: true,
projection:new OpenLayers.Projection("EPSG:900913"),
format: 'aggpng24'
},
{isBaseLayer: false}
);