aheinecke@5004: try:
aheinecke@5004:     from osgeo import ogr
aheinecke@5077: except ImportError:
aheinecke@5004:     import ogr
ingo@2798: 
ingo@2853: from importer import Importer
aheinecke@5294: import os.path
aheinecke@5294: import utils
ingo@2853: 
ingo@2798: TABLE_NAME="floodmaps"
tom@5276: PATH="Hydrologie/UeSG"
ingo@3654: NAME="UESG"
ingo@2798: 
ingo@2798: 
ingo@2853: class UESG(Importer):
ingo@2853: 
ingo@2853:     def getPath(self, base):
ingo@2853:         return "%s/%s" % (base, PATH)
ingo@2853: 
ingo@2853: 
ingo@2853:     def getTablename(self):
ingo@2853:         return TABLE_NAME
ingo@2798: 
ingo@2798: 
ingo@3654:     def getName(self):
ingo@3654:         return NAME
ingo@3654: 
ingo@3654: 
ingo@2798:     def isGeometryValid(self, geomType):
aheinecke@5294:         return geomType in [ogr.wkbMultiPolygon,
aheinecke@5294:                             ogr.wkbPolygon]
ingo@2798: 
ingo@2798:     def getKind(self, path):
ingo@2798:         kind = 0
ingo@2798:         if path.find("Berechnung") > 0:
ingo@2798:             kind = kind + 100
ingo@2798: 
ingo@2798:             if path.find("Aktuell") > 0:
ingo@2798:                 kind = kind + 10
ingo@2798:             else:
ingo@2798:                 kind = kind + 20
ingo@2798: 
tom@5276:             if path.find("Bundesl") > 0:
ingo@2798:                 kind = kind + 2
ingo@2798:             else:
ingo@2798:                 kind = kind + 1
ingo@2798:         else:
ingo@2798:             kind = kind + 200
ingo@2798: 
ingo@2798:         return kind
ingo@2798: 
ingo@2798: 
ingo@2853:     def createNewFeature(self, featureDef, feat, **args):
ingo@2853:         kind  = self.getKind(args['path'])
ingo@2798:         newFeat = ogr.Feature(featureDef)
ingo@2798:         newFeat.SetGeometry(feat.GetGeometryRef())
ingo@2798: 
ingo@2853:         if self.IsFieldSet(feat, "river_id"):
ingo@2853:             riverId = feat.GetField(feat)
ingo@2798:         else:
ingo@2853:             riverId = self.river_id
ingo@2798: 
ingo@2861:         if self.IsFieldSet(feat, "diff"):
ingo@2798:             diff = feat.GetFieldAsDouble("diff")
ingo@2798:         else:
ingo@2798:             diff = 0
ingo@2798: 
ingo@2861:         if self.IsFieldSet(feat, "count"):
ingo@2798:             count = feat.GetFieldAsInteger("count")
ingo@2798:         else:
ingo@2798:             count = 0
ingo@2798: 
ingo@2861:         if self.IsFieldSet(feat, "area"):
ingo@2798:             area = feat.GetFieldAsDouble("area")
ingo@2798:         else:
ingo@2798:             area = 0
ingo@2798: 
ingo@2861:         if self.IsFieldSet(feat, "perimeter"):
ingo@2798:             perimeter = feat.GetFieldAsDouble("perimeter")
ingo@2798:         else:
ingo@2798:             perimeter = 0
ingo@2798: 
tom@5854:         if self.IsFieldSet(feat, "GEWAESSER"):
tom@5854:             newFeat.SetField("waterbody", feat.GetField("GEWAESSER"))
tom@5854: 
aheinecke@5294:         if kind >= 200:
aheinecke@5294:             newFeat.SetField("source",
aheinecke@5294:                     os.path.basename(os.path.dirname(args['path'])))
aheinecke@5294: 
aheinecke@5294: 
ingo@2798:         groupId = 2
ingo@2798: 
ingo@2798:         newFeat.SetField("river_id", riverId)
ingo@2798:         newFeat.SetField("diff", diff)
ingo@2798:         newFeat.SetField("count", count)
ingo@2798:         newFeat.SetField("area", area)
ingo@2798:         newFeat.SetField("perimeter", perimeter)
ingo@2853:         newFeat.SetField("kind", kind)
ingo@2853:         newFeat.SetField("name", args['name'])
ingo@2798: 
aheinecke@5294:         return utils.convertToMultiPolygon(newFeat)
ingo@2798: