comparison flys-backend/contrib/shpimporter/buildings.py @ 5387:974f0e3dcc28

Import buildings according to specification
author Andre Heinecke <aheinecke@intevation.de>
date Fri, 22 Mar 2013 17:32:09 +0100
parents c5187ab9f571
children ff11b178f152
comparison
equal deleted inserted replaced
5386:6c2751c17869 5387:974f0e3dcc28
1 # -*- coding: utf-8 -*-
1 try: 2 try:
2 from osgeo import ogr 3 from osgeo import ogr
3 except ImportError: 4 except ImportError:
4 import ogr 5 import ogr
5 6
7 8
8 TABLE_NAME="buildings" 9 TABLE_NAME="buildings"
9 PATH="Geodaesie/Bauwerke" 10 PATH="Geodaesie/Bauwerke"
10 NAME="Buildings" 11 NAME="Buildings"
11 12
13 BUILDING_KINDS= {
14 "sonstige" : 0,
15 "brücken" : 1,
16 "wehre" : 2,
17 "pegel" : 3,
18 }
12 19
13 class Building(Importer): 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 }
14 31
15 def getPath(self, base): 32 def getPath(self, base):
16 return "%s/%s" % (base, PATH) 33 return "%s/%s" % (base, PATH)
17 34
18 35
27 def isGeometryValid(self, geomType): 44 def isGeometryValid(self, geomType):
28 return geomType == 2 45 return geomType == 2
29 46
30 47
31 def isShapeRelevant(self, name, path): 48 def isShapeRelevant(self, name, path):
32 return True 49 return "buhnen.shp" not in name.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 if self.searchValue(feat, "^br[ueü]{0,2}cke[n]{0,1}$"):
66 return BUILDING_KINDS["brücken"]
67 if self.searchValue(feat, "^wehr[e]{0,1}$"):
68 return BUILDING_KINDS["wehre"]
69
70 return BUILDING_KINDS["sonstige"]
33 71
34 72
35 def createNewFeature(self, featureDef, feat, **args): 73 def createNewFeature(self, featureDef, feat, **args):
36 newFeat = ogr.Feature(featureDef) 74 newFeat = ogr.Feature(featureDef)
37 newFeat.SetGeometry(feat.GetGeometryRef()) 75 geometry = feat.GetGeometryRef()
76 geometry.SetCoordinateDimension(2)
77 newFeat.SetGeometry(geometry)
38 78
39 if self.IsFieldSet(feat, "river_id"): 79 self.copyFields(feat, newFeat, self.fieldmap)
40 newFeat.SetField("river_id", feat.GetField("river_id"))
41 else:
42 newFeat.SetField("river_id", self.river_id)
43 80
44 if self.IsFieldSet(feat, "Name"): 81 newFeat.SetField("kind_id", self.getKind(feat, args['path']))
45 newFeat.SetField("name", feat.GetField("Name")) 82 newFeat.SetField("name", args["name"])
46 elif self.IsFieldSet(feat, "KWNAAM"): 83
47 newFeat.SetField("name", feat.GetField("KWNAAM")) 84 newFeat.SetField("river_id", self.river_id)
48 85
49 return newFeat 86 return newFeat
50 87

http://dive4elements.wald.intevation.org