annotate flys-backend/contrib/shpimporter/hws.py @ 4935:c0a58558b817 dami

Importer: - Handle regular expressions for attribute names - Convert Strings to UTF-8 - Add regular expressions for hws_points values
author Andre Heinecke <aheinecke@intevation.de>
date Thu, 31 Jan 2013 12:23:41 +0100
parents 11b459a3eb5c
children 7323847fa7df
rev   line source
4875
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
1 # -*- coding: utf-8 -*-
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
2 import os
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
3
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
4 try:
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
5 from osgeo import ogr
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
6 except ImportErrror:
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
7 import ogr
2862
998f1a7dcfde New shape importers and schema modifications.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
8
998f1a7dcfde New shape importers and schema modifications.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
9 from importer import Importer
4875
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
10 import utils
2862
998f1a7dcfde New shape importers and schema modifications.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
11
998f1a7dcfde New shape importers and schema modifications.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
12 PATH="Hydrologie/HW-Schutzanlagen"
3654
59ca5dab2782 Shape importer: use python's OptionParse to read user specific configuration from command line.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2862
diff changeset
13 NAME="HWS"
2862
998f1a7dcfde New shape importers and schema modifications.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
14
4875
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
15 # Keep in sync with hws_kinds table:
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
16 HWS_KIND = {
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
17 "Durchlass" : 1,
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
18 "Damm" : 2,
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
19 "Deich" : 2,
4932
60b026b4340e Importer: Classify hochufer as Deich
Andre Heinecke <aheinecke@intevation.de>
parents: 4884
diff changeset
20 "Hochufer" : 2,
4875
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
21 "Graben" : 3,
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
22 }
2862
998f1a7dcfde New shape importers and schema modifications.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
23
4875
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
24 # Keep in sync with fed_states table:
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
25 FED_STATES = {
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
26 "Bayern" : 1,
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
27 "Hessen" : 2,
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
28 "Niedersachsen" : 3,
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
29 "Nordrhein-Westfalen" : 4,
4933
03989fa957fc Importer: Allow Bundeslaender with spaces
Andre Heinecke <aheinecke@intevation.de>
parents: 4932
diff changeset
30 "Nordrhein Westfalen" : 4,
4875
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
31 "Rheinland-Pfalz" : 5,
4933
03989fa957fc Importer: Allow Bundeslaender with spaces
Andre Heinecke <aheinecke@intevation.de>
parents: 4932
diff changeset
32 "Rheinland Pfalz" : 5,
4875
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
33 "Saarland" : 6,
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
34 "Schleswig-Holstein" : 7,
4933
03989fa957fc Importer: Allow Bundeslaender with spaces
Andre Heinecke <aheinecke@intevation.de>
parents: 4932
diff changeset
35 "Schleswig Holstein" : 7,
4875
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
36 "Brandenburg" : 8,
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
37 "Mecklenburg-Vorpommern" : 9,
4933
03989fa957fc Importer: Allow Bundeslaender with spaces
Andre Heinecke <aheinecke@intevation.de>
parents: 4932
diff changeset
38 "Mecklenburg Vorpommern" : 9,
4875
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
39 "Thüringen" : 10,
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
40 "Baden-Württemberg" : 11,
4933
03989fa957fc Importer: Allow Bundeslaender with spaces
Andre Heinecke <aheinecke@intevation.de>
parents: 4932
diff changeset
41 "Baden Württemberg" : 11,
4875
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
42 "Sachsen-Anhalt" : 12,
4933
03989fa957fc Importer: Allow Bundeslaender with spaces
Andre Heinecke <aheinecke@intevation.de>
parents: 4932
diff changeset
43 "Sachsen Anhalt" : 12,
4875
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
44 "Sachsen" : 13,
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
45 "Berlin" : 14,
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
46 "Bremen" : 15,
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
47 "Hamburg" : 16,
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
48 }
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
49
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
50 class HWSLines(Importer):
2862
998f1a7dcfde New shape importers and schema modifications.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
51
998f1a7dcfde New shape importers and schema modifications.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
52 def getPath(self, base):
998f1a7dcfde New shape importers and schema modifications.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
53 return "%s/%s" % (base, PATH)
998f1a7dcfde New shape importers and schema modifications.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
54
998f1a7dcfde New shape importers and schema modifications.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
55 def getTablename(self):
4875
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
56 return "hws_lines"
2862
998f1a7dcfde New shape importers and schema modifications.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
57
3654
59ca5dab2782 Shape importer: use python's OptionParse to read user specific configuration from command line.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2862
diff changeset
58 def getName(self):
4875
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
59 return "HWS_LINES"
3654
59ca5dab2782 Shape importer: use python's OptionParse to read user specific configuration from command line.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2862
diff changeset
60
2862
998f1a7dcfde New shape importers and schema modifications.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
61 def isGeometryValid(self, geomType):
998f1a7dcfde New shape importers and schema modifications.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
62 return geomType == 2
998f1a7dcfde New shape importers and schema modifications.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
63
998f1a7dcfde New shape importers and schema modifications.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
64 def isShapeRelevant(self, name, path):
998f1a7dcfde New shape importers and schema modifications.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
65 return True
998f1a7dcfde New shape importers and schema modifications.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
66
998f1a7dcfde New shape importers and schema modifications.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
67 def createNewFeature(self, featureDef, feat, **args):
998f1a7dcfde New shape importers and schema modifications.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
68 newFeat = ogr.Feature(featureDef)
998f1a7dcfde New shape importers and schema modifications.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
69 geometry = feat.GetGeometryRef()
998f1a7dcfde New shape importers and schema modifications.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
70 geometry.SetCoordinateDimension(2)
998f1a7dcfde New shape importers and schema modifications.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
71
998f1a7dcfde New shape importers and schema modifications.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
72 newFeat.SetGeometry(geometry)
998f1a7dcfde New shape importers and schema modifications.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
73
998f1a7dcfde New shape importers and schema modifications.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
74 if self.IsFieldSet(feat, "river_id"):
998f1a7dcfde New shape importers and schema modifications.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
75 newFeat.SetField("river_id", feat.GetField("river_id"))
998f1a7dcfde New shape importers and schema modifications.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
76 else:
998f1a7dcfde New shape importers and schema modifications.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
77 newFeat.SetField("river_id", self.river_id)
998f1a7dcfde New shape importers and schema modifications.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
78
998f1a7dcfde New shape importers and schema modifications.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
79 if self.IsFieldSet(feat, "TYP"):
998f1a7dcfde New shape importers and schema modifications.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
80 newFeat.SetField("type", feat.GetField("TYP"))
998f1a7dcfde New shape importers and schema modifications.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
81
998f1a7dcfde New shape importers and schema modifications.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
82 if self.IsFieldSet(feat, "Bauart"):
998f1a7dcfde New shape importers and schema modifications.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
83 newFeat.SetField("hws_facility", feat.GetField("Bauart"))
998f1a7dcfde New shape importers and schema modifications.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
84
998f1a7dcfde New shape importers and schema modifications.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
85 if self.IsFieldSet(feat, "Name"):
998f1a7dcfde New shape importers and schema modifications.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
86 newFeat.SetField("name", feat.GetField("name"))
998f1a7dcfde New shape importers and schema modifications.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
87 else:
998f1a7dcfde New shape importers and schema modifications.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
88 newFeat.SetField("name", args['name'])
998f1a7dcfde New shape importers and schema modifications.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
89
998f1a7dcfde New shape importers and schema modifications.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
90 return newFeat
998f1a7dcfde New shape importers and schema modifications.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
91
4875
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
92 class HWSPoints(Importer):
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
93 fieldmap = {
4935
c0a58558b817 Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents: 4934
diff changeset
94 "name$" : "name",
c0a58558b817 Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents: 4934
diff changeset
95 "quelle$" : "source",
c0a58558b817 Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents: 4934
diff changeset
96 "anmerkung$" : "description",
c0a58558b817 Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents: 4934
diff changeset
97 "stand$" : "status_date",
c0a58558b817 Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents: 4934
diff changeset
98 "verband$" : "agency",
c0a58558b817 Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents: 4934
diff changeset
99 "Deich_{0,1}KM$" : "dike_km",
c0a58558b817 Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents: 4934
diff changeset
100 "Bereich$" : "range",
c0a58558b817 Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents: 4934
diff changeset
101 "H[oeö]{0,2}he_{0,1}SOLL$" : "z_target",
c0a58558b817 Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents: 4934
diff changeset
102 "(WSP_){0,1}BfG_{0,1}100$" : "rated_level",
c0a58558b817 Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents: 4934
diff changeset
103 "H[oeö]{0,2}he_{0,1}IST$" : "z",
4875
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
104 }
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
105
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
106 def getPath(self, base):
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
107 return "%s/%s" % (base, PATH)
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
108
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
109 def getTablename(self):
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
110 return "hws_points"
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
111
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
112 def getName(self):
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
113 return "HWS_POINTS"
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
114
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
115 def isGeometryValid(self, geomType):
4934
11b459a3eb5c Importer: Import hws_points based on geom type
Andre Heinecke <aheinecke@intevation.de>
parents: 4933
diff changeset
116 return geomType == ogr.wkbPoint or geomType == ogr.wkbPoint25D
4875
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
117
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
118 def isShapeRelevant(self, name, path):
4934
11b459a3eb5c Importer: Import hws_points based on geom type
Andre Heinecke <aheinecke@intevation.de>
parents: 4933
diff changeset
119 shp = ogr.Open(path)
11b459a3eb5c Importer: Import hws_points based on geom type
Andre Heinecke <aheinecke@intevation.de>
parents: 4933
diff changeset
120 if shp.GetLayerByName(name).GetGeomType() == ogr.wkbPoint or \
11b459a3eb5c Importer: Import hws_points based on geom type
Andre Heinecke <aheinecke@intevation.de>
parents: 4933
diff changeset
121 shp.GetLayerByName(name).GetGeomType() == ogr.wkbPoint25D:
4875
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
122 return True
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
123 else:
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
124 return False
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
125
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
126 def createNewFeature(self, featureDef, feat, **args):
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
127 newFeat = ogr.Feature(featureDef)
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
128 geometry = feat.GetGeometryRef()
4881
9b03cf6b85c9 (importer) calculate freeboard and expect sql
Andre Heinecke <aheinecke@intevation.de>
parents: 4875
diff changeset
129 geometry.SetCoordinateDimension(2)
4875
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
130
4884
b457532dae63 Importer: Move copy fields into importer class and track imported/unimported fields
Andre Heinecke <aheinecke@intevation.de>
parents: 4881
diff changeset
131 self.copyFields(feat, newFeat, self.fieldmap)
4875
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
132
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
133 newFeat.SetGeometry(geometry)
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
134
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
135 newFeat.SetField("ogr_fid", feat.GetFID())
4935
c0a58558b817 Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents: 4934
diff changeset
136 artname = self.searchField("art$")
c0a58558b817 Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents: 4934
diff changeset
137 if self.IsFieldSet(feat, artname):
c0a58558b817 Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents: 4934
diff changeset
138 self.handled(artname)
c0a58558b817 Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents: 4934
diff changeset
139 kind_id = HWS_KIND.get(feat.GetField(artname))
4875
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
140 if not kind_id:
4935
c0a58558b817 Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents: 4934
diff changeset
141 print ("Unknown Art: %s" % \
c0a58558b817 Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents: 4934
diff changeset
142 feat.GetField(artname))
4875
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
143 else:
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
144 newFeat.SetField("kind_id", kind_id)
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
145
4935
c0a58558b817 Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents: 4934
diff changeset
146 fname = self.searchField("Bundesland$")
c0a58558b817 Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents: 4934
diff changeset
147 if self.IsFieldSet(feat, fname):
c0a58558b817 Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents: 4934
diff changeset
148 self.handled(fname)
c0a58558b817 Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents: 4934
diff changeset
149 fed_id = FED_STATES.get(feat.GetField(fname))
4875
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
150
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
151 if not fed_id:
4935
c0a58558b817 Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents: 4934
diff changeset
152 print ("Unknown Bundesland: %s" % \
4875
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
153 feat.GetField("Bundesland"))
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
154 else:
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
155 newFeat.SetField("fed_state_id", fed_id)
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
156
4935
c0a58558b817 Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents: 4934
diff changeset
157 fname = self.searchField("(ufer$)|(flussseite$)")
c0a58558b817 Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents: 4934
diff changeset
158 if self.IsFieldSet(feat, fname):
c0a58558b817 Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents: 4934
diff changeset
159 self.handled(fname)
c0a58558b817 Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents: 4934
diff changeset
160 shoreString = feat.GetField(fname)
4875
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
161 if "links" in shoreString.lower():
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
162 newFeat.SetField("shore_side", True)
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
163 elif "rechts" in shoreString.lower():
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
164 newFeat.SetField("shore_side", False)
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
165
4935
c0a58558b817 Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents: 4934
diff changeset
166
c0a58558b817 Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents: 4934
diff changeset
167 fname = self.searchField("river_{0,1}id$")
c0a58558b817 Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents: 4934
diff changeset
168 if self.IsFieldSet(feat, fname):
c0a58558b817 Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents: 4934
diff changeset
169 self.handled(fname)
c0a58558b817 Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents: 4934
diff changeset
170 if feat.GetField(fname) != self.river_id:
c0a58558b817 Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents: 4934
diff changeset
171 print ("River_id mismatch between shapefile and"
c0a58558b817 Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents: 4934
diff changeset
172 " importer parameter.")
c0a58558b817 Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents: 4934
diff changeset
173 newFeat.SetField("river_id", feat.GetField(fname))
c0a58558b817 Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents: 4934
diff changeset
174 else:
c0a58558b817 Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents: 4934
diff changeset
175 newFeat.SetField("river_id", self.river_id)
c0a58558b817 Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents: 4934
diff changeset
176
c0a58558b817 Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents: 4934
diff changeset
177 fname = self.searchField("name$")
c0a58558b817 Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents: 4934
diff changeset
178 if not self.IsFieldSet(feat, fname):
4875
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
179 newFeat.SetField("name", args['name'])
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
180
4935
c0a58558b817 Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents: 4934
diff changeset
181 fname = self.searchField("offiziell$")
c0a58558b817 Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents: 4934
diff changeset
182 if self.IsFieldSet(feat, fname):
c0a58558b817 Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents: 4934
diff changeset
183 self.handled(fname)
c0a58558b817 Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents: 4934
diff changeset
184 offiziell = feat.GetField(fname)
4881
9b03cf6b85c9 (importer) calculate freeboard and expect sql
Andre Heinecke <aheinecke@intevation.de>
parents: 4875
diff changeset
185 if offiziell == "1" or offiziell == 1:
9b03cf6b85c9 (importer) calculate freeboard and expect sql
Andre Heinecke <aheinecke@intevation.de>
parents: 4875
diff changeset
186 newFeat.SetField("offiziell", True)
9b03cf6b85c9 (importer) calculate freeboard and expect sql
Andre Heinecke <aheinecke@intevation.de>
parents: 4875
diff changeset
187 else:
9b03cf6b85c9 (importer) calculate freeboard and expect sql
Andre Heinecke <aheinecke@intevation.de>
parents: 4875
diff changeset
188 newFeat.SetField("offiziell", False)
9b03cf6b85c9 (importer) calculate freeboard and expect sql
Andre Heinecke <aheinecke@intevation.de>
parents: 4875
diff changeset
189
9b03cf6b85c9 (importer) calculate freeboard and expect sql
Andre Heinecke <aheinecke@intevation.de>
parents: 4875
diff changeset
190 if self.IsFieldSet(newFeat, "z") and \
9b03cf6b85c9 (importer) calculate freeboard and expect sql
Andre Heinecke <aheinecke@intevation.de>
parents: 4875
diff changeset
191 self.IsFieldSet(newFeat, "rated_level"):
4935
c0a58558b817 Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents: 4934
diff changeset
192 fname = self.searchField("freibord(_m){0,1}$")
c0a58558b817 Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents: 4934
diff changeset
193 self.handled(fname)
4881
9b03cf6b85c9 (importer) calculate freeboard and expect sql
Andre Heinecke <aheinecke@intevation.de>
parents: 4875
diff changeset
194 z = newFeat.GetFieldAsDouble("z")
9b03cf6b85c9 (importer) calculate freeboard and expect sql
Andre Heinecke <aheinecke@intevation.de>
parents: 4875
diff changeset
195 rl = newFeat.GetFieldAsDouble("rated_level")
9b03cf6b85c9 (importer) calculate freeboard and expect sql
Andre Heinecke <aheinecke@intevation.de>
parents: 4875
diff changeset
196 newFeat.SetField("freeboard", z - rl)
4875
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
197
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
198 return newFeat
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
199
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
200

http://dive4elements.wald.intevation.org