osm2pgsql und mapserver

Hallo,

ich bastel gerade ein bisschen mit osm2pgsql und mapserver rum, nach dieser Anleitung. Leider bringe ich nicht mal das mitgelieferte Beispiel zum laufen. Hat das schon mal jemand geschafft?

osm2pgsql legt mir eine Tabelle “osm_polygon” mit einer Spalte namens “natural” an. Um diese abzufragen, muss ich bei SQL Anführungszeichen setzen, weil natural ein Schlüsselwort von SQL ist, also z.B.

osm=# select name,"natural" from osm_polygon where name like '%Weiher' limit 4;
                name                | natural 
------------------------------------+---------
 Riederer Weiher                    | water
 Alter Weiher                       | water
 Eitzenberger Weiher                | 
 Jugendzeltplatz Eizenberger Weiher | 

So weit so gut. mapserver akzeptiert aber anscheinend keine Anführungszeichen in seinem map file. Im mitgelieferten Beispiel der osm-mapserver utilities steht zwar

CONNECTION "host=localhost dbname=osm user=xxx password=yyy port=5432"
DATA "way from (select way,osm_id ,\"natural\",landuse ,highway, name from osm_polygon....

aber mein mapserver frisst das einfach nicht. Auch keine andere Kombination von Anführungszeichen oder "" hilft weiter.

Benenne ich die Spalte um in “nature” und lass die Anführungszeichen weg, rendert der mapserver wie gewünscht. Aber eigentlich wollte ich mit eigenen Bastelarbeiten erst zu einem späteren Zeitpunkt anfangen und erstmal die Beispiele zum laufen bringen…

(OS=Debian, mapserver 5.6.6, postgresql 8.3, osm2pgsql frisch aus dem svn)

Grüße, Max

also bei mir lief es wie besschrieben. Ich hatte es schon vor einer Weile installiert, aber auch bei mir stehts mit “nature”. Kann aber auch sein, dass ich ein Find/Replace gemacht und "natural"\ durch nature ersetzt habe. Jedenfalls ging es recht einfach.
"DATA “way from (select way,osm_id ,nature,landuse ,highway, name from osm_polygon_view where landuse is…”

im Postprocessing steht das, was immer das genau bedeutet
create or replace view osm_polygon_view as select osm_id, “natural” as nature, landuse, waterway, highway, name, way from osm_polygon;

EDIT:

Da stehts:
“the osm data has to be postprocessed to allow rendering enhancements and speedups, and to rename the column “natural” to “nature”:”

Danke Thomas,

bei mir hat wohl das create view nicht geklappt und der Rest sind Folgefehler… habs angelegt und im map file “natural” durch “nature” ersetzt. Jetzt gehts.

Grüße, Max

Hallo Max,

keine Ahnung ob Du es weißt oder brauchst…Wenn Du das Rendering in geringen Vergrößerungen beschleuningen willst, nimm Tilecache (geht super) oder erstelle einen Materialized View wie folgt. Ich habe das noch nicht versucht sonder hier gefunden
http://geoinformatics.fsv.cvut.cz/gwiki/OpenStreetMap_over_WMS#Speeding_up_rendering_time


DROP TABLE IF EXISTS osm_highway_motorways;
DELETE FROM geometry_columns WHERE f_table_name='osm_highway_motorways';
CREATE table osm_highway_motorways AS select way, osm_id ,highway,ref, name, z_order from osm_line
 where highway = 'motorway' order by z_order;

CREATE INDEX osm_highway_motorways_index
 ON osm_highway_motorways
 USING gist
 (way);

CREATE INDEX osm_highway_motorways_pkey
 ON osm_highway_motorways
 USING btree
 (osm_id);

INSERT INTO geometry_columns (f_table_catalog, f_table_schema, f_table_name, f_geometry_column, 
 coord_dimension, srid, "type") VALUES (' ', 'public', 'osm_highway_motorways', 'way', 2, 900913,
 'LINESTRING');

GRANT SELECT on osm_highway_motorways to "www-data";

Mir fällt auf dass hier statt einer View eine neue Tabelle angelegt wird, das ist zwar redundant, aber schneller. Gibt es irgendwo schon Skripte die das möglichst geschickt machen so für den allgemeinen Bedarf?

schreibt die o.g. Befehle ins Postprocessing Skript ans Ende…oder verstehe ich Deine Frage falsch?

Ich hab noch gar kein Postprocessing - bisher nehme ich die Tabellen so wie sie osm2pgsql erzeugt und hab ein paar Views. Allerdings irgendwelchen Kram den ich mir so ausgedacht habe und der sicher nicht optimal ist. Schlaue Leute werden sich da sicher mal ein schickes Postprocessing ausgedacht haben und sowas suche ich nun mal. Fein dokumentiert wäre schick, aber geht auch so. Das Beispiel aus Frankreich oder was das war kenn ich schon.

Inkl der oben erwähnten Änderungen würde das bei mir so aussehen (wobei ich zusätzlich noch name:de und name:hu mit importiert habe


-- custom local names
ALTER TABLE osm_line RENAME COLUMN "name:hu" TO namehu;
ALTER TABLE osm_point RENAME COLUMN "name:hu" TO namehu;
ALTER TABLE osm_polygon RENAME COLUMN "name:hu" TO namehu;
ALTER TABLE osm_roads RENAME COLUMN "name:hu" TO namehu;



ALTER TABLE osm_line RENAME COLUMN "name:de" TO namede;
ALTER TABLE osm_point RENAME COLUMN "name:de" TO namede;
ALTER TABLE osm_polygon RENAME COLUMN "name:de" TO namede;
ALTER TABLE osm_roads RENAME COLUMN "name:de" TO namede;

--add default name if local name is empty
update osm_line set namede = name where namede is null and name is not null;
update osm_point set namede = name where namede is null and name is not null;
update osm_polygon set namede = name where namede is null and name is not null;
update osm_roads set namede = name where namede is null and name is not null;

update osm_line set namede = name where namehu is null and name is not null;
update osm_point set namede = name where namehu is null and name is not null;
update osm_polygon set namede = name where namehu is null and name is not null;
update osm_roads set namede = name where namehu is null and name is not null;


-- optional, makes it easier to wrap place names
update osm_point set name = replace(name,'-',' ');

-- grant our user access to the data
grant SELECT on osm_line to "www-data";
grant SELECT on osm_point to "www-data";
grant SELECT on osm_polygon to "www-data";
create or replace view osm_polygon_view as select osm_id, "natural" as nature, landuse, waterway, highway, name, namede, namehu, way from osm_polygon;
grant select on osm_polygon_view to "www-data" ;

-- correct a few common typos
update osm_line set tunnel='yes' where tunnel='true';
update osm_line set tunnel='no' where tunnel='false';
update osm_line set tunnel='yes' where tunnel='yel';
update osm_line set bridge='yes' where bridge='true';

update osm_line set oneway='yes' where oneway='Yes';
update osm_line set oneway='yes' where oneway='true';
update osm_line set oneway='yes' where oneway='1';

-- create a few indexes on the data for speedier access
create index osm_polygon_building_idx on osm_polygon(building);
create index osm_polygon_amenity_idx on osm_polygon(amenity);
create index osm_polygon_landuse_idx on osm_polygon(landuse);
create index osm_line_highway_idx on osm_line(highway);
create index osm_line_aeroway_idx on osm_line(aeroway);
create index osm_line_railway_idx on osm_line(railway);
create index osm_line_bridge_idx on osm_line(bridge);
create index osm_polygon_leisure_idx on osm_polygon(leisure);
create index osm_polygon_aeroway_idx on osm_polygon(aeroway);
create index osm_polygon_waterway_idx on osm_polygon(waterway);
create index osm_polygon_natural_idx on osm_polygon("natural");
create index osm_point_place_idx on osm_point(place);
create index osm_line_zorder_idx on osm_line(z_order);


alter table osm_line add column priority integer;
update osm_line set priority = 10 where highway='motorway';
update osm_line set priority = 20 where highway='trunk';
update osm_line set priority = 26 where highway='trunk_link';
update osm_line set priority = 25 where highway='motorway_link';
update osm_line set priority = 30 where highway='primary';
update osm_line set priority = 35 where highway='primary_link';

update osm_line set priority=40 where highway='secondary';
update osm_line set priority=45 where highway='secondary_link';

update osm_line set priority=50 where highway='tertiary';
update osm_line set priority=65 where highway='tertiary_link';

update osm_line set priority=70 where highway='residential';
update osm_line set priority=75 where highway='service';
update osm_line set priority=80 where highway='track';
update osm_line set priority=85 where highway='pedestrian';

create index line_priority_idx on osm_line(priority);

DROP TABLE IF EXISTS osm_highway_motorways;
DELETE FROM geometry_columns WHERE f_table_name='osm_highway_motorways';
CREATE table osm_highway_motorways AS select way, osm_id ,highway,ref, name, z_order from osm_line where highway = 'motorway' order by z_order;

CREATE INDEX osm_highway_motorways_index ON osm_highway_motorways USING gist (way);

CREATE INDEX osm_highway_motorways_pkey ON osm_highway_motorways USING btree (osm_id);

INSERT INTO geometry_columns (f_table_catalog, f_table_schema, f_table_name, f_geometry_column, coord_dimension, srid, "type") VALUES 
(' ', 'public', 'osm_highway_motorways', 'way', 2, 900913, 'LINESTRING');

GRANT SELECT on osm_highway_motorways to "www-data";


Das kenn ich wie gesagt schon: http://mapserver-utils.googlecode.com/svn/trunk/ - aber Danke auch für Dein Posting.