# HG changeset patch # User Andre Heinecke # Date 1363261551 -3600 # Node ID 3f35d9db48c120e97f2e2f3bfbd31fdcb94b72fe # Parent 8aae8c26844f08cbed86f2366727ebec3f95a8e6 Force UESG to multipolygon and import source field for messungen diff -r 8aae8c26844f -r 3f35d9db48c1 flys-backend/contrib/shpimporter/uesg.py --- a/flys-backend/contrib/shpimporter/uesg.py Thu Mar 14 12:44:04 2013 +0100 +++ b/flys-backend/contrib/shpimporter/uesg.py Thu Mar 14 12:45:51 2013 +0100 @@ -4,7 +4,8 @@ import ogr from importer import Importer - +import os.path +import utils TABLE_NAME="floodmaps" PATH="Hydrologie/UeSG" @@ -26,11 +27,8 @@ def isGeometryValid(self, geomType): - if geomType == 3 or geomType == 6: - return True - else: - return False - + return geomType in [ogr.wkbMultiPolygon, + ogr.wkbPolygon] def getKind(self, path): kind = 0 @@ -54,7 +52,6 @@ def createNewFeature(self, featureDef, feat, **args): kind = self.getKind(args['path']) - newFeat = ogr.Feature(featureDef) newFeat.SetGeometry(feat.GetGeometryRef()) @@ -83,6 +80,11 @@ else: perimeter = 0 + if kind >= 200: + newFeat.SetField("source", + os.path.basename(os.path.dirname(args['path']))) + + groupId = 2 newFeat.SetField("river_id", riverId) @@ -93,5 +95,5 @@ newFeat.SetField("kind", kind) newFeat.SetField("name", args['name']) - return newFeat + return utils.convertToMultiPolygon(newFeat) diff -r 8aae8c26844f -r 3f35d9db48c1 flys-backend/contrib/shpimporter/utils.py --- a/flys-backend/contrib/shpimporter/utils.py Thu Mar 14 12:44:04 2013 +0100 +++ b/flys-backend/contrib/shpimporter/utils.py Thu Mar 14 12:45:51 2013 +0100 @@ -108,3 +108,15 @@ geometry.AssignSpatialReference(srs) feature.SetGeometry(geometry) return feature + +def convertToMultiPolygon(feature): + """ + Converts a feature to a multiline feature. + """ + geometry = feature.GetGeometryRef() + # SRS information is lost while forcing to multiline + srs = geometry.GetSpatialReference() + geometry = ogr.ForceToMultiPolygon(geometry) + geometry.AssignSpatialReference(srs) + feature.SetGeometry(geometry) + return feature