Mercurial > dive4elements > river
diff flys-backend/contrib/shpimporter/jetties.py @ 5353:d086ce6c13d3
Add jetties importer
author | Andre Heinecke <aheinecke@intevation.de> |
---|---|
date | Wed, 20 Mar 2013 17:55:53 +0100 |
parents | |
children | 776427b5aa76 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-backend/contrib/shpimporter/jetties.py Wed Mar 20 17:55:53 2013 +0100 @@ -0,0 +1,69 @@ +# -*- coding: utf-8 -*- +import os + +try: + from osgeo import ogr +except ImportError: + import ogr + +from importer import Importer +import utils + +import logging +logger = logging.getLogger("Jetties") + +PATH="Geodaesie/Bauwerke" +NAME="Jetties" + +# strings need to be lowercase +JETTY_KIND = { + "buhnenkopf" : 0, + "buhnenfuß" : 1, + "buhnenwurzel" : 2, + } + +class Jetties(Importer): + fieldmap = { + "^station$" : "km", + "^z$" : "z", + } + + def getPath(self, base): + return "%s/%s" % (base, PATH) + + def getTablename(self): + return "jetties" + + def getName(self): + return "JETTIES" + + def isGeometryValid(self, geomType): + return geomType == ogr.wkbPoint or geomType == ogr.wkbPoint25D + + def isShapeRelevant(self, name, path): + if not path.endswith("Buhnen.shp"): + return False + shp = ogr.Open(path) + return self.isGeometryValid(shp.GetLayerByName(name).GetGeomType()) + + def createNewFeature(self, featureDef, feat, **args): + newFeat = ogr.Feature(featureDef) + geometry = feat.GetGeometryRef() + geometry.SetCoordinateDimension(2) + + self.copyFields(feat, newFeat, self.fieldmap) + + newFeat.SetGeometry(geometry) + + artname = self.searchField("^type$") + if self.IsFieldSet(feat, artname): + self.handled(artname) + kind_id = JETTY_KIND.get(feat.GetField(artname).lower()) + if not kind_id: + logger.warn("Unknown Type: %s" % \ + feat.GetField(artname)) + else: + newFeat.SetField("kind_id", kind_id) + + return newFeat +