Mercurial > dive4elements > river
changeset 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 (2013-02-01) |
parents | 1a218a0bcfcf |
children | 1469066cc7d9 |
files | flys-backend/contrib/shpimporter/hws.py flys-backend/contrib/shpimporter/shpimporter.py |
diffstat | 2 files changed, 39 insertions(+), 48 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-backend/contrib/shpimporter/hws.py Fri Feb 01 10:43:19 2013 +0100 +++ b/flys-backend/contrib/shpimporter/hws.py Fri Feb 01 11:42:34 2013 +0100 @@ -47,48 +47,6 @@ "Hamburg" : 16, } -class HWSLines(Importer): - - def getPath(self, base): - return "%s/%s" % (base, PATH) - - def getTablename(self): - return "hws_lines" - - def getName(self): - return "HWS_LINES" - - 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 - class HWSPoints(Importer): fieldmap = { "name$" : "name", @@ -117,11 +75,7 @@ def isShapeRelevant(self, name, path): shp = ogr.Open(path) - if shp.GetLayerByName(name).GetGeomType() == ogr.wkbPoint or \ - shp.GetLayerByName(name).GetGeomType() == ogr.wkbPoint25D: - return True - else: - return False + return self.isGeometryValid(shp.GetLayerByName(name).GetGeomType()) def createNewFeature(self, featureDef, feat, **args): newFeat = ogr.Feature(featureDef) @@ -197,4 +151,40 @@ return newFeat +class HWSLines(HWSPoints): + # TODO: GEOM_target, GEOM_rated_level, dike_km_from, dike_km_to + fieldmap = { + "name$" : "name", + "quelle$" : "source", + "anmerkung$" : "description", + "stand$" : "status_date", + "verband$" : "agency", + "Bereich$" : "range", + } + + def getPath(self, base): + return "%s/%s" % (base, PATH) + + def getTablename(self): + return "hws_lines" + + def getName(self): + return "HWS_LINES" + + def isGeometryValid(self, geomType): + return geomType == ogr.wkbLineString or geomType == ogr.wkbLineString25D + + def isShapeRelevant(self, name, path): + shp = ogr.Open(path) + return self.isGeometryValid(shp.GetLayerByName(name).GetGeomType()) + + def createNewFeature(self, featureDef, feat, **args): + newFeat = HWSPoints.createNewFeature(self, featureDef, feat, **args) + geometry = feat.GetGeometryRef() + geometry.SetCoordinateDimension(3) + newFeat.SetGeometry(geometry) + + return newFeat + +
--- a/flys-backend/contrib/shpimporter/shpimporter.py Fri Feb 01 10:43:19 2013 +0100 +++ b/flys-backend/contrib/shpimporter/shpimporter.py Fri Feb 01 11:42:34 2013 +0100 @@ -121,7 +121,8 @@ elif config.skip_floodplains == 1 and isinstance(importer, Floodplain): return True elif config.skip_hws_points == 1 and isinstance(importer, HWSPoints): - return True + if not isinstance(importer, HWSLines): + return True elif config.skip_hws_lines == 1 and isinstance(importer, HWSLines): return True elif config.skip_gauge_locations == 1 and isinstance(importer, GaugeLocation):