當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。