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

http://dive4elements.wald.intevation.org