comparison flys-backend/contrib/shpimporter/boundaries.py @ 3800:69d19995bc3c 2.9.1

merged flys-backend/2.9.1
author Thomas Arendsen Hein <thomas@intevation.de>
date Fri, 28 Sep 2012 12:14:48 +0200
parents 59ca5dab2782
children 5a0225ddae2b
comparison
equal deleted inserted replaced
3786:4adc35aa655c 3800:69d19995bc3c
1 import ogr
2
3 from importer import Importer
4
5 TABLE_NAME="hydr_boundaries"
6 TABLE_NAME_POLY="hydr_boundaries_poly"
7 PATH="Hydrologie/Hydr.Grenzen/Linien"
8 NAME="Hydr. Boundaries"
9
10
11 class HydrBoundary(Importer):
12
13 def getPath(self, base):
14 return "%s/%s" % (base, PATH)
15
16
17 def getTablename(self):
18 return TABLE_NAME
19
20
21 def getName(self):
22 return NAME
23
24
25 def isGeometryValid(self, geomType):
26 return geomType == 2
27
28
29 def isShapeRelevant(self, name, path):
30 return True
31
32
33 def getKind(self, path):
34 if path.find("BfG") > 0:
35 return 1
36 else:
37 return 2
38
39
40 def createNewFeature(self, featureDef, feat, **args):
41 kind = self.getKind(args['path'])
42
43 newFeat = ogr.Feature(featureDef)
44 geometry = feat.GetGeometryRef()
45 geometry.SetCoordinateDimension(2)
46
47 newFeat.SetGeometry(geometry)
48 newFeat.SetField("name", args['name'])
49 newFeat.SetField("kind", kind)
50
51 if self.IsFieldSet(feat, "river_id"):
52 newFeat.SetField("river_id", feat.GetField("river_id"))
53 else:
54 newFeat.SetField("river_id", self.river_id)
55
56 return newFeat
57
58
59
60 class HydrBoundaryPoly(HydrBoundary):
61
62 def getTablename(self):
63 return TABLE_NAME_POLY
64
65
66 def getName(self):
67 return "%s (Polygons)" % NAME
68
69
70 def isGeometryValid(self, geomType):
71 return geomType == 3 or geomType == 6
72
73
74 def createNewFeature(self, featureDef, feat, **args):
75 kind = self.getKind(args['path'])
76
77 newFeat = ogr.Feature(featureDef)
78 geometry = feat.GetGeometryRef()
79 geometry.SetCoordinateDimension(2)
80
81 newFeat.SetGeometry(geometry)
82 newFeat.SetField("name", args['name'])
83 newFeat.SetField("kind", kind)
84
85 if self.IsFieldSet(feat, "river_id"):
86 newFeat.SetField("river_id", feat.GetField("river_id"))
87 else:
88 newFeat.SetField("river_id", self.river_id)
89
90 return newFeat
91

http://dive4elements.wald.intevation.org