comparison 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
comparison
equal deleted inserted replaced
5352:f1009aa7dcd1 5353:d086ce6c13d3
1 # -*- coding: utf-8 -*-
2 import os
3
4 try:
5 from osgeo import ogr
6 except ImportError:
7 import ogr
8
9 from importer import Importer
10 import utils
11
12 import logging
13 logger = logging.getLogger("Jetties")
14
15 PATH="Geodaesie/Bauwerke"
16 NAME="Jetties"
17
18 # strings need to be lowercase
19 JETTY_KIND = {
20 "buhnenkopf" : 0,
21 "buhnenfuß" : 1,
22 "buhnenwurzel" : 2,
23 }
24
25 class Jetties(Importer):
26 fieldmap = {
27 "^station$" : "km",
28 "^z$" : "z",
29 }
30
31 def getPath(self, base):
32 return "%s/%s" % (base, PATH)
33
34 def getTablename(self):
35 return "jetties"
36
37 def getName(self):
38 return "JETTIES"
39
40 def isGeometryValid(self, geomType):
41 return geomType == ogr.wkbPoint or geomType == ogr.wkbPoint25D
42
43 def isShapeRelevant(self, name, path):
44 if not path.endswith("Buhnen.shp"):
45 return False
46 shp = ogr.Open(path)
47 return self.isGeometryValid(shp.GetLayerByName(name).GetGeomType())
48
49 def createNewFeature(self, featureDef, feat, **args):
50 newFeat = ogr.Feature(featureDef)
51 geometry = feat.GetGeometryRef()
52 geometry.SetCoordinateDimension(2)
53
54 self.copyFields(feat, newFeat, self.fieldmap)
55
56 newFeat.SetGeometry(geometry)
57
58 artname = self.searchField("^type$")
59 if self.IsFieldSet(feat, artname):
60 self.handled(artname)
61 kind_id = JETTY_KIND.get(feat.GetField(artname).lower())
62 if not kind_id:
63 logger.warn("Unknown Type: %s" % \
64 feat.GetField(artname))
65 else:
66 newFeat.SetField("kind_id", kind_id)
67
68 return newFeat
69

http://dive4elements.wald.intevation.org