Mercurial > dive4elements > river
comparison flys-backend/contrib/shpimporter/boundaries.py @ 3471:e4250c6e1538 2.8.1
merged flys-backend/2.8.1
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Fri, 28 Sep 2012 12:14:40 +0200 |
parents | b0132e1b9719 |
children | 59ca5dab2782 |
comparison
equal
deleted
inserted
replaced
3468:f37e7e8907cb | 3471:e4250c6e1538 |
---|---|
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 | |
9 | |
10 class HydrBoundary(Importer): | |
11 | |
12 def getPath(self, base): | |
13 return "%s/%s" % (base, PATH) | |
14 | |
15 | |
16 def getTablename(self): | |
17 return TABLE_NAME | |
18 | |
19 | |
20 def isGeometryValid(self, geomType): | |
21 return geomType == 2 | |
22 | |
23 | |
24 def isShapeRelevant(self, name, path): | |
25 return True | |
26 | |
27 | |
28 def getKind(self, path): | |
29 if path.find("BfG") > 0: | |
30 return 1 | |
31 else: | |
32 return 2 | |
33 | |
34 | |
35 def createNewFeature(self, featureDef, feat, **args): | |
36 kind = self.getKind(args['path']) | |
37 | |
38 newFeat = ogr.Feature(featureDef) | |
39 geometry = feat.GetGeometryRef() | |
40 geometry.SetCoordinateDimension(2) | |
41 | |
42 newFeat.SetGeometry(geometry) | |
43 newFeat.SetField("name", args['name']) | |
44 newFeat.SetField("kind", kind) | |
45 | |
46 if self.IsFieldSet(feat, "river_id"): | |
47 newFeat.SetField("river_id", feat.GetField("river_id")) | |
48 else: | |
49 newFeat.SetField("river_id", self.river_id) | |
50 | |
51 return newFeat | |
52 | |
53 | |
54 | |
55 class HydrBoundaryPoly(HydrBoundary): | |
56 | |
57 def getTablename(self): | |
58 return TABLE_NAME_POLY | |
59 | |
60 | |
61 def isGeometryValid(self, geomType): | |
62 return geomType == 3 or geomType == 6 | |
63 | |
64 | |
65 def createNewFeature(self, featureDef, feat, **args): | |
66 kind = self.getKind(args['path']) | |
67 | |
68 newFeat = ogr.Feature(featureDef) | |
69 geometry = feat.GetGeometryRef() | |
70 geometry.SetCoordinateDimension(2) | |
71 | |
72 newFeat.SetGeometry(geometry) | |
73 newFeat.SetField("name", args['name']) | |
74 newFeat.SetField("kind", kind) | |
75 | |
76 if self.IsFieldSet(feat, "river_id"): | |
77 newFeat.SetField("river_id", feat.GetField("river_id")) | |
78 else: | |
79 newFeat.SetField("river_id", self.river_id) | |
80 | |
81 return newFeat | |
82 |