Diskussion:PostGIS Terminal: Unterschied zwischen den Versionen
Stefan (Diskussion | Beiträge) |
Stefan (Diskussion | Beiträge) (→Database) |
||
Zeile 131: | Zeile 131: | ||
=== Database === | === Database === | ||
− | Das PostGIS-Terminal-Schema (siehe [[Osm2pgsql]]) wurde angepasst (wo überhaupt möglich) mittels der Konfigurations-Daten (.style): | + | Das PostGIS-Terminal-Schema (siehe '''[[Osm2pgsql]]''') wurde angepasst (wo überhaupt möglich) mittels der Konfigurations-Daten (.style): |
* Tabellen-Gruppe 'OSM-Original': Tabellen angelehnt an originale OSM-Planet-Struktur (jedoch mit Tags als Array): | * Tabellen-Gruppe 'OSM-Original': Tabellen angelehnt an originale OSM-Planet-Struktur (jedoch mit Tags als Array): | ||
** osm_nodes => Node mit id, version, lat/lon, tags-Array (gem. default.style) | ** osm_nodes => Node mit id, version, lat/lon, tags-Array (gem. default.style) |
Version vom 23. Juli 2011, 13:25 Uhr
Please note here your questions and feedback below. You can also send them directly to Stefan Keller.
Inhaltsverzeichnis
Feature Requests
- Markers mit Maus-über ("hover") - wären toll... nicht Popup und wegklicken müssen! -
- Features klickbar machen mit Link zu OSM mit osm_id, z.B. http://www.openstreetmap.org/browse/way/82142220
- Data... Next update scheduled on ....
- DB-unabhängig machen! D.h. "Weitere Parameter" (aus config.php) in HTML/Javascript laden.
- DB Zugangsparameter mit Port und Zugangsweise (Text, TSL, SSL) erweitern.
- Besseres Verwalten von Layern, die aus Map und Marker Queries entstanden sind.
- Wie geht das mit Wait-Cursor in OpenLayers???
More Queries...
Marker Queries
--- marker query (must have exactly field names lon, lat, title and description): SELECT X(p2.way) AS lon, Y(p2.way) AS lat, 'Briefkasten' AS title, p2.ref AS description FROM planet_osm_polygon p1 JOIN planet_osm_point p2 ON CONTAINS(p1.way, p2.way) WHERE p1.name = 'Uster' AND p2.amenity = 'post_box'
--- Extension with user defined marker icon (attribute 'icon'): SELECT X(p2.way) AS lon, Y(p2.way) AS lat, 'Briefkasten' AS title, p2.ref AS description, 'http://myserver/marker.png' as icon FROM planet_osm_polygon p1 JOIN planet_osm_point p2 ON CONTAINS(p1.way, p2.way) WHERE p1.name = 'Uster' AND p2.amenity = 'post_box'
All Tag-Value-Pairs of OSM data
Kann anstelle mit osm_point auch mit osm_all durchgeführt werden.
-- -- Key-Value Statistics of OSM Data -- Return all key-value-pairs of type 'enum' without some -- types numeric, date/time etc. chosen by hand: -- SELECT tmp.key||'='||tmp.value as kvp, count(*)::integer as freq FROM ( SELECT (each(tags)).key as key, (each(tags)).value as value FROM osm_point) as tmp WHERE (trim(value) !~ '^[-]*[0-9,.:\ ]+[m]*$') AND NOT (value ILIKE '%fixme%' OR key ILIKE '%fixme%') AND key NOT LIKE '%:%' AND key NOT LIKE '%description%' AND key NOT LIKE '%comment%' AND key NOT LIKE '%name' AND key NOT LIKE 'uic_%' AND key NOT LIKE '%ref' AND key NOT ILIKE '%fixme%' AND key NOT ILIKE '%todo%' AND key NOT IN ('name','operator','_picture_','_waypoint_','address','alt','is_in','url','website','wikipedia','email', 'converted_by','phone','information','opening_hours','date','time','collection_times','colour','fee', 'population','access','noexit','towards','bus_routes','busline','lines','type','denotation', 'CONTINUE','continue','copyright','stop') GROUP BY tmp.key, tmp.value HAVING COUNT(*) > 1 ORDER by key, freq DESC
XAPI-to-Map
Die XAPI-to-Map-Funktion wandelt Anfragen in der Query-Sprache XAPI nach SQL um, fragt die OSM-Datenbank ab und stellt das Resultat direkt in der Webkarte dar. XAPI-to-Map ist - wie der Name sagt - kein Webservice (Maschine-Maschine) sondern eine Mensch-Maschine-Webapplikation. Die Syntax kennt häufige Requests, bestehend aus einem oder mehrerer Tag/Value-Paar sowie ggf. einer Bounding Box-Angabe. Nicht implementiert ist z.B. 'Union-Filter' (OR) im Key (node[amenity|leisure=golf_course]). Im Gegensatz zu anderen XAPI-Implementationn kann man dafür mehrere Filter-Prädikate angeben (z.B. node[amenity=golf_course]node[leisure=golf_course]).
Supported syntax elements:
- Abbildung aller Tabellen sowie '*' (siehe Tabellen-Abbildungen unten)
- Equality Filter (1x): way[highway=motorway]
- Wildcard Filter: im Value way[highway=*]
- BBox-Filter (1x): [bbox=left,bottom,right,top]
- 'Union-Filter' (OR) im Value: way[highway=motorway|motorway_link|trunk|primary]
- Mehrere Filter-Prädikate: node[amenity=golf_course]node[leisure=golf_course]
Notes:
- Special query characters - except A-Z, a-z and " - must be "percent-encoded US-ASCII octet". There are online tools to help out like this one. (see [1]
- It's not possible to do an OR query with nodes OR ways. This is a limitation of the XAPI syntax.
XAPI-Tests
Some test examples:
Use PostGIS Terminal for <postgisterminal_url>: <postgisterminal_url>?xapi=node[tourism=zoo]</nowiki> <postgisterminal_url>/?xapi=node[amenity=*][bbox=5.943,45.935,10.612,47.731]</nowiki> <postgisterminal_url>/?xapi=node[highway=busstop]</nowiki> <postgisterminal_url>/?xapi=node[amenity=hospital][bbox=-6,50,2,61]?zoom=18&lat=47.223&lon=8.822&layers=B0T</nowiki> <postgisterminal_url>/?xapi=*[seamark:type=signal_station_warning]</nowiki>
Use e.g. http://osm.xiala.net:8080/xapi/api/0.6 for a <xapi_service_url>: <xapi_service_url>/node[tourism=zoo] <xapi_service_url>/*[highway=bus_stop][bbox=5.943,45.935,10.612,47.731] <xapi_service_url>/node[amenity=hospital] <xapi_service_url>/node[natural=peak] <xapi_service_url>/*[power_source=nuclear] <xapi_service_url>/node[amenity=*][bbox=5.943,45.935,10.612,47.731] <xapi_service_url>/*[seamark:type=signal_station_warning] <xapi_service_url>/*[amenity=*][bbox=8.420,47.072,9.088,47.431] <xapi_service_url>/*[shop=*][bbox=8.420,47.072,9.088,47.431] <xapi_service_url>/*[tourism=*][bbox=8.420,47.072,9.088,47.431] <xapi_service_url>/node[railway=station][bbox=8.420,47.072,9.088,47.431] <xapi_service_url>/relation[type=restriction][bbox=8.420,47.072,9.088,47.431]
Original XAPI-Dokumentation und andere XAPI-Server
Hier konkrete, laufende XAPI-Beispiele:
- jXAPI (weltweit): http://jxapi.openstreetmap.org/xapi/api/0.6/*%5Btourism=zoo%5D%5Bbbox=5.943,45.935,10.612,47.731%5D
- MapQuest (weltweit): http://open.mapquestapi.com/xapi/api/0.6/*%tourism=zoo%5D%5Bbbox=5.943,45.935,10.612,47.731%5D
- Xiala (Schweiz, ca. 2h behind OSM Planet): http://osm.xiala.net:8080/xapi/api/0.6/*%5Btourism=zoo%5D
- Geometa HSR (Schweiz, alt): http://geometa.hsr.ch/xapi/api/0.6/*%5Btourism=zoo%5D
- Defunct?
XAPI-Dokumentation:
- XAPI
- Query-Syntax: ANTRL-Syntax [2], Query-Parser in Python [3]
- JXAPI-Logs (live!): http://jxapi.openstreetmap.org/xapi/admin/stats sowie Log-Backup von XAPI (unbestätigter Herkunft).
Häufige Anfragen gemäss Logs:
- *[amenity=*]
- *[highway=bus_stop]
- *[shop=*]
- *[tourism=*]
- node[railway=station]
- relation[type=restriction]
PostGIS-Terminal Documentation
Database
Das PostGIS-Terminal-Schema (siehe Osm2pgsql) wurde angepasst (wo überhaupt möglich) mittels der Konfigurations-Daten (.style):
- Tabellen-Gruppe 'OSM-Original': Tabellen angelehnt an originale OSM-Planet-Struktur (jedoch mit Tags als Array):
- osm_nodes => Node mit id, version, lat/lon, tags-Array (gem. default.style)
- osm_ways => Way mit Referenz auf Nodes, d.h. ohne eigene Geometrie (gem. default.style)
- osm_rels => Relation mit Referenz auf Nodes, Ways, Relations (gem. default.style)
- Tabellen-Gruppe 'Osm2pgsql': Tabellen mit Geometrien (PostGIS) zusammengestellt aus aus osm_nodes und osm_ways (mit Tags als hstore durch osm2pgsql '-h'-Flag ):
- osm_point => Punktobjekte (nur Nodes, die Tags enthalten), osm_id, versch. Attr. (gem. default.style) plus osm_version
- osm_line => Linienobjekte (mit 'echter' Geometrie, inkl. Ways, die eigentlich Flächen bilden), osm_id, versch. Attr. (gem. default.style) plus osm_version
- osm_polygon => Flächenobjekte (gebildet aus bestimmten Ways und Relations), osm_id, versch. Attr. (gem. default.style) plus osm_version
- Spezialtabellen:
- osm_roads => linienhafte Strassenobjekte => fehlt, da nicht verwendet! (aus .style auskommentiert)
- osm_all => View über osm_point, osm_line und osm_polygon über die Kolonnen osm_id, name, tags, gtype, way, osm_version (ACHTUNG: z.Zt. nicht-materialisiert, d.h. langsam!).
- osm_poi => Tabelle als View über osm_point und osm_polygon mit ST_Centroid mit den Kolonnen osm_id, name, tags, gtype, way, osm_version (materialisierte View).
Die Attribute osm_id und osm_version (aus Oms2pgsql-Option "-extended-attributes") in der Tabellen-Gruppe 'Osm2pgsql' können nicht umbenannt werden.
XAPI-to-Map
Tabellen-Abbildungen auf Basis osm2pgsql-Schema, die dann Grundlage der:
- point, line, polygon => osm_point, osm_line, osm_polygon (zusätzlich zur XAPI-Syntax).
- node => osm_point
- way => osm_polygon
- relation => osm_rels
- '*' => osm_all
XAPI-zu-SQL-Abbildungen:
- bbox becomes "WHERE ST_CONTAINS(<bbox>,<point_or_way_geom>)"
- equality search becomes AND hstore(tags)->'key' = 'value'
- wildcard search becomes AND hstore(tags)?'fee'
- Passend dazu SQL-Requests https://github.com/osm-spline/xapi/blob/master/sql/sampleRequests.sql
Implementations-Details:
- Wegen '[', '*' sowie ':' (in Keys wie 'name:de') muss die URL kanonisiert werden?
- Spaces sind in Values auch zugelassen, vgl. node[name=Knie's Kinderzoo]
- das XAPI-to-Map funktioniert auch mit Permalink, z.B. node[amenity=hospital][bbox=-6,50,2,61]?zoom=18&lat=47.223&lon=8.822&layers=B0T
- Für häufige Abrafen siehe auch die JXAPI-Logs (live!) sowie den Log-Backup von XAPI mit unbestätigter Herkunft.
- Ev. Zusätzliche Views, Tabellen und Indexes anlegen.
- Primary Keys prüfen! Bei mir hatten osm_point, osm_line, osm_polygon keine!!
- Prüfen was schneller ist: DROP osm_node und all das CREATE... oder TRUNCATE TABLE osm_node und INSERT...
- osm_roads => streichen aus default-style?
Beispiel (man beachte, dass nicht der '->'- sondern der '@>'-Operator verwendet wird wegen GiST-Index):
.../node[tourism=zoo][bbox=6.2,46.1,10.0,47.6] wird abgebildet auf: SELECT ST_AsText(way) geom, name||' '||osm_id label FROM osm_point WHERE tags @> hstore('tourism','zoo') -- nicht hstore(tags)->'tourism' = 'zoo' -- OR ... abhängig von XAPI-Syntax AND ST_Contains(ST_Transform(ST_SetSRID('BOX(6.2 46.1, 10.0 47.6)'::box2d, 4326),900913),way)
.../way[xxx] wird abgebildet auf osm_line (oder osm_polygon?)
Security Features
GRANTS: Rechte entziehen, damit User Tables und Views nicht erzeugen oder löschen können!
Schema nicht PUBLIC? Test: create table customer (id serial, name text); drop table customer; !!! Konfigurieren PostgreSQL Server (postgresql.conf parameters): Disabling autovacuum daemon, fsync=off etc.
DB-Server-Timeout: als Parameter der PostgreSQL-Verbindung in process-query.php (oder als "statement_timeout (60000)" in postgresql.conf); siehe [4]
SET STATEMENT_TIMEOUT TO 60000; SET transaction_read_only TO TRUE; ALTER DATABASE x SET default_transaction_read_only = on;
Logging: Log von IP, Query-String und Response-Infos (success/error/etc. und Prozess-Zeit) speichert. Lösung über process-query.php oder Analyse (grep) Apache-Log?
Data Features
Schema configuration: Style-Datei anpassen, so dass Tabellennamen ohne "planet" und ohne Underscores erzeugt werden, also z.B. anstelle „planet_osm_point“ nur „osmpoint“.
Associative Array: hstore (-h Parameter bei osm2pgsql)
Additional Views and Tables:
CREATE VIEW osm_all AS SELECT osm_id, name, tags, 'pt' AS gtyp, way FROM osm_point UNION SELECT osm_id, name, tags, 'ln' AS gtyp, way FROM osm_line UNION SELECT osm_id, name, tags, 'po' AS gtyp, way FROM osm_polygon
CREATE INDEX osm_point_name_idx ON osm_point(name) WITH (FILLFACTOR=100);
CREATE INDEX osm_point_tags_idx ON osm_point USING gist(tags) WITH (FILLFACTOR=100); -- Kann "FEHLER: invalid hstore value found" ergeben! ALTER TABLE osm_point CLUSTER ON osm_point_name_idx;
VACUUM FREEZE ANALYZE; -- das kann dauern...
Nightly Update: Einrichten eines Cron-Jobs, der einmal pro Nacht die Schweiz neu einspielt (Bitte Vorschlag).
Webservice indicatind database update time and a list of tables => about-db-query.php
Marker Query with attribute 'icon', mit dem man Icons von externen Quellen (url) darstellen kann.