ingo@1230: BEGIN;
ingo@1230: 
hans@1238: -- Geodaesie/Flussachse+km/achse
ingo@1240: CREATE SEQUENCE RIVER_AXES_ID_SEQ;
ingo@1230: CREATE TABLE river_axes (
ingo@1240:     id       int PRIMARY KEY NOT NULL,
ingo@1230:     river_id int REFERENCES rivers(id),
ingo@3948:     kind     int             NOT NULL DEFAULT 0,
ingo@3948:     name     VARCHAR(64),
ingo@3948:     path     VARCHAR(256)
ingo@1230: );
ingo@3950: SELECT AddGeometryColumn('river_axes', 'geom', 31467, 'LINESTRING', 2);
ingo@1240: ALTER TABLE river_axes ALTER COLUMN id SET DEFAULT NEXTVAL('RIVER_AXES_ID_SEQ');
ingo@1230: 
ingo@1230: 
bjoern@2340: -- TODO: TestMe.
bjoern@2339: -- Geodaesie/Flussachse+km/km.shp
bjoern@2340: CREATE SEQUENCE RIVER_AXES_KM_ID_SEQ;
bjoern@2340: CREATE TABLE river_axes_km (
bjoern@2340:     id       int PRIMARY KEY NOT NULL,
bjoern@2340:     river_id int REFERENCES rivers(id),
ingo@3948:     km       NUMERIC NOT NULL,
ingo@3948:     name     VARCHAR(64),
ingo@3948:     path     VARCHAR(256)
bjoern@2340: );
ingo@3950: SELECT AddGeometryColumn('river_axes_km', 'geom', 31467, 'POINT', 2);
bjoern@2340: ALTER TABLE river_axes_km ALTER COLUMN id SET DEFAULT NEXTVAL('RIVER_AXES_KM_ID_SEQ');
bjoern@2339: 
bjoern@2339: 
bjoern@2339: --Geodaesie/Querprofile/QP-Spuren/qps.shp
ingo@1240: CREATE SEQUENCE CROSS_SECTION_TRACKS_ID_SEQ;
ingo@1230: CREATE TABLE cross_section_tracks (
ingo@1240:     id       int PRIMARY KEY NOT NULL,
ingo@1230:     river_id int REFERENCES rivers(id),
ingo@1230:     km       NUMERIC NOT NULL,
ingo@3948:     z        NUMERIC NOT NULL DEFAULT 0,
ingo@3948:     name     VARCHAR(64),
ingo@3948:     path     VARCHAR(256)
ingo@1230: );
ingo@3950: SELECT AddGeometryColumn('cross_section_tracks', 'geom', 31467, 'LINESTRING', 2);
ingo@1240: ALTER TABLE cross_section_tracks ALTER COLUMN id SET DEFAULT NEXTVAL('CROSS_SECTION_TRACKS_ID_SEQ');
ingo@1230: 
ingo@1230: 
hans@1238: -- Geodaesie/Linien/rohre-und-spreen
ingo@1240: CREATE SEQUENCE LINES_ID_SEQ;
ingo@1230: CREATE TABLE lines (
ingo@1240:     id       int PRIMARY KEY NOT NULL,
ingo@1230:     river_id int REFERENCES rivers(id),
ingo@2365:     kind     VARCHAR(16) NOT NULL,
ingo@3948:     z        NUMERIC DEFAULT 0,
ingo@3948:     name     VARCHAR(64),
ingo@3948:     path     VARCHAR(256)
ingo@1230: );
ingo@3950: SELECT AddGeometryColumn('lines', 'geom', 31467, 'LINESTRING', 3);
ingo@1240: ALTER TABLE lines ALTER COLUMN id SET DEFAULT NEXTVAL('LINES_ID_SEQ');
ingo@1230: -- 'kind':
ingo@1230: -- 0: ROHR1
ingo@1230: -- 1: DAMM
ingo@1230: 
ingo@1230: 
hans@1238: -- Geodaesie/Bauwerke/Wehre.shp
ingo@1240: CREATE SEQUENCE BUILDINGS_ID_SEQ;
ingo@1230: CREATE TABLE buildings (
ingo@1240:     id       int PRIMARY KEY NOT NULL,
ingo@1230:     river_id int REFERENCES rivers(id),
ingo@3948:     name     VARCHAR(256),
ingo@3948:     path     VARCHAR(256)
ingo@1230: );
ingo@3950: SELECT AddGeometryColumn('buildings', 'geom', 31467, 'LINESTRING', 2);
ingo@1240: ALTER TABLE buildings ALTER COLUMN id SET DEFAULT NEXTVAL('BUILDINGS_ID_SEQ');
ingo@1230: 
ingo@1230: 
hans@1238: -- Geodaesie/Festpunkte/Festpunkte.shp
ingo@1240: CREATE SEQUENCE FIXPOINTS_ID_SEQ;
ingo@1230: CREATE TABLE fixpoints (
ingo@1240:     id       int PRIMARY KEY NOT NULL,
ingo@1230:     river_id int REFERENCES rivers(id),
ingo@1230:     x        int,
ingo@1230:     y        int,
ingo@1230:     km       NUMERIC NOT NULL,
ingo@3948:     HPGP     VARCHAR(2),
ingo@3948:     name     VARCHAR(64),
ingo@3948:     path     VARCHAR(256)
ingo@1230: );
ingo@3950: SELECT AddGeometryColumn('fixpoints', 'geom', 31467, 'POINT', 2);
ingo@1240: ALTER TABLE fixpoints ALTER COLUMN id SET DEFAULT NEXTVAL('FIXPOINTS_ID_SEQ');
ingo@1230: 
ingo@1236: 
hans@1238: -- Hydrologie/Hydr. Grenzen/talaue.shp
ingo@1240: CREATE SEQUENCE FLOODPLAIN_ID_SEQ;
ingo@1237: CREATE TABLE floodplain (
ingo@1240:     id       int PRIMARY KEY NOT NULL,
ingo@3948:     river_id int REFERENCES rivers(id),
ingo@3948:     name     VARCHAR(64),
ingo@3948:     path     VARCHAR(256)
ingo@1237: );
ingo@3950: SELECT AddGeometryColumn('floodplain', 'geom', 31467, 'POLYGON', 2);
ingo@1240: ALTER TABLE floodplain ALTER COLUMN id SET DEFAULT NEXTVAL('FLOODPLAIN_ID_SEQ');
ingo@1237: 
ingo@1237: 
hans@1238: -- Geodaesie/Hoehenmodelle/*
ingo@1240: CREATE SEQUENCE DEM_ID_SEQ;
ingo@1240: CREATE TABLE dem (
ingo@1240:     id       int PRIMARY KEY NOT NULL,
ingo@1236:     river_id int REFERENCES rivers(id),
ingo@1236:     -- XXX Should we use the ranges table instead?
ingo@3951:     name            VARCHAR(64),
ingo@3951:     lower           NUMERIC,
ingo@3951:     upper           NUMERIC,
ingo@3961:     year_from       VARCHAR(32) NOT NULL,
ingo@3961:     year_to         VARCHAR(32) NOT NULL,
ingo@3961:     projection      VARCHAR(32) NOT NULL,
ingo@3951:     elevation_state VARCHAR(32),
ingo@3951:     format          VARCHAR(32),
ingo@3951:     border_break    BOOLEAN NOT NULL DEFAULT FALSE,
ingo@3951:     resolution      VARCHAR(16),
ingo@3951:     description     VARCHAR(256),
ingo@3951:     path            VARCHAR(256)
ingo@1236: );
ingo@1240: ALTER TABLE dem ALTER COLUMN id SET DEFAULT NEXTVAL('DEM_ID_SEQ');
ingo@1236: 
hans@1238: 
bjoern@1241: -- Hydrologie/Einzugsgebiete/EZG.shp
bjoern@1241: CREATE SEQUENCE CATCHMENT_ID_SEQ;
bjoern@1241: CREATE TABLE catchment (
bjoern@1241:     id int PRIMARY KEY NOT NULL,
bjoern@1241:     river_id int REFERENCES rivers(id),
bjoern@2339:     area NUMERIC,
ingo@3948:     name VARCHAR(256),
ingo@3948:     path     VARCHAR(256)
bjoern@1241: );
ingo@3950: SELECT AddGeometryColumn('catchment','geom',31467,'POLYGON',2);
bjoern@1241: ALTER TABLE catchment ALTER COLUMN id SET DEFAULT NEXTVAL('CATCHMENT_ID_SEQ');
bjoern@1241: 
bjoern@1241: 
bjoern@2339: --Hydrologie/HW-Schutzanlagen/hws.shp
bjoern@2339: CREATE SEQUENCE HWS_ID_SEQ;
bjoern@2339: CREATE TABLE hws (
bjoern@2339:     id int PRIMARY KEY NOT NULL,
bjoern@2339:     river_id int REFERENCES rivers(id),
bjoern@2339:     hws_facility VARCHAR(256),
ingo@3948:     type VARCHAR(256),
ingo@3948:     name VARCHAR(64),
ingo@3948:     path     VARCHAR(256)
bjoern@2339: );
ingo@3950: SELECT AddGeometryColumn('hws','geom',31467,'LINESTRING',2);
sascha@2376: ALTER TABLE hws ALTER COLUMN id SET DEFAULT NEXTVAL('HWS_ID_SEQ');
bjoern@1241: 
bjoern@1241: 
ingo@2797: --
ingo@2796: --Hydrologie/UeSG
ingo@2797: --
ingo@2797: -- 'kind' can be one of:
ingo@2797: -- 200 = Messung
ingo@2797: -- 111 = Berechnung->Aktuell->BfG
ingo@2797: -- 112 = Berechnung->Aktuell->Land
ingo@2797: -- 121 = Berechnung->Potenziell->BfG
ingo@2797: -- 122 = Berechnung->Potenziell->Land
ingo@2797: --
ingo@3948: CREATE SEQUENCE FLOODMAPS_ID_SEQ;
ingo@2796: CREATE TABLE floodmaps (
ingo@2796:     id         int PRIMARY KEY NOT NULL,
ingo@2796:     river_id   int REFERENCES rivers(id),
ingo@2797:     name       varchar(64) NOT NULL,
ingo@2796:     kind       int NOT NULL,
ingo@2797:     diff       real,
ingo@2796:     count      int,
ingo@2797:     area       real,
ingo@3948:     perimeter  real,
ingo@3948:     path     VARCHAR(256)
ingo@2796: );
ingo@3950: SELECT AddGeometryColumn('floodmaps', 'geom', 31467, 'MULTIPOLYGON', 2);
ingo@2797: ALTER TABLE floodmaps DROP CONSTRAINT enforce_geotype_geom;
ingo@2797: ALTER TABLE floodmaps ADD CONSTRAINT enforce_geotype_geom CHECK (geometrytype(geom) = 'POLYGON'::text OR geometrytype(geom) = 'MULTIPOLYGON'::text);
ingo@3948: ALTER TABLE floodmaps ALTER COLUMN id SET DEFAULT NEXTVAL('FLOODMAPS_ID_SEQ');
ingo@2796: 
ingo@3948: 
ingo@3948: CREATE SEQUENCE HYDR_BOUNDARIES_ID_SEQ;
ingo@3948: CREATE TABLE hydr_boundaries (
ingo@3948:     id         int PRIMARY KEY NOT NULL,
ingo@3948:     river_id   int REFERENCES rivers(id),
ingo@3948:     name       VARCHAR(255),
ingo@3948:     kind       int,
ingo@3948:     path       VARCHAR(256)
ingo@3948: );
ingo@3950: SELECT AddGeometryColumn('hydr_boundaries','geom',31467,'LINESTRING',3);
ingo@3948: ALTER TABLE hydr_boundaries ALTER COLUMN id SET DEFAULT NEXTVAL('HYDR_BOUNDARIES_ID_SEQ');
ingo@3948: 
ingo@3948: 
ingo@3948: CREATE SEQUENCE HYDR_BOUNDARIES_POLY_ID_SEQ;
ingo@3948: CREATE TABLE hydr_boundaries_poly (
ingo@3948:     id         int PRIMARY KEY NOT NULL,
ingo@3948:     river_id   int REFERENCES rivers(id),
ingo@3948:     name       VARCHAR(255),
ingo@3948:     kind       int,
ingo@3948:     path       VARCHAR(256)
ingo@3948: );
ingo@3950: SELECT AddGeometryColumn('hydr_boundaries_poly','geom',31467,'POLYGON',3);
ingo@3948: ALTER TABLE hydr_boundaries_poly ALTER COLUMN id SET DEFAULT NEXTVAL('HYDR_BOUNDARIES_POLY_ID_SEQ');
ingo@3948: 
ingo@3948: 
ingo@3948: CREATE SEQUENCE GAUGE_LOCATION_ID_SEQ;
ingo@3948: CREATE TABLE gauge_location (
ingo@3948:     id         int PRIMARY KEY NOT NULL,
ingo@3948:     river_id   int REFERENCES rivers(id),
ingo@3948:     name       VARCHAR(255),
ingo@3948:     path       VARCHAR(256)
ingo@3948: );
ingo@3950: SELECT AddGeometryColumn('gauge_location','geom',31467,'POINT',2);
ingo@3948: ALTER TABLE gauge_location ALTER COLUMN id SET DEFAULT NEXTVAL('GAUGE_LOCATION_ID_SEQ');
ingo@3948: 
ingo@3948: COMMIT;