[opengeodb] stadtname, lon, lat, postleitzahl - nur aus deutschland
Lucas Mengel
froschpopo at gmx.de
Mit Dez 5 01:03:49 CET 2007
Sven Neuhaus schrieb:
> Hallo Lucas,
>
> Lucas Mengel schrieb:
>
>> ich habe mir ein SQL-Statement gebastelt, um "Stadtname, lon, lat,
>> postleitzahl" auszugeben.
>> Das dient dem Zweck, dass ich mir eine eigene, einfacherer Architektur
>> erstellen möchte, die nur diejenigen Daten enthält,
>> die ich auch wirklich benötige.
>>
>> Bevor ich das Problem beschreibe, hier mein Ansatz:
>>
>> SELECT
>> plz.text_val AS stadt,
>> position.lon,
>> position.lat,
>> FROM
>> geodb_textdata plz,
>> geodb_textdata ort,
>> geodb_coordinates position
>> WHERE
>> position.loc_id = plz.loc_id AND
>> ort.loc_id = plz.loc_id AND
>> plz.text_type = 500300000 AND
>> ort.text_type = 500100000
>> ORDER BY 2
>>
>>
>> Nun zum Problemchen: Wie schaffe ich es, das Ergebnis auf Orte in
>> Deutschland zu beschränken?
>>
>
> Das Statement mit hinzugefügter Beschränkung auf Deutschland sieht so aus:
>
> SELECT
> plz.text_val AS stadt,
> position.lon,
> position.lat
> FROM
> geodb_textdata plz,
> geodb_textdata ort,
> geodb_textdata land,
> geodb_coordinates position,
> geodb_locations lo,
> geodb_hierarchies hi
> WHERE
> lo.loc_type = 100200000 /* State */
> AND lo.loc_id = land.loc_id
> AND land.text_type = 500100001 /* ISO_3166_1_ALPHA_2 */
> AND land.text_val = 'DE'
> AND hi.id_lvl2 = lo.loc_id
> AND hi.loc_id = plz.loc_id
> AND position.loc_id = plz.loc_id
> AND ort.loc_id = plz.loc_id
> AND plz.text_type = 500300000
> AND ort.text_type = 500100000
> ORDER BY 2
>
>
> Aber vielleicht solltest Du lieber das folgende Statement verwenden, das
> liefert genauere Koordinaten (dafür aber weniger Einträge):
>
> SELECT DISTINCT text_val, lon, lat
> FROM geodb_coordinates co, geodb_textdata tx,
> geodb_locations lo, geodb_hierarchies hi
> WHERE lo.loc_id = tx.loc_id
> AND lo.loc_id = co.loc_id
> AND lo.loc_id = hi.loc_id
> AND loc_type = 100800000 /* LOC_AREA_CODE */
> AND text_type = 500100000 /* NAME */
>
> Derlei Einträge existieren aber derzeit nur für Deutschland, für Österreich
> und die Schweiz musst Du auf die Einträge vom Typ 100700000 (POPULATED AREA)
> zurückgreifen, die weniger genau sind und für diese den Text des Typs
> 500300000 (AREA_CODE) heraussuchen:
>
> SELECT DISTINCT tx.text_val AS plz, hi.id_lvl2 AS staat, lon, lat
> FROM geodb_textdata tx, geodb_locations lo,
> geodb_coordinates co, geodb_hierarchies hi
> WHERE text_type = 500300000 /* AREA_CODE */
> AND lo.loc_id = tx.loc_id
> AND lo.loc_id = hi.loc_id
> AND lo.loc_id = co.loc_id
> AND lo.loc_type = 100700000 /* POPULATED AREA */
> AND id_lvl2 IN (
> SELECT DISTINCT tx.loc_id
> FROM geodb_textdata tx, geodb_locations lo
> WHERE text_val in ('AT', 'CH')
> AND text_type = 500100001 /* ISO_3166_1_ALPHA_2 */
> AND tx.loc_id = lo.loc_id
> AND lo.loc_type = 100200000 /* State */
>
> Der Subselect liefert übrigens immer "106,107" als loc_id für AT und CH, das
> wird sich vermutlich nicht mal so eben ändern.
>
> Gruss,
> -Sven Neuhaus
>
Hallo Sven!
Danke für die Mühe! Allerdings nutze ich die aktuellste Version der
geodb und die wird ohne geodb_hierarchies ausgeliefert. Das ist ja genau
der Knackpunkt.
Ich weiss nicht, wie ich die füllen muss.