SQL-Skript zum Einlesen der Festpunkte

Aus kvwmap
Wechseln zu: Navigation, Suche

Wenn die Festpunktdatei sehr groß ist, kann es sein, dass das Einlesen der Festpunkte über die Oberfläche sehr lange dauert bzw. irgendwann abbricht. Um die Festpunkte automatisch einzulesen, kann dieses SQL-Skript verwendet werden:

--Tabelle fp_punkte_temp leeren--

DELETE FROM fp_punkte_temp;

--Daten aus CSV in fp_punkte_temp einlesen und aufbereiten--
DROP index index_pkz;
 COPY fp_punkte_temp 
 (PKZ,RW,HW,HOE,S,ZST,VMA,BEM,ENT,UNT,ZUO,TEX,LS,LG,LZ,LBJ,LAH,HS,HG,HZ,HBJ,HAH) FROM '/home/fgs/fgs/www/var/data/Festpunkte/festpunkte.csv' WITH DELIMITER AS ';' CSV FORCE NOT NULL hoe, zuo, tex, hs, hg, hz, hbj, hah;
 UPDATE fp_punkte_temp SET rw=replace(rw,',','.'), hw=replace(hw,',','.'), hoe=replace(hoe,',','.');
 UPDATE fp_punkte_temp SET the_geom=force_3D(GeometryFromText('POINT('||rw||' '||hw||' '||hoe||')', 2398)) WHERE substring(rw from 0 for 2) = '4';
 UPDATE fp_punkte_temp SET the_geom=force_3D(GeometryFromText('POINT('||rw||' '||hw||' '||hoe||')', 2399)) WHERE substring(rw from 0 for 2) = '5';
 UPDATE fp_punkte_temp SET art=CAST(substring(pkz from '-(.)-') AS int); 
 UPDATE fp_punkte_temp SET art=6 WHERE art=0 AND SUBSTRING(pkz,'.$') NOT LIKE '0';
 UPDATE fp_punkte_temp SET art=5 WHERE ent LIKE '*%';
 UPDATE fp_punkte_temp SET pkz=trim(both ' ' from pkz);
 UPDATE fp_punkte_temp SET datei=substring(pkz from 0 for position('-' in pkz))||'/'||replace(pkz,'-','')||'.tif';
 UPDATE fp_punkte_temp Set datei=substring(pkz from 0 for position('-' in pkz))||'/'||replace(ent,'*','')||'.tif' WHERE ent LIKE '*%' AND split_part(pkz, '-' ,2) = '1';
 UPDATE fp_punkte_temp SET verhandelt=1 WHERE ent LIKE '%*' OR tex LIKE '%*%';
 UPDATE fp_punkte_temp SET vermarkt=1 WHERE vma NOT IN ('000','070','071','073','088','089','090','091','093');
 UPDATE fp_punkte_temp SET pktnr=TRIM(leading '0' FROM SUBSTRING(pkz FROM '.....$'));
 CREATE INDEX index_pkz ON fp_punkte_temp USING btree (pkz);

-- Tabelle fp_punkte leeren --

DELETE FROM fp_punkte;

--Inhalt der Tabelle fp_punkte_temp nach fp_punkte--

INSERT INTO fp_punkte SELECT * FROM fp_punkte_temp;