view flys-backend/contrib/shpimporter/jetties.py @ 5355:480d2f1f61cc

Fix import_rivers script for postgres
author Andre Heinecke <aheinecke@intevation.de>
date Wed, 20 Mar 2013 19:02:10 +0100
parents d086ce6c13d3
children 776427b5aa76
line wrap: on
line source
# -*- 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

http://dive4elements.wald.intevation.org