comparison flys-backend/contrib/shpimporter/hws.py @ 4875:37fa93f65971

(importer) Add classes for hws_points and hws_lines
author Andre Heinecke <aheinecke@intevation.de>
date Fri, 25 Jan 2013 10:41:59 +0100
parents 59ca5dab2782
children 9b03cf6b85c9
comparison
equal deleted inserted replaced
4874:b1d7e600b43b 4875:37fa93f65971
1 import ogr 1 # -*- coding: utf-8 -*-
2 import os
3
4 try:
5 from osgeo import ogr
6 except ImportErrror:
7 import ogr
2 8
3 from importer import Importer 9 from importer import Importer
10 import utils
4 11
5 TABLE_NAME="hws"
6 PATH="Hydrologie/HW-Schutzanlagen" 12 PATH="Hydrologie/HW-Schutzanlagen"
7 NAME="HWS" 13 NAME="HWS"
8 14
15 # Keep in sync with hws_kinds table:
16 HWS_KIND = {
17 "Durchlass" : 1,
18 "Damm" : 2,
19 "Deich" : 2,
20 "Graben" : 3,
21 }
9 22
10 class HWS(Importer): 23 # Keep in sync with fed_states table:
24 FED_STATES = {
25 "Bayern" : 1,
26 "Hessen" : 2,
27 "Niedersachsen" : 3,
28 "Nordrhein-Westfalen" : 4,
29 "Rheinland-Pfalz" : 5,
30 "Saarland" : 6,
31 "Schleswig-Holstein" : 7,
32 "Brandenburg" : 8,
33 "Mecklenburg-Vorpommern" : 9,
34 "Thüringen" : 10,
35 "Baden-Württemberg" : 11,
36 "Sachsen-Anhalt" : 12,
37 "Sachsen" : 13,
38 "Berlin" : 14,
39 "Bremen" : 15,
40 "Hamburg" : 16,
41 }
42
43 class HWSLines(Importer):
11 44
12 def getPath(self, base): 45 def getPath(self, base):
13 return "%s/%s" % (base, PATH) 46 return "%s/%s" % (base, PATH)
14 47
15
16 def getTablename(self): 48 def getTablename(self):
17 return TABLE_NAME 49 return "hws_lines"
18
19 50
20 def getName(self): 51 def getName(self):
21 return NAME 52 return "HWS_LINES"
22
23 53
24 def isGeometryValid(self, geomType): 54 def isGeometryValid(self, geomType):
25 return geomType == 2 55 return geomType == 2
26 56
27
28 def isShapeRelevant(self, name, path): 57 def isShapeRelevant(self, name, path):
29 return True 58 return True
30
31 59
32 def createNewFeature(self, featureDef, feat, **args): 60 def createNewFeature(self, featureDef, feat, **args):
33 newFeat = ogr.Feature(featureDef) 61 newFeat = ogr.Feature(featureDef)
34 geometry = feat.GetGeometryRef() 62 geometry = feat.GetGeometryRef()
35 geometry.SetCoordinateDimension(2) 63 geometry.SetCoordinateDimension(2)
52 else: 80 else:
53 newFeat.SetField("name", args['name']) 81 newFeat.SetField("name", args['name'])
54 82
55 return newFeat 83 return newFeat
56 84
85 class HWSPoints(Importer):
86 fieldmap = {
87 "Name" : "name",
88 "Freibord_m" : "freeboard",
89 "Quelle" : "source",
90 "Anmerkung" : "description",
91 "Stand" : "status_date",
92 "Verband" : "agency",
93 "Deich_KM" : "dike_km",
94 "Bereich" : "range",
95 }
96
97 def getPath(self, base):
98 return "%s/%s" % (base, PATH)
99
100 def getTablename(self):
101 return "hws_points"
102
103 def getName(self):
104 return "HWS_POINTS"
105
106 def isGeometryValid(self, geomType):
107 return geomType == 1
108
109 def isShapeRelevant(self, name, path):
110 print "Checking relevancy of %s" % path
111 if "punkte" in os.path.basename(path).lower():
112 return True
113 else:
114 return False
115
116 def createNewFeature(self, featureDef, feat, **args):
117 newFeat = ogr.Feature(featureDef)
118 geometry = feat.GetGeometryRef()
119 geometry.SetCoordinateDimension(3)
120
121 utils.copyFields(feat, newFeat, self.fieldmap)
122
123 newFeat.SetGeometry(geometry)
124
125 newFeat.SetFID(feat.GetFID())
126
127 newFeat.SetField("ogr_fid", feat.GetFID())
128
129 if self.IsFieldSet(feat, "Art"):
130 kind_id = HWS_KIND.get(feat.GetField("Art"))
131 if not kind_id:
132 print ("Unbekannte Art: %s" % \
133 feat.GetField("Art"))
134 else:
135 newFeat.SetField("kind_id", kind_id)
136
137 if self.IsFieldSet(feat, "Bundesland"):
138 fed_id = FED_STATES.get(feat.GetField("Bundesland"))
139
140 if not fed_id:
141 print ("Unbekanntes Bundesland: %s" % \
142 feat.GetField("Bundesland"))
143 else:
144 newFeat.SetField("fed_state_id", fed_id)
145
146 if self.IsFieldSet(feat, "river_id"):
147 if feat.GetField("river_id") != self.river_id:
148 print ("River_id mismatch between shapefile and"
149 " importer parameter.")
150 newFeat.SetField("river_id", feat.GetField("river_id"))
151 else:
152 newFeat.SetField("river_id", self.river_id)
153
154 if self.IsFieldSet(feat, "Ufer"):
155 shoreString = feat.GetField("Ufer")
156 if "links" in shoreString.lower():
157 newFeat.SetField("shore_side", True)
158 elif "rechts" in shoreString.lower():
159 newFeat.SetField("shore_side", False)
160
161 if not self.IsFieldSet(feat, "Name"):
162 newFeat.SetField("name", args['name'])
163
164 # TODO:
165 # offical
166
167 return newFeat
168
169

http://dive4elements.wald.intevation.org