comparison backend/contrib/shpimporter/buildings.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/buildings.py@b91cc44312b7
children
comparison
equal deleted inserted replaced
5837:d9901a08d0a6 5838:5aa05a7a34b7
1 # -*- coding: utf-8 -*-
2 try:
3 from osgeo import ogr
4 except ImportError:
5 import ogr
6
7 from importer import Importer
8
9 TABLE_NAME="buildings"
10 PATH="Geodaesie/Bauwerke"
11 NAME="Buildings"
12
13 BUILDING_KINDS= {
14 "sonstige" : 0,
15 "brücken" : 1,
16 "wehre" : 2,
17 "pegel" : 3,
18 }
19
20 class Building(Importer):
21 fieldmap = {
22 "^station$" : "km",
23 "^km$" : "km",
24 "^wsv-km$" : "km",
25 "^z$" : "z",
26 "^H[oeö]{0,2}he$" : "z",
27 "^m+NHN$" : "z",
28 "^KWNAAM$" : "description",
29 "^Name$" : "description"
30 }
31
32 def getPath(self, base):
33 return "%s/%s" % (base, PATH)
34
35
36 def getTablename(self):
37 return TABLE_NAME
38
39
40 def getName(self):
41 return NAME
42
43
44 def isGeometryValid(self, geomType):
45 return geomType == 2
46
47
48 def isShapeRelevant(self, name, path):
49 return "buhnen.shp" not in path.lower()
50
51 def getKind(self, feat, path):
52 # First try to resolve it with the filename
53 for fname in ["brücke.shp", "bruecke.shp",
54 "brücken.shp", "bruecken.shp"]:
55 if path.lower().endswith(fname):
56 return BUILDING_KINDS["brücken"]
57 for fname in ["wehr.shp", "wehre.shp"]:
58 if path.lower().endswith(fname):
59 return BUILDING_KINDS["wehre"]
60 for fname in ["pegel.shp"]:
61 if path.lower().endswith(fname):
62 return BUILDING_KINDS["pegel"]
63
64 # Now it gets ugly when we search all attributes
65 ret = self.searchValue(feat, "^br[ueü]{0,2}cke[n]{0,1}$")
66 if ret:
67 self.handled(ret)
68 return BUILDING_KINDS["brücken"]
69 ret = self.searchValue(feat, "^wehr[e]{0,1}$")
70 if ret:
71 self.handled(ret)
72 return BUILDING_KINDS["wehre"]
73
74 return BUILDING_KINDS["sonstige"]
75
76
77 def createNewFeature(self, featureDef, feat, **args):
78 newFeat = ogr.Feature(featureDef)
79 geometry = feat.GetGeometryRef()
80 geometry.SetCoordinateDimension(2)
81 newFeat.SetGeometry(geometry)
82
83 self.copyFields(feat, newFeat, self.fieldmap)
84
85 newFeat.SetField("kind_id", self.getKind(feat, args['path']))
86 newFeat.SetField("name", args["name"])
87
88 newFeat.SetField("river_id", self.river_id)
89
90 return newFeat
91

http://dive4elements.wald.intevation.org