当前位置: 首页>>代码示例>>Python>>正文


Python FToolsUtils.combineVectorFields方法代码示例

本文整理汇总了Python中sextante.algs.ftools.FToolsUtils.combineVectorFields方法的典型用法代码示例。如果您正苦于以下问题:Python FToolsUtils.combineVectorFields方法的具体用法?Python FToolsUtils.combineVectorFields怎么用?Python FToolsUtils.combineVectorFields使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sextante.algs.ftools.FToolsUtils的用法示例。


在下文中一共展示了FToolsUtils.combineVectorFields方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: processAlgorithm

# 需要导入模块: from sextante.algs.ftools import FToolsUtils [as 别名]
# 或者: from sextante.algs.ftools.FToolsUtils import combineVectorFields [as 别名]
    def processAlgorithm(self, progress):
        vlayerA = QGisLayers.getObjectFromUri(self.getParameterValue(Intersection.INPUT))
        vlayerB = QGisLayers.getObjectFromUri(self.getParameterValue(Intersection.INPUT2))
        vproviderA = vlayerA.dataProvider()

        fields = utils.combineVectorFields(vlayerA, vlayerB)
        writer = self.getOutputFromName(Intersection.OUTPUT).getVectorWriter(fields, vproviderA.geometryType(), vproviderA.crs() )
        inFeatA = QgsFeature()
        inFeatB = QgsFeature()
        outFeat = QgsFeature()
        index = utils.createSpatialIndex(vlayerB)
        nElement = 0
        selectionA = QGisLayers.features(vlayerA)
        nFeat = len(selectionA)
        for inFeatA in selectionA:
            nElement += 1
            progress.setPercentage(nElement/float(nFeat) * 100)
            geom = QgsGeometry( inFeatA.geometry() )
            atMapA = inFeatA.attributes()
            intersects = index.intersects( geom.boundingBox() )
            for id in intersects:
                vlayerB.featureAtId( int( id ), inFeatB , True)
                tmpGeom = QgsGeometry( inFeatB.geometry() )
                try:
                    if geom.intersects( tmpGeom ):
                        atMapB = inFeatB.attributes()
                        int_geom = QgsGeometry( geom.intersection( tmpGeom ) )
                        if int_geom.wkbType() == 7:
                            int_com = geom.combine( tmpGeom )
                            int_sym = geom.symDifference( tmpGeom )
                            int_geom = QgsGeometry( int_com.difference( int_sym ) )
                    try:
                        outFeat.setGeometry( int_geom )
                        attrs = []
                        attrs.extend(atMapA)
                        attrs.extend(atMapB)
                        outFeat.setAttributes(attrs)
                        writer.addFeature( outFeat )
                    except:
                        raise GeoAlgorithmExecutionException("Feature exception while computing intersection")
                except:
                    raise GeoAlgorithmExecutionException("Geometry exception while computing intersection")


        del writer
开发者ID:badcock4412,项目名称:Quantum-GIS,代码行数:47,代码来源:Intersection.py

示例2: processAlgorithm

# 需要导入模块: from sextante.algs.ftools import FToolsUtils [as 别名]
# 或者: from sextante.algs.ftools.FToolsUtils import combineVectorFields [as 别名]
    def processAlgorithm(self, progress):
        vlayerA = QGisLayers.getObjectFromUri(self.getParameterValue(Union.INPUT))
        vlayerB = QGisLayers.getObjectFromUri(self.getParameterValue(Union.INPUT2))
        GEOS_EXCEPT = True
        FEATURE_EXCEPT = True
        vproviderA = vlayerA.dataProvider()

        fields = utils.combineVectorFields(vlayerA, vlayerB )
        names = [field.name() for field in fields]
        SextanteLog.addToLog(SextanteLog.LOG_INFO, str(names))
        writer = self.getOutputFromName(Union.OUTPUT).getVectorWriter(fields, vproviderA.geometryType(), vproviderA.crs() )
        inFeatA = QgsFeature()
        inFeatB = QgsFeature()
        outFeat = QgsFeature()
        indexA = utils.createSpatialIndex(vlayerB)
        indexB = utils.createSpatialIndex(vlayerA)

        count = 0
        nElement = 0
        featuresA = QGisLayers.features(vlayerA)
        nFeat = len(featuresA)
        for inFeatA in featuresA:
          progress.setPercentage(nElement/float(nFeat) * 50)
          nElement += 1
          found = False
          geom = QgsGeometry( inFeatA.geometry() )
          diff_geom = QgsGeometry( geom )
          atMapA = inFeatA.attributes()
          intersects = indexA.intersects( geom.boundingBox() )
          if len( intersects ) < 1:
            try:
              outFeat.setGeometry( geom )
              outFeat.setAttributes( atMapA )
              writer.addFeature( outFeat )
            except:
              # this really shouldn't happen, as we
              # haven't edited the input geom at all
              raise GeoAlgorithmExecutionException("Feature exception while computing union")
          else:
            for id in intersects:
                count += 1
                request = QgsFeatureRequest().setFilterFid(id)
                inFeatB = vlayerB.getFeatures(request).next()
                atMapB = inFeatB.attributes()
                tmpGeom = QgsGeometry( inFeatB.geometry() )

                if geom.intersects( tmpGeom ):
                  found = True
                  int_geom = geom.intersection( tmpGeom )

                  if int_geom is None:
                    # There was a problem creating the intersection
                    raise GeoAlgorithmExecutionException("Geometry exception while computing intersection")
                  else:
                    int_geom = QgsGeometry(int_geom)

                  if diff_geom.intersects( tmpGeom ):
                    diff_geom = diff_geom.difference( tmpGeom )
                    if diff_geom is None:
                      # It's possible there was an error here?
                      diff_geom = QgsGeometry()
                    else:
                      diff_geom = QgsGeometry(diff_geom)

                  if int_geom.wkbType() == 0:
                    # intersection produced different geomety types
                    temp_list = int_geom.asGeometryCollection()
                    for i in temp_list:
                      if i.type() == geom.type():
                          int_geom = QgsGeometry( i )
                  try:
                    outFeat.setGeometry( int_geom )
                    attrs = []
                    attrs.extend(atMapA)
                    attrs.extend(atMapB)
                    outFeat.setAttributes(attrs)
                    writer.addFeature( outFeat )
                  except Exception, err:
                    raise GeoAlgorithmExecutionException("Feature exception while computing union")
                else:
                  # this only happends if the bounding box
                  # intersects, but the geometry doesn't
                  try:
                    outFeat.setGeometry( geom )
                    outFeat.setAttributes( atMapA )
                    writer.addFeature( outFeat )
                  except:
                    # also shoudn't ever happen
                    raise GeoAlgorithmExecutionException("Feature exception while computing union")


            if found:
              try:
                if diff_geom.wkbType() == 0:
                  temp_list = diff_geom.asGeometryCollection()
                  for i in temp_list:
                    if i.type() == geom.type():
                        diff_geom = QgsGeometry( i )
                outFeat.setGeometry( diff_geom )
                outFeat.setAttributes( atMapA )
#.........这里部分代码省略.........
开发者ID:Adam-Brown,项目名称:Quantum-GIS,代码行数:103,代码来源:Union.py

示例3: processAlgorithm

# 需要导入模块: from sextante.algs.ftools import FToolsUtils [as 别名]
# 或者: from sextante.algs.ftools.FToolsUtils import combineVectorFields [as 别名]
    def processAlgorithm(self, progress):
        vlayerA = QGisLayers.getObjectFromUri(self.getParameterValue(Intersection.INPUT))
        vlayerB = QGisLayers.getObjectFromUri(self.getParameterValue(Intersection.INPUT2))
        GEOS_EXCEPT = True
        FEATURE_EXCEPT = True
        vproviderA = vlayerA.dataProvider()       
        vproviderB = vlayerB.dataProvider()        
        
        # check for crs compatibility
        crsA = vproviderA.crs()
        crsB = vproviderB.crs()
        if not crsA.isValid() or not crsB.isValid():
            SextanteLog.addToLog(SextanteLog.LOG_WARNING, "Intersection. Invalid CRS. Results might be unexpected")
        else:
            if not crsA != crsB:
                SextanteLog.addToLog(SextanteLog.LOG_WARNING, "Intersection. Non-matching CRSs. Results might be unexpected")
        fields = utils.combineVectorFields(vlayerA, vlayerB)
        #=======================================================================
        # longNames = ftools_utils.checkFieldNameLength( fields )
        # if not longNames.isEmpty():
        #    raise GeoAlgorithmExecutionException("Following field names are longer than 10 characters:\n" +  longNames.join('\n') )
        #=======================================================================
        writer = self.getOutputFromName(Intersection.OUTPUT).getVectorWriter(fields, vproviderA.geometryType(), vproviderA.crs() )
        inFeatA = QgsFeature()
        inFeatB = QgsFeature()
        outFeat = QgsFeature()
        index = utils.createSpatialIndex(vlayerB)
        nElement = 0
        selectionA = QGisLayers.features(vlayerA)
        nFeat = len(selectionA)        
        for inFeatA in selectionA:
            nElement += 1
            progress.setPercentage(nElement/float(nFeat) * 100)
            geom = QgsGeometry( inFeatA.geometry() )
            atMapA = inFeatA.attributes()
            intersects = index.intersects( geom.boundingBox() )
            for id in intersects:
                vlayerB.featureAtId( int( id ), inFeatB , True)
                tmpGeom = QgsGeometry( inFeatB.geometry() )
                try:
                    if geom.intersects( tmpGeom ):
                        atMapB = inFeatB.attributes()
                        int_geom = QgsGeometry( geom.intersection( tmpGeom ) )
                        if int_geom.wkbType() == 7:
                            int_com = geom.combine( tmpGeom )
                            int_sym = geom.symDifference( tmpGeom )
                            int_geom = QgsGeometry( int_com.difference( int_sym ) )
                    try:
                        outFeat.setGeometry( int_geom )
                        outFeat.setAttributes( atMapA.extend( atMapB ) )
                        writer.addFeature( outFeat )
                    except:
                        FEATURE_EXCEPT = False
                        continue
                except:
                    GEOS_EXCEPT = False
                    break

        del writer
        if not GEOS_EXCEPT:
            SextanteLog.addToLog(SextanteLog.LOG_WARNING, "Geometry exception while computing intersection")
        if not FEATURE_EXCEPT:
            SextanteLog.addToLog(SextanteLog.LOG_WARNING, "Feature exception while computing intersection")
开发者ID:sawajid,项目名称:Quantum-GIS,代码行数:65,代码来源:Intersection.py

示例4: processAlgorithm

# 需要导入模块: from sextante.algs.ftools import FToolsUtils [as 别名]
# 或者: from sextante.algs.ftools.FToolsUtils import combineVectorFields [as 别名]
    def processAlgorithm(self, progress):
        vlayerA = QGisLayers.getObjectFromUri(self.getParameterValue(Union.INPUT))
        vlayerB = QGisLayers.getObjectFromUri(self.getParameterValue(Union.INPUT2))
        GEOS_EXCEPT = True
        FEATURE_EXCEPT = True
        vproviderA = vlayerA.dataProvider()
        allAttrsA = vproviderA.attributeIndexes()
        vproviderA.select( allAttrsA )
        vproviderB = vlayerB.dataProvider()
        allAttrsB = vproviderB.attributeIndexes()
        vproviderB.select( allAttrsB )

        # check for crs compatibility
        crsA = vproviderA.crs()
        crsB = vproviderB.crs()
        if not crsA.isValid() or not crsB.isValid():
            SextanteLog.addToLog(SextanteLog.LOG_WARNING, "Union. Invalid CRS. Results might be unexpected")
        else:
            if not crsA != crsB:
                SextanteLog.addToLog(SextanteLog.LOG_WARNING, "Union. Non-matching CRSs. Results might be unexpected")
        fields = utils.combineVectorFields(vlayerA, vlayerB )
        #longNames = ftools_utils.checkFieldNameLength( fields )
        #if not longNames.isEmpty():
            #raise GeoAlgorithmExecutionException("Following field names are longer than 10 characters:\n" +  longNames.join('\n') )
        writer = self.getOutputFromName(Union.OUTPUT).getVectorWriter(fields, vproviderA.geometryType(), vproviderA.crs() )
        inFeatA = QgsFeature()
        inFeatB = QgsFeature()
        outFeat = QgsFeature()
        indexA = utils.createSpatialIndex(vlayerB)
        indexB = utils.createSpatialIndex(vlayerA)
        vproviderA.rewind()
        count = 0
        nElement = 0

        featuresA = QGisLayers.features(vlayerA)
        nFeat = len(featuresA)
        for inFeatA in featuresA:
          progress.setPercentage(nElement/float(nFeat) * 50)
          nElement += 1
          found = False
          geom = QgsGeometry( inFeatA.geometry() )
          diff_geom = QgsGeometry( geom )
          atMapA = inFeatA.attributes()
          intersects = indexA.intersects( geom.boundingBox() )
          if len( intersects ) < 1:
            try:
              outFeat.setGeometry( geom )
              outFeat.setAttributes( atMapA )
              writer.addFeature( outFeat )
            except:
              # this really shouldn't happen, as we
              # haven't edited the input geom at all
              FEATURE_EXCEPT = False
          else:
            for id in intersects:
              count += 1
              vproviderB.featureAtId( int( id ), inFeatB , True, allAttrsB )
              atMapB = inFeatB.attributes()
              tmpGeom = QgsGeometry( inFeatB.geometry() )
              try:
                if geom.intersects( tmpGeom ):
                  found = True
                  int_geom = geom.intersection( tmpGeom )

                  if int_geom is None:
                    # There was a problem creating the intersection
                    GEOS_EXCEPT = False
                    int_geom = QgsGeometry()
                  else:
                    int_geom = QgsGeometry(int_geom)

                  if diff_geom.intersects( tmpGeom ):
                    diff_geom = diff_geom.difference( tmpGeom )
                    if diff_geom is None:
                      # It's possible there was an error here?
                      diff_geom = QgsGeometry()
                    else:
                      diff_geom = QgsGeometry(diff_geom)

                  if int_geom.wkbType() == 0:
                    # intersection produced different geomety types
                    temp_list = int_geom.asGeometryCollection()
                    for i in temp_list:
                      if i.type() == geom.type():
                          int_geom = QgsGeometry( i )
                  try:
                    outFeat.setGeometry( int_geom )
                    outFeat.setAttributes( atMapA.extend( atMapB ) )
                    writer.addFeature( outFeat )
                  except Exception, err:
                    FEATURE_EXCEPT = False
                else:
                  # this only happends if the bounding box
                  # intersects, but the geometry doesn't
                  try:
                    outFeat.setGeometry( geom )
                    outFeat.setAttributes( atMapA )
                    writer.addFeature( outFeat )
                  except:
                    # also shoudn't ever happen
#.........这里部分代码省略.........
开发者ID:sawajid,项目名称:Quantum-GIS,代码行数:103,代码来源:Union.py


注:本文中的sextante.algs.ftools.FToolsUtils.combineVectorFields方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。