Mercurial > dive4elements > river
comparison flys-backend/contrib/shpimporter/boundaries.py @ 2861:b0132e1b9719
Added further shape importers and added the option to reproject shapes during the import process.
flys-backend/trunk@4342 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Thu, 03 May 2012 14:19:52 +0000 |
parents | |
children | 59ca5dab2782 |
comparison
equal
deleted
inserted
replaced
2860:2f874d14ac68 | 2861:b0132e1b9719 |
---|---|
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 |