# HG changeset patch # User Ingo Weinzierl # Date 1336114680 0 # Node ID 998f1a7dcfdeda0e8f0596f5f86e0ede2078178d # Parent b0132e1b97194516c60f8f03b9c1f7afc1387271 New shape importers and schema modifications. flys-backend/trunk@4345 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r b0132e1b9719 -r 998f1a7dcfde flys-backend/ChangeLog --- a/flys-backend/ChangeLog Thu May 03 14:19:52 2012 +0000 +++ b/flys-backend/ChangeLog Fri May 04 06:58:00 2012 +0000 @@ -1,3 +1,19 @@ +2012-05-04 Ingo Weinzierl + + * doc/schema/oracle-drop-spatial.sql, + doc/schema/oracle-spatial.sql: New relation 'gauge_location' and some + bugfixes in the drop schema. + + * contrib/shpimporter/catchments.py, + contrib/shpimporter/hws.py, + contrib/shpimporter/gauges.py: New importers. + + * contrib/shpimporter/importer.py: Added a debug statement to improve the + visibility of the log output. + + * contrib/shpimporter/shpimporter.py: Make use of the new importers. + + 2012-05-03 Ingo Weinzierl * doc/schema/oracle-drop-spatial.sql, diff -r b0132e1b9719 -r 998f1a7dcfde flys-backend/contrib/shpimporter/catchments.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-backend/contrib/shpimporter/catchments.py Fri May 04 06:58:00 2012 +0000 @@ -0,0 +1,48 @@ +import ogr + +from importer import Importer + +TABLE_NAME="catchment" +PATH="Hydrologie/Einzugsgebiet" + + +class Catchment(Importer): + + def getPath(self, base): + return "%s/%s" % (base, PATH) + + + def getTablename(self): + return TABLE_NAME + + + def isGeometryValid(self, geomType): + return geomType == 3 or geomType == 6 + + + def isShapeRelevant(self, name, path): + return True + + + def createNewFeature(self, featureDef, feat, **args): + newFeat = ogr.Feature(featureDef) + geometry = feat.GetGeometryRef() + geometry.SetCoordinateDimension(2) + + newFeat.SetGeometry(geometry) + + if self.IsFieldSet(feat, "river_id"): + newFeat.SetField("river_id", feat.GetField("river_id")) + else: + newFeat.SetField("river_id", self.river_id) + + if self.IsFieldSet(feat, "Name"): + newFeat.SetField("name", feat.GetField("name")) + else: + newFeat.SetField("name", args['name']) + + if self.IsFieldSet(feat, "AREA"): + newFeat.SetField("area", feat.GetField("area")) + + return newFeat + diff -r b0132e1b9719 -r 998f1a7dcfde flys-backend/contrib/shpimporter/gauges.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-backend/contrib/shpimporter/gauges.py Fri May 04 06:58:00 2012 +0000 @@ -0,0 +1,45 @@ +import ogr + +from importer import Importer + +TABLE_NAME="gauge_location" +PATH="Hydrologie/Streckendaten" + + +class GaugeLocation(Importer): + + def getPath(self, base): + return "%s/%s" % (base, PATH) + + + def getTablename(self): + return TABLE_NAME + + + def isGeometryValid(self, geomType): + return geomType == 1 + + + def isShapeRelevant(self, name, path): + return True + + + def createNewFeature(self, featureDef, feat, **args): + newFeat = ogr.Feature(featureDef) + geometry = feat.GetGeometryRef() + geometry.SetCoordinateDimension(2) + + newFeat.SetGeometry(geometry) + + if self.IsFieldSet(feat, "river_id"): + newFeat.SetField("river_id", feat.GetField("river_id")) + else: + newFeat.SetField("river_id", self.river_id) + + if self.IsFieldSet(feat, "Name"): + newFeat.SetField("name", feat.GetField("name")) + else: + newFeat.SetField("name", args['name']) + + return newFeat + diff -r b0132e1b9719 -r 998f1a7dcfde flys-backend/contrib/shpimporter/hws.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-backend/contrib/shpimporter/hws.py Fri May 04 06:58:00 2012 +0000 @@ -0,0 +1,51 @@ +import ogr + +from importer import Importer + +TABLE_NAME="hws" +PATH="Hydrologie/HW-Schutzanlagen" + + +class HWS(Importer): + + def getPath(self, base): + return "%s/%s" % (base, PATH) + + + def getTablename(self): + return TABLE_NAME + + + def isGeometryValid(self, geomType): + return geomType == 2 + + + def isShapeRelevant(self, name, path): + return True + + + def createNewFeature(self, featureDef, feat, **args): + newFeat = ogr.Feature(featureDef) + geometry = feat.GetGeometryRef() + geometry.SetCoordinateDimension(2) + + newFeat.SetGeometry(geometry) + + if self.IsFieldSet(feat, "river_id"): + newFeat.SetField("river_id", feat.GetField("river_id")) + else: + newFeat.SetField("river_id", self.river_id) + + if self.IsFieldSet(feat, "TYP"): + newFeat.SetField("type", feat.GetField("TYP")) + + if self.IsFieldSet(feat, "Bauart"): + newFeat.SetField("hws_facility", feat.GetField("Bauart")) + + if self.IsFieldSet(feat, "Name"): + newFeat.SetField("name", feat.GetField("name")) + else: + newFeat.SetField("name", args['name']) + + return newFeat + diff -r b0132e1b9719 -r 998f1a7dcfde flys-backend/contrib/shpimporter/importer.py --- a/flys-backend/contrib/shpimporter/importer.py Thu May 03 14:19:52 2012 +0000 +++ b/flys-backend/contrib/shpimporter/importer.py Fri May 04 06:58:00 2012 +0000 @@ -42,6 +42,7 @@ def walkOverShapes(self, shape): + print "---" (name, path) = shape if not self.isShapeRelevant(name, path): print "Skip shapefile '%s'" % name diff -r b0132e1b9719 -r 998f1a7dcfde flys-backend/contrib/shpimporter/shpimporter.py --- a/flys-backend/contrib/shpimporter/shpimporter.py Thu May 03 14:19:52 2012 +0000 +++ b/flys-backend/contrib/shpimporter/shpimporter.py Fri May 04 06:58:00 2012 +0000 @@ -10,6 +10,9 @@ from crosssectiontracks import CrosssectionTrack from floodplains import Floodplain from boundaries import HydrBoundary, HydrBoundaryPoly +from hws import HWS +from gauges import GaugeLocation +from catchments import Catchment DBCONN='OCI:user/pass@host' PATH='/path/to/Gewaesser/Elbe' @@ -28,6 +31,9 @@ Floodplain(DBCONN, RIVER_ID, DEST_SRS), HydrBoundary(DBCONN, RIVER_ID, DEST_SRS), HydrBoundaryPoly(DBCONN, RIVER_ID, DEST_SRS), + HWS(DBCONN, RIVER_ID, DEST_SRS), + GaugeLocation(DBCONN, RIVER_ID, DEST_SRS), + Catchment(DBCONN, RIVER_ID, DEST_SRS), UESG(DBCONN, RIVER_ID, DEST_SRS) ] diff -r b0132e1b9719 -r 998f1a7dcfde flys-backend/doc/schema/oracle-drop-spatial.sql --- a/flys-backend/doc/schema/oracle-drop-spatial.sql Thu May 03 14:19:52 2012 +0000 +++ b/flys-backend/doc/schema/oracle-drop-spatial.sql Fri May 04 06:58:00 2012 +0000 @@ -1,63 +1,68 @@ +DROP TRIGGER river_axes_trigger; DROP TABLE river_axes; DELETE FROM USER_SDO_GEOM_METADATA WHERE TABLE_NAME = 'RIVER_AXES'; -DROP TRIGGER river_axes_trigger; DROP SEQUENCE RIVER_AXES_ID_SEQ; +DROP TRIGGER river_axes_km_trigger; DROP TABLE river_axes_km; DELETE FROM USER_SDO_GEOM_METADATA WHERE TABLE_NAME = 'RIVER_AXES_KM'; -DROP TRIGGER river_axes_km_trigger; DROP SEQUENCE RIVER_AXES_KM_ID_SEQ; +DROP TRIGGER cross_section_tracks_trigger; DROP TABLE cross_section_tracks; DELETE FROM USER_SDO_GEOM_METADATA WHERE TABLE_NAME = 'CROSS_SECTION_TRACKS'; -DROP TRIGGER cross_section_tracks_trigger; DROP SEQUENCE CROSS_SECTION_TRACKS_ID_SEQ; +DROP TRIGGER lines_trigger; DROP TABLE lines; DELETE FROM USER_SDO_GEOM_METADATA WHERE TABLE_NAME = 'LINES'; -DROP TRIGGER lines_trigger; DROP SEQUENCE LINES_ID_SEQ; +DROP TRIGGER buildings_trigger; DROP TABLE buildings; DELETE FROM USER_SDO_GEOM_METADATA WHERE TABLE_NAME = 'BUILDINGS'; -DROP TRIGGER buildings_trigger; DROP SEQUENCE BUILDINGS_ID_SEQ; +DROP TRIGGER fixpoints_trigger; DROP TABLE fixpoints; DELETE FROM USER_SDO_GEOM_METADATA WHERE TABLE_NAME = 'FIXPOINTS'; -DROP TRIGGER fixpoints_trigger; DROP SEQUENCE FIXPOINTS_ID_SEQ; +DROP TRIGGER floodplain_trigger; DROP TABLE floodplain; DELETE FROM USER_SDO_GEOM_METADATA WHERE TABLE_NAME = 'FLOODPLAIN'; -DROP TRIGGER floodplain_trigger; DROP SEQUENCE FLOODPLAIN_ID_SEQ; +DROP TRIGGER dem_trigger; DROP TABLE dem; -DROP TRIGGER dem_trigger; DROP SEQUENCE DEM_ID_SEQ; +DROP TRIGGER catchment_trigger; DROP TABLE catchment; DELETE FROM USER_SDO_GEOM_METADATA WHERE TABLE_NAME = 'CATCHMENT'; -DROP TRIGGER catchment_trigger; DROP SEQUENCE CATCHMENT_ID_SEQ; +DROP TRIGGER hws_trigger; DROP TABLE hws; DELETE FROM USER_SDO_GEOM_METADATA WHERE TABLE_NAME = 'HWS'; -DROP TRIGGER hws_trigger; DROP SEQUENCE HWS_ID_SEQ; +DROP TRIGGER floodmaps_trigger; DROP TABLE floodmaps; DELETE FROM USER_SDO_GEOM_METADATA WHERE TABLE_NAME = 'FLOODMAPS'; -DROP TRIGGER floodmaps_trigger; DROP SEQUENCE FLOODMAPS_ID_SEQ; +DROP TRIGGER hydr_boundaries_trigger; DROP TABLE hydr_boundaries; -DELETE FROM USER_SDO_GEOM_METADATA WHERE TABLE_NAME = 'hydr_boundaries'; -DROP TRIGGER hydr_boundaries_trigger; +DELETE FROM USER_SDO_GEOM_METADATA WHERE TABLE_NAME = 'HYDR_BOUNDARIES'; DROP SEQUENCE HYDR_BOUNDARIES_ID_SEQ; +DROP TRIGGER hydr_boundaries_poly_trigger; DROP TABLE hydr_boundaries_poly; -DELETE FROM USER_SDO_GEOM_METADATA WHERE TABLE_NAME = 'hydr_boundaries_poly'; -DROP TRIGGER hydr_boundaries_poly_trigger; +DELETE FROM USER_SDO_GEOM_METADATA WHERE TABLE_NAME = 'HYDR_BOUNDARIES_POLY'; DROP SEQUENCE HYDR_BOUNDARIES_POLY_ID_SEQ; + +DROP TRIGGER gauge_location_trigger; +DROP TABLE gauge_location; +DELETE FROM USER_SDO_GEOM_METADATA WHERE TABLE_NAME = 'GAUGE_LOCATION'; +DROP SEQUENCE GAUGE_LOCATION_ID_SEQ; diff -r b0132e1b9719 -r 998f1a7dcfde flys-backend/doc/schema/oracle-spatial.sql --- a/flys-backend/doc/schema/oracle-spatial.sql Thu May 03 14:19:52 2012 +0000 +++ b/flys-backend/doc/schema/oracle-spatial.sql Fri May 04 06:58:00 2012 +0000 @@ -256,3 +256,21 @@ END; / CREATE INDEX hydr_boundaries_poly_idx ON hydr_boundaries_poly(GEOM) indextype IS MDSYS.SPATIAL_INDEX parameters ('LAYER_GTYPE=MULTIPOLYGON'); + + +-- Hydrologie/Streckendaten/ +CREATE SEQUENCE GAUGE_LOCATION_ID_SEQ; +CREATE TABLE gauge_location ( + OGR_FID NUMBER(38), + GEOM MDSYS.SDO_GEOMETRY, + river_id NUMBER(38), + name VARCHAR(64), + id NUMBER PRIMARY KEY NOT NULL +); +INSERT INTO USER_SDO_GEOM_METADATA VALUES ('gauge_location', 'GEOM', MDSYS.SDO_DIM_ARRAY(MDSYS.SDO_DIM_ELEMENT('X',3282450,3912240,0.001),MDSYS.SDO_DIM_ELEMENT('Y',5248260,6100130,0.001),MDSYS.SDO_DIM_ELEMENT('Z',-100000,100000,0.002)), 31467); +CREATE OR REPLACE TRIGGER gauge_location_trigger BEFORE INSERT ON gauge_location FOR EACH ROW + BEGIN + SELECT GAUGE_LOCATION_ID_SEQ.nextval INTO :new.id FROM dual; + END; +/ +CREATE INDEX gauge_location_idx ON gauge_location(GEOM) indextype IS MDSYS.SPATIAL_INDEX parameters ('LAYER_GTYPE=POINT');