aheinecke@5004: try:
aheinecke@5004:     from osgeo import ogr, osr
aheinecke@5077: except ImportError:
aheinecke@5004:     import ogr, osr
ingo@2853: 
ingo@2853: from importer import Importer
aheinecke@5198: import logging
aheinecke@5198: logger = logging.getLogger("Fixpoints")
aheinecke@5198: fixpoints_no_km_logged=False
ingo@2853: 
ingo@2853: TABLE_NAME="fixpoints"
ingo@2853: PATH="Geodaesie/Festpunkte"
ingo@3654: NAME="Fixpoints"
ingo@2853: 
ingo@2853: 
ingo@2853: class Fixpoint(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 == 1
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@2861:         newFeat  = ogr.Feature(featureDef)
aheinecke@5356: 
ingo@2861:         geometry = feat.GetGeometryRef()
aheinecke@5356:         geometry.SetCoordinateDimension(2)
aheinecke@5356:         newFeat.SetGeometry(geometry)
ingo@2861: 
ingo@2861:         newFeat.SetField("name", args['name'])
ingo@2853: 
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, "KM"):
ingo@2853:             newFeat.SetField("km", feat.GetFieldAsDouble("KM"))
ingo@2861:         elif self.IsFieldSet(feat, "ELBE_KM"):
ingo@2861:             newFeat.SetField("km", feat.GetFieldAsDouble("ELBE_KM"))
ingo@2853:         else:
tom@5302:             global fixpoints_no_km_logged
aheinecke@5198:             if not fixpoints_no_km_logged:
aheinecke@5198:                 logger.error("Could not find KM attribute")
aheinecke@5198:                 fixpoints_no_km_logged = True
ingo@2853:             return None
ingo@2853: 
ingo@2853:         if self.IsFieldSet(feat, "X"):
ingo@2853:             newFeat.SetField("x", feat.GetFieldAsDouble("X"))
ingo@2853: 
ingo@2853:         if self.IsFieldSet(feat, "Y"):
ingo@2853:             newFeat.SetField("y", feat.GetFieldAsDouble("Y"))
ingo@2853: 
ingo@2853:         if self.IsFieldSet(feat, "HPGP"):
ingo@2853:             newFeat.SetField("HPGP", feat.GetField("HPGP"))
tom@5624:         elif self.IsFieldSet(feat, "ART"):
tom@5624:             newFeat.SetField("HPGP", feat.GetField("ART"))
ingo@2853: 
ingo@2853:         return newFeat
ingo@2853: