Mercurial > dive4elements > river
comparison flys-backend/contrib/shpimporter/boundaries.py @ 5182:8aac391871f9
SCHEME CHANGE: Hydr.Boundaries are now three dimensional multilinestrings
author | Andre Heinecke <aheinecke@intevation.de> |
---|---|
date | Thu, 07 Mar 2013 10:53:44 +0100 |
parents | c5187ab9f571 |
children | 71a24278322c |
comparison
equal
deleted
inserted
replaced
5181:9d36ddf7dbd3 | 5182:8aac391871f9 |
---|---|
2 from osgeo import ogr | 2 from osgeo import ogr |
3 except ImportError: | 3 except ImportError: |
4 import ogr | 4 import ogr |
5 | 5 |
6 from importer import Importer | 6 from importer import Importer |
7 import utils | |
7 | 8 |
8 TABLE_NAME="hydr_boundaries" | 9 TABLE_NAME="hydr_boundaries" |
9 TABLE_NAME_POLY="hydr_boundaries_poly" | 10 TABLE_NAME_POLY="hydr_boundaries_poly" |
10 PATH="Hydrologie/Hydr.Grenzen" | 11 PATH="Hydrologie/Hydr.Grenzen" |
11 NAME="Hydr. Boundaries" | 12 NAME="Hydr. Boundaries" |
21 | 22 |
22 def getName(self): | 23 def getName(self): |
23 return NAME | 24 return NAME |
24 | 25 |
25 def isGeometryValid(self, geomType): | 26 def isGeometryValid(self, geomType): |
26 return geomType == ogr.wkbLineString | 27 return geomType in [ogr.wkbLineString, |
28 ogr.wkbLineString25D, | |
29 ogr.wkbMultiLineString25D, | |
30 ogr.wkbMultiLineString] | |
27 | 31 |
28 def isShapeRelevant(self, name, path): | 32 def isShapeRelevant(self, name, path): |
29 shp = ogr.Open(path) | 33 shp = ogr.Open(path) |
30 if self.isGeometryValid(shp.GetLayerByName(name).GetGeomType()) and \ | 34 if self.isGeometryValid(shp.GetLayerByName(name).GetGeomType()) and \ |
31 self.getKind(path) > 0: | 35 self.getKind(path) > 0: |
46 def createNewFeature(self, featureDef, feat, **args): | 50 def createNewFeature(self, featureDef, feat, **args): |
47 kind = self.getKind(args['path']) | 51 kind = self.getKind(args['path']) |
48 | 52 |
49 newFeat = ogr.Feature(featureDef) | 53 newFeat = ogr.Feature(featureDef) |
50 geometry = feat.GetGeometryRef() | 54 geometry = feat.GetGeometryRef() |
51 geometry.SetCoordinateDimension(2) | 55 geometry.SetCoordinateDimension(3) |
52 | 56 |
53 newFeat.SetGeometry(geometry) | 57 newFeat.SetGeometry(geometry) |
54 newFeat.SetField("name", args['name']) | 58 newFeat.SetField("name", args['name']) |
55 newFeat.SetField("kind", kind) | 59 newFeat.SetField("kind", kind) |
56 if self.IsFieldSet(feat, "SECTIE"): | 60 if self.IsFieldSet(feat, "SECTIE"): |
62 if self.IsFieldSet(feat, "river_id"): | 66 if self.IsFieldSet(feat, "river_id"): |
63 newFeat.SetField("river_id", feat.GetField("river_id")) | 67 newFeat.SetField("river_id", feat.GetField("river_id")) |
64 else: | 68 else: |
65 newFeat.SetField("river_id", self.river_id) | 69 newFeat.SetField("river_id", self.river_id) |
66 | 70 |
67 return newFeat | 71 return utils.convertToMultiLine(newFeat) |
68 | 72 |
69 class HydrBoundaryPoly(HydrBoundary): | 73 class HydrBoundaryPoly(HydrBoundary): |
70 | 74 |
71 def getTablename(self): | 75 def getTablename(self): |
72 return TABLE_NAME_POLY | 76 return TABLE_NAME_POLY |