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


Python QgsWKBTypes.hasM方法代码示例

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


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

示例1: reclassify

# 需要导入模块: from qgis.core import QgsWKBTypes [as 别名]
# 或者: from qgis.core.QgsWKBTypes import hasM [as 别名]
 def reclassify(self):
     """
     Performs the actual reclassification, moving the geometry to the correct layer along with the specified attributes
     """
     if not self.checkConditions():
         return
     
     somethingMade = False
     reclassifiedFeatures = 0
     
     #button that sent the signal
     self.buttonName = self.sender().text().split(' [')[0]
     (reclassificationLayer, self.category, self.edgvClass) = self.getLayerFromButton(self.buttonName)
     geomType = reclassificationLayer.geometryType()
     hasMValues =  QgsWKBTypes.hasM(int(reclassificationLayer.wkbType()))    #generic check (not every database is implemented as ours)
     hasZValues =  QgsWKBTypes.hasZ(int(reclassificationLayer.wkbType()))    #
     isMulti = QgsWKBTypes.isMultiType(int(reclassificationLayer.wkbType())) #
     mapLayers = self.iface.mapCanvas().layers()
     #we need to get the authid that thefines the ref system of destination layer
     crsSrc = QgsCoordinateReferenceSystem(reclassificationLayer.crs().authid())
     deleteList = []
     for mapLayer in mapLayers:
         if mapLayer.type() != QgsMapLayer.VectorLayer:
             continue
         
         #iterating over selected features
         featList = []
         mapLayerCrs = mapLayer.crs()
         #creating a coordinate transformer (mapLayerCrs to crsSrc)
         coordinateTransformer = QgsCoordinateTransform(mapLayerCrs, crsSrc)
         for feature in mapLayer.selectedFeatures():
             geomList = []
             geom = feature.geometry()
             if geom.type() != geomType:
                 continue
             if 'geometry' in dir(geom):
                 if not hasMValues:
                     geom.geometry().dropMValue()
                 if not hasZValues:
                     geom.geometry().dropZValue()
             if isMulti and not geom.isMultipart():
                 geom.convertToMultiType()
                 geomList.append(geom)
             if not isMulti and geom.isMultipart():
                 #deaggregate here
                 parts = geom.asGeometryCollection()
                 for part in parts:
                     part.convertToSingleType()
                     geomList.append(part)
             else:
                 geomList.append(geom)
             for newGeom in geomList:
                 #creating a new feature according to the reclassification layer
                 newFeature = QgsFeature(reclassificationLayer.pendingFields())
                 #transforming the geometry to the correct crs
                 geom.transform(coordinateTransformer)
                 #setting the geometry
                 newFeature.setGeometry(newGeom)
                 #setting the attributes using the reclassification dictionary
                 newFeature = self.setFeatureAttributes(newFeature, oldFeat = feature)
                 #adding the newly created feature to the addition list
                 featList.append(newFeature)
                 somethingMade = True
                 deleteList.append({'originalLyr':mapLayer,'featid':feature.id()})
         #actual feature insertion
         reclassificationLayer.addFeatures(featList, False)
         reclassifiedFeatures += len(featList)
     
     for item in deleteList:
         item['originalLyr'].startEditing()
         item['originalLyr'].deleteFeature(item['featid'])
     
     if somethingMade:
         self.iface.messageBar().pushMessage(self.tr('Information!'), self.tr('{} features reclassified with success!').format(reclassifiedFeatures), level=QgsMessageBar.INFO, duration=3)
开发者ID:lcoandrade,项目名称:DsgTools,代码行数:76,代码来源:field_toolbox.py


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