Mercurial > dive4elements > river
comparison flys-backend/contrib/shpimporter/boundaries.py @ 4952:5a0225ddae2b dami
Importer: Add sectie and strover to boundaries and select more
files for import
author | Andre Heinecke <aheinecke@intevation.de> |
---|---|
date | Fri, 01 Feb 2013 10:38:26 +0100 |
parents | 59ca5dab2782 |
children | f1c01fecf194 |
comparison
equal
deleted
inserted
replaced
4951:23a090b41543 | 4952:5a0225ddae2b |
---|---|
2 | 2 |
3 from importer import Importer | 3 from importer import Importer |
4 | 4 |
5 TABLE_NAME="hydr_boundaries" | 5 TABLE_NAME="hydr_boundaries" |
6 TABLE_NAME_POLY="hydr_boundaries_poly" | 6 TABLE_NAME_POLY="hydr_boundaries_poly" |
7 PATH="Hydrologie/Hydr.Grenzen/Linien" | 7 PATH="Hydrologie/Hydr.Grenzen" |
8 NAME="Hydr. Boundaries" | 8 NAME="Hydr. Boundaries" |
9 | 9 |
10 | 10 |
11 class HydrBoundary(Importer): | 11 class HydrBoundary(Importer): |
12 | 12 |
13 def getPath(self, base): | 13 def getPath(self, base): |
14 return "%s/%s" % (base, PATH) | 14 return "%s/%s" % (base, PATH) |
15 | 15 |
16 | |
17 def getTablename(self): | 16 def getTablename(self): |
18 return TABLE_NAME | 17 return TABLE_NAME |
19 | |
20 | 18 |
21 def getName(self): | 19 def getName(self): |
22 return NAME | 20 return NAME |
23 | 21 |
22 def isGeometryValid(self, geomType): | |
23 return geomType == ogr.wkbLineString | |
24 | |
25 def isShapeRelevant(self, name, path): | |
26 shp = ogr.Open(path) | |
27 if self.isGeometryValid(shp.GetLayerByName(name).GetGeomType()) and \ | |
28 self.getKind(path) > 0: | |
29 return True | |
30 else: | |
31 return False | |
32 | |
33 def getKind(self, path): | |
34 if "linien/bfg" in path.lower(): | |
35 return 1 | |
36 elif "linien/land" in path.lower(): | |
37 return 2 | |
38 elif "/sonstige/" in path.lower(): | |
39 return 3 | |
40 else: | |
41 return 0 | |
42 | |
43 def createNewFeature(self, featureDef, feat, **args): | |
44 kind = self.getKind(args['path']) | |
45 | |
46 newFeat = ogr.Feature(featureDef) | |
47 geometry = feat.GetGeometryRef() | |
48 geometry.SetCoordinateDimension(2) | |
49 | |
50 newFeat.SetGeometry(geometry) | |
51 newFeat.SetField("name", args['name']) | |
52 newFeat.SetField("kind", kind) | |
53 if self.IsFieldSet(feat, "SECTIE"): | |
54 newFeat.SetField("sectie", feat.GetField("SECTIE")) | |
55 | |
56 if self.IsFieldSet(feat, "SOBEK"): | |
57 newFeat.SetField("sobek", feat.GetField("SOBEK")) | |
58 | |
59 if self.IsFieldSet(feat, "river_id"): | |
60 newFeat.SetField("river_id", feat.GetField("river_id")) | |
61 else: | |
62 newFeat.SetField("river_id", self.river_id) | |
63 | |
64 return newFeat | |
65 | |
66 class HydrBoundaryPoly(HydrBoundary): | |
67 | |
68 def getTablename(self): | |
69 return TABLE_NAME_POLY | |
70 | |
71 def getName(self): | |
72 return "%s (Polygons)" % NAME | |
24 | 73 |
25 def isGeometryValid(self, geomType): | 74 def isGeometryValid(self, geomType): |
26 return geomType == 2 | 75 return geomType == ogr.wkbPolygon or geomType == ogr.wkbMultiPolygon |
27 | |
28 | 76 |
29 def isShapeRelevant(self, name, path): | 77 def isShapeRelevant(self, name, path): |
30 return True | 78 shp = ogr.Open(path) |
31 | 79 if self.isGeometryValid(shp.GetLayerByName(name).GetGeomType()) and \ |
32 | 80 self.getKind(path) > 0: |
33 def getKind(self, path): | 81 return True |
34 if path.find("BfG") > 0: | |
35 return 1 | |
36 else: | 82 else: |
37 return 2 | 83 return False |
38 | |
39 | 84 |
40 def createNewFeature(self, featureDef, feat, **args): | 85 def createNewFeature(self, featureDef, feat, **args): |
41 kind = self.getKind(args['path']) | 86 kind = self.getKind(args['path']) |
42 | 87 |
43 newFeat = ogr.Feature(featureDef) | 88 newFeat = ogr.Feature(featureDef) |
46 | 91 |
47 newFeat.SetGeometry(geometry) | 92 newFeat.SetGeometry(geometry) |
48 newFeat.SetField("name", args['name']) | 93 newFeat.SetField("name", args['name']) |
49 newFeat.SetField("kind", kind) | 94 newFeat.SetField("kind", kind) |
50 | 95 |
51 if self.IsFieldSet(feat, "river_id"): | 96 if self.IsFieldSet(feat, "SECTIE"): |
52 newFeat.SetField("river_id", feat.GetField("river_id")) | 97 newFeat.SetField("sectie", feat.GetField("SECTIE")) |
53 else: | |
54 newFeat.SetField("river_id", self.river_id) | |
55 | 98 |
56 return newFeat | 99 if self.IsFieldSet(feat, "SOBEK"): |
100 newFeat.SetField("sobek", feat.GetField("SOBEK")) | |
57 | 101 |
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 | 102 |
85 if self.IsFieldSet(feat, "river_id"): | 103 if self.IsFieldSet(feat, "river_id"): |
86 newFeat.SetField("river_id", feat.GetField("river_id")) | 104 newFeat.SetField("river_id", feat.GetField("river_id")) |
87 else: | 105 else: |
88 newFeat.SetField("river_id", self.river_id) | 106 newFeat.SetField("river_id", self.river_id) |