aheinecke@5004: try:
aheinecke@5004:     from osgeo import ogr
aheinecke@5077: except ImportError:
aheinecke@5004:     import ogr
ingo@2853: 
ingo@2853: from importer import Importer
ingo@2853: 
ingo@2853: TABLE_NAME="cross_section_tracks"
ingo@2853: PATH="Geodaesie/Querprofile"
ingo@3654: NAME="Crosssections"
ingo@2853: 
ingo@2853: 
ingo@2853: class CrosssectionTrack(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@2853: 
ingo@2853: 
ingo@3654:     def getName(self):
ingo@3654:         return NAME
ingo@3654: 
ingo@3654: 
ingo@2853:     def isGeometryValid(self, geomType):
ingo@2853:         return geomType == 2
ingo@2853: 
ingo@2853: 
ingo@2853:     def isShapeRelevant(self, name, path):
ingo@2853:         return True
ingo@2853: 
ingo@2853: 
ingo@2853:     def createNewFeature(self, featureDef, feat, **args):
ingo@2853:         newFeat = ogr.Feature(featureDef)
ingo@2853:         newFeat.SetGeometry(feat.GetGeometryRef())
ingo@2861:         newFeat.SetField("name", args['name'])
ingo@2853: 
aheinecke@5242:         if args['path'].lower().endswith("/qps.shp") and \
aheinecke@5242:                 not "sonstige" in args['path'].lower():
aheinecke@5242:             newFeat.SetField("kind_id", 1) # offical
aheinecke@5242:         else:
aheinecke@5242:             newFeat.SetField("kind_id", 0) # misc
aheinecke@5242: 
ingo@2853:         if self.IsFieldSet(feat, "river_id"):
ingo@2853:             newFeat.SetField("river_id", feat.GetField("river_id"))
ingo@2853:         else:
ingo@2853:             newFeat.SetField("river_id", self.river_id)
ingo@2853: 
ingo@2853:         if self.IsFieldSet(feat, "KILOMETER"):
ingo@2853:             newFeat.SetField("km", feat.GetFieldAsDouble("KILOMETER"))
ingo@2853:         elif self.IsFieldSet(feat, "KM"):
ingo@2853:             newFeat.SetField("km", feat.GetFieldAsDouble("KM"))
ingo@2867:         elif self.IsFieldSet(feat, "STATION"):
ingo@2867:             newFeat.SetField("km", feat.GetFieldAsDouble("STATION"))
ingo@2853:         else:
ingo@2853:             return None
ingo@2853: 
ingo@2853:         if self.IsFieldSet(feat, "ELEVATION"):
ingo@2853:             newFeat.SetField("z", feat.GetFieldAsDouble("ELEVATION"))
ingo@2853:         else:
ingo@2853:             newFeat.SetField("z", 0)
ingo@2853: 
ingo@2853:         return newFeat
ingo@2853: