annotate backend/contrib/shpimporter/jetties.py @ 5838:5aa05a7a34b7

Rename modules to more fitting names.
author Sascha L. Teichmann <teichmann@intevation.de>
date Thu, 25 Apr 2013 15:23:37 +0200
parents flys-backend/contrib/shpimporter/jetties.py@91b14ade2149
children
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
5357
776427b5aa76 Add updated type mapping for jetties
Andre Heinecke <aheinecke@intevation.de>
parents: 5353
diff changeset
19 # buhnenkopf 0
776427b5aa76 Add updated type mapping for jetties
Andre Heinecke <aheinecke@intevation.de>
parents: 5353
diff changeset
20 # buhnenfuß 1
776427b5aa76 Add updated type mapping for jetties
Andre Heinecke <aheinecke@intevation.de>
parents: 5353
diff changeset
21 # buhnenwurzel 2
5353
d086ce6c13d3 Add jetties importer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
22 JETTY_KIND = {
5357
776427b5aa76 Add updated type mapping for jetties
Andre Heinecke <aheinecke@intevation.de>
parents: 5353
diff changeset
23 "bkl" : 0,
776427b5aa76 Add updated type mapping for jetties
Andre Heinecke <aheinecke@intevation.de>
parents: 5353
diff changeset
24 "bkr" : 0,
5384
5a42ca06b93e Importer act according to specs when importing jetties
Andre Heinecke <aheinecke@intevation.de>
parents: 5357
diff changeset
25 "bk" : 0,
5357
776427b5aa76 Add updated type mapping for jetties
Andre Heinecke <aheinecke@intevation.de>
parents: 5353
diff changeset
26 "bfl" : 1,
776427b5aa76 Add updated type mapping for jetties
Andre Heinecke <aheinecke@intevation.de>
parents: 5353
diff changeset
27 "bfr" : 1,
5384
5a42ca06b93e Importer act according to specs when importing jetties
Andre Heinecke <aheinecke@intevation.de>
parents: 5357
diff changeset
28 "bf" : 1,
5357
776427b5aa76 Add updated type mapping for jetties
Andre Heinecke <aheinecke@intevation.de>
parents: 5353
diff changeset
29 "bwl" : 2,
776427b5aa76 Add updated type mapping for jetties
Andre Heinecke <aheinecke@intevation.de>
parents: 5353
diff changeset
30 "bwr" : 2,
5384
5a42ca06b93e Importer act according to specs when importing jetties
Andre Heinecke <aheinecke@intevation.de>
parents: 5357
diff changeset
31 "bw" : 2,
5353
d086ce6c13d3 Add jetties importer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
32 }
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 class Jetties(Importer):
d086ce6c13d3 Add jetties importer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
35 fieldmap = {
5384
5a42ca06b93e Importer act according to specs when importing jetties
Andre Heinecke <aheinecke@intevation.de>
parents: 5357
diff changeset
36 "^station$" : "km",
5a42ca06b93e Importer act according to specs when importing jetties
Andre Heinecke <aheinecke@intevation.de>
parents: 5357
diff changeset
37 "^km$" : "km",
5a42ca06b93e Importer act according to specs when importing jetties
Andre Heinecke <aheinecke@intevation.de>
parents: 5357
diff changeset
38 "^wsv-km$" : "km",
5a42ca06b93e Importer act according to specs when importing jetties
Andre Heinecke <aheinecke@intevation.de>
parents: 5357
diff changeset
39 "^z$" : "z",
5a42ca06b93e Importer act according to specs when importing jetties
Andre Heinecke <aheinecke@intevation.de>
parents: 5357
diff changeset
40 "^H[oeö]{0,2}he$" : "z",
5a42ca06b93e Importer act according to specs when importing jetties
Andre Heinecke <aheinecke@intevation.de>
parents: 5357
diff changeset
41 "^m+NHN$" : "z",
5353
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
d086ce6c13d3 Add jetties importer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
44 def getPath(self, base):
d086ce6c13d3 Add jetties importer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
45 return "%s/%s" % (base, PATH)
d086ce6c13d3 Add jetties importer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
46
d086ce6c13d3 Add jetties importer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
47 def getTablename(self):
d086ce6c13d3 Add jetties importer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
48 return "jetties"
d086ce6c13d3 Add jetties importer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
49
d086ce6c13d3 Add jetties importer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
50 def getName(self):
d086ce6c13d3 Add jetties importer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
51 return "JETTIES"
d086ce6c13d3 Add jetties importer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
52
d086ce6c13d3 Add jetties importer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
53 def isGeometryValid(self, geomType):
d086ce6c13d3 Add jetties importer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
54 return geomType == ogr.wkbPoint or geomType == ogr.wkbPoint25D
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 def isShapeRelevant(self, name, path):
d086ce6c13d3 Add jetties importer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
57 if not path.endswith("Buhnen.shp"):
d086ce6c13d3 Add jetties importer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
58 return False
d086ce6c13d3 Add jetties importer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
59 shp = ogr.Open(path)
d086ce6c13d3 Add jetties importer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
60 return self.isGeometryValid(shp.GetLayerByName(name).GetGeomType())
d086ce6c13d3 Add jetties importer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
61
d086ce6c13d3 Add jetties importer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
62 def createNewFeature(self, featureDef, feat, **args):
d086ce6c13d3 Add jetties importer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
63 newFeat = ogr.Feature(featureDef)
d086ce6c13d3 Add jetties importer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
64 geometry = feat.GetGeometryRef()
d086ce6c13d3 Add jetties importer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
65 geometry.SetCoordinateDimension(2)
d086ce6c13d3 Add jetties importer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
66
d086ce6c13d3 Add jetties importer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
67 self.copyFields(feat, newFeat, self.fieldmap)
d086ce6c13d3 Add jetties importer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
68
d086ce6c13d3 Add jetties importer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
69 newFeat.SetGeometry(geometry)
d086ce6c13d3 Add jetties importer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
70
5438
91b14ade2149 Set river_id for jetties
Andre Heinecke <aheinecke@intevation.de>
parents: 5384
diff changeset
71 newFeat.SetField("river_id", self.river_id)
91b14ade2149 Set river_id for jetties
Andre Heinecke <aheinecke@intevation.de>
parents: 5384
diff changeset
72
5353
d086ce6c13d3 Add jetties importer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
73 artname = self.searchField("^type$")
d086ce6c13d3 Add jetties importer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
74 if self.IsFieldSet(feat, artname):
d086ce6c13d3 Add jetties importer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
75 self.handled(artname)
d086ce6c13d3 Add jetties importer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
76 kind_id = JETTY_KIND.get(feat.GetField(artname).lower())
5357
776427b5aa76 Add updated type mapping for jetties
Andre Heinecke <aheinecke@intevation.de>
parents: 5353
diff changeset
77 if kind_id == None:
5353
d086ce6c13d3 Add jetties importer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
78 logger.warn("Unknown Type: %s" % \
d086ce6c13d3 Add jetties importer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
79 feat.GetField(artname))
d086ce6c13d3 Add jetties importer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
80 else:
d086ce6c13d3 Add jetties importer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
81 newFeat.SetField("kind_id", kind_id)
d086ce6c13d3 Add jetties importer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
82
d086ce6c13d3 Add jetties importer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
83 return newFeat
d086ce6c13d3 Add jetties importer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
84

http://dive4elements.wald.intevation.org