Mercurial > dive4elements > river
comparison flys-backend/contrib/shpimporter/hws.py @ 4955:7323847fa7df dami
Importer: Add HWS lines stub. Needs some example data to finish
especially the setting of additional geometry values
author | Andre Heinecke <aheinecke@intevation.de> |
---|---|
date | Fri, 01 Feb 2013 11:42:34 +0100 |
parents | c0a58558b817 |
children | baa32f1df47d |
comparison
equal
deleted
inserted
replaced
4954:1a218a0bcfcf | 4955:7323847fa7df |
---|---|
45 "Berlin" : 14, | 45 "Berlin" : 14, |
46 "Bremen" : 15, | 46 "Bremen" : 15, |
47 "Hamburg" : 16, | 47 "Hamburg" : 16, |
48 } | 48 } |
49 | 49 |
50 class HWSLines(Importer): | |
51 | |
52 def getPath(self, base): | |
53 return "%s/%s" % (base, PATH) | |
54 | |
55 def getTablename(self): | |
56 return "hws_lines" | |
57 | |
58 def getName(self): | |
59 return "HWS_LINES" | |
60 | |
61 def isGeometryValid(self, geomType): | |
62 return geomType == 2 | |
63 | |
64 def isShapeRelevant(self, name, path): | |
65 return True | |
66 | |
67 def createNewFeature(self, featureDef, feat, **args): | |
68 newFeat = ogr.Feature(featureDef) | |
69 geometry = feat.GetGeometryRef() | |
70 geometry.SetCoordinateDimension(2) | |
71 | |
72 newFeat.SetGeometry(geometry) | |
73 | |
74 if self.IsFieldSet(feat, "river_id"): | |
75 newFeat.SetField("river_id", feat.GetField("river_id")) | |
76 else: | |
77 newFeat.SetField("river_id", self.river_id) | |
78 | |
79 if self.IsFieldSet(feat, "TYP"): | |
80 newFeat.SetField("type", feat.GetField("TYP")) | |
81 | |
82 if self.IsFieldSet(feat, "Bauart"): | |
83 newFeat.SetField("hws_facility", feat.GetField("Bauart")) | |
84 | |
85 if self.IsFieldSet(feat, "Name"): | |
86 newFeat.SetField("name", feat.GetField("name")) | |
87 else: | |
88 newFeat.SetField("name", args['name']) | |
89 | |
90 return newFeat | |
91 | |
92 class HWSPoints(Importer): | 50 class HWSPoints(Importer): |
93 fieldmap = { | 51 fieldmap = { |
94 "name$" : "name", | 52 "name$" : "name", |
95 "quelle$" : "source", | 53 "quelle$" : "source", |
96 "anmerkung$" : "description", | 54 "anmerkung$" : "description", |
115 def isGeometryValid(self, geomType): | 73 def isGeometryValid(self, geomType): |
116 return geomType == ogr.wkbPoint or geomType == ogr.wkbPoint25D | 74 return geomType == ogr.wkbPoint or geomType == ogr.wkbPoint25D |
117 | 75 |
118 def isShapeRelevant(self, name, path): | 76 def isShapeRelevant(self, name, path): |
119 shp = ogr.Open(path) | 77 shp = ogr.Open(path) |
120 if shp.GetLayerByName(name).GetGeomType() == ogr.wkbPoint or \ | 78 return self.isGeometryValid(shp.GetLayerByName(name).GetGeomType()) |
121 shp.GetLayerByName(name).GetGeomType() == ogr.wkbPoint25D: | |
122 return True | |
123 else: | |
124 return False | |
125 | 79 |
126 def createNewFeature(self, featureDef, feat, **args): | 80 def createNewFeature(self, featureDef, feat, **args): |
127 newFeat = ogr.Feature(featureDef) | 81 newFeat = ogr.Feature(featureDef) |
128 geometry = feat.GetGeometryRef() | 82 geometry = feat.GetGeometryRef() |
129 geometry.SetCoordinateDimension(2) | 83 geometry.SetCoordinateDimension(2) |
195 rl = newFeat.GetFieldAsDouble("rated_level") | 149 rl = newFeat.GetFieldAsDouble("rated_level") |
196 newFeat.SetField("freeboard", z - rl) | 150 newFeat.SetField("freeboard", z - rl) |
197 | 151 |
198 return newFeat | 152 return newFeat |
199 | 153 |
154 class HWSLines(HWSPoints): | |
200 | 155 |
156 # TODO: GEOM_target, GEOM_rated_level, dike_km_from, dike_km_to | |
157 fieldmap = { | |
158 "name$" : "name", | |
159 "quelle$" : "source", | |
160 "anmerkung$" : "description", | |
161 "stand$" : "status_date", | |
162 "verband$" : "agency", | |
163 "Bereich$" : "range", | |
164 } | |
165 | |
166 def getPath(self, base): | |
167 return "%s/%s" % (base, PATH) | |
168 | |
169 def getTablename(self): | |
170 return "hws_lines" | |
171 | |
172 def getName(self): | |
173 return "HWS_LINES" | |
174 | |
175 def isGeometryValid(self, geomType): | |
176 return geomType == ogr.wkbLineString or geomType == ogr.wkbLineString25D | |
177 | |
178 def isShapeRelevant(self, name, path): | |
179 shp = ogr.Open(path) | |
180 return self.isGeometryValid(shp.GetLayerByName(name).GetGeomType()) | |
181 | |
182 def createNewFeature(self, featureDef, feat, **args): | |
183 newFeat = HWSPoints.createNewFeature(self, featureDef, feat, **args) | |
184 geometry = feat.GetGeometryRef() | |
185 geometry.SetCoordinateDimension(3) | |
186 newFeat.SetGeometry(geometry) | |
187 | |
188 return newFeat | |
189 | |
190 |