本文整理匯總了Python中qgis.core.QgsWKBTypes.isMultiType方法的典型用法代碼示例。如果您正苦於以下問題:Python QgsWKBTypes.isMultiType方法的具體用法?Python QgsWKBTypes.isMultiType怎麽用?Python QgsWKBTypes.isMultiType使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類qgis.core.QgsWKBTypes
的用法示例。
在下文中一共展示了QgsWKBTypes.isMultiType方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: getFeatureNodes
# 需要導入模塊: from qgis.core import QgsWKBTypes [as 別名]
# 或者: from qgis.core.QgsWKBTypes import isMultiType [as 別名]
def getFeatureNodes(self, layer, feature, geomType=None):
"""
Inverts the flow from a given feature. THE GIVEN FEATURE IS ALTERED. Standard behaviour is to not
refresh canvas map.
:param layer: layer containing the target feature for flipping.
:param feature: feature to be flipped.
:param geomType: if layer geometry type is not given, it'll calculate it (0,1 or 2).
:returns: feature as of a list of points (nodes).
"""
if not geomType:
geomType = layer.geometryType()
# getting whether geometry is multipart or not
isMulti = QgsWKBTypes.isMultiType(int(layer.wkbType()))
geom = feature.geometry()
if geomType == 0:
if isMulti:
nodes = geom.asMultiPoint()
else:
nodes = geom.asPoint()
elif geomType == 1:
if isMulti:
nodes = geom.asMultiPolyline()
else:
nodes = geom.asPolyline()
elif geomType == 2:
if isMulti:
nodes = geom.asMultiPolygon()
else:
nodes = geom.asPolygon()
return nodes
示例2: mergeLines
# 需要導入模塊: from qgis.core import QgsWKBTypes [as 別名]
# 或者: from qgis.core.QgsWKBTypes import isMultiType [as 別名]
def mergeLines(self, line_a, line_b, layer):
"""
Merge 2 lines of the same layer (it is assumed that they share the same set od attributes - except for ID and geometry).
In case sets are different, the set of attributes from line_a will be kept. If geometries don't touch, method is not applicable.
:param line_a: (QgsFeature) main line of merging process.
:param line_b: (QgsFeature) line to be merged to line_a.
:param layer: (QgsVectorLayer) layer containing given lines.
:return: (bool) True if method runs OK or False, if lines do not touch.
"""
# check if original layer is a multipart
isMulti = QgsWKBTypes.isMultiType(int(layer.wkbType()))
# retrieve lines geometries
geometry_a = line_a.geometry()
geometry_b = line_b.geometry()
# checking the spatial predicate touches
if geometry_a.touches(geometry_b):
# this generates a multi geometry
geometry_a = geometry_a.combine(geometry_b)
# this make a single line string if the multi geometries are neighbors
geometry_a = geometry_a.mergeLines()
if isMulti:
# making a "single" multi geometry (EDGV standard)
geometry_a.convertToMultiType()
# updating feature
line_a.setGeometry(geometry_a)
# remove the aggregated line to avoid overlapping
layer.deleteFeature(line_b.id())
# updating layer
layer.updateFeature(line_a)
return True
return False
示例3: flipFeature
# 需要導入模塊: from qgis.core import QgsWKBTypes [as 別名]
# 或者: from qgis.core.QgsWKBTypes import isMultiType [as 別名]
def flipFeature(self, layer, feature, geomType=None, refreshCanvas=False):
"""
Inverts the flow from a given feature. THE GIVEN FEATURE IS ALTERED. Standard behaviour is to not
refresh canvas map.
:param layer: layer containing the target feature for flipping.
:param feature: feature to be flipped.
:param geomType: if layer geometry type is not given, it'll calculate it (0,1 or 2)
:param refreshCanvas: indicates whether the canvas should be refreshed after flipping feature.
:returns: flipped feature as of [layer, feature, geometry_type].
"""
if not geomType:
geomType = layer.geometryType()
# getting whether geometry is multipart or not
isMulti = QgsWKBTypes.isMultiType(int(layer.wkbType()))
geom = feature.geometry()
if geomType == 0:
if isMulti:
nodes = geom.asMultiPoint()
# inverting the point list by parts
for idx, part in enumerate(nodes):
nodes[idx] = part[::-1]
# setting flipped geometry
flippedFeatureGeom = QgsGeometry.fromMultiPoint(nodes)
else:
# inverting the point list
nodes = geom.asPoint()
nodes = nodes[::-1]
flippedFeatureGeom = QgsGeometry.fromPoint(nodes)
elif geomType == 1:
if isMulti:
nodes = geom.asMultiPolyline()
for idx, part in enumerate(nodes):
nodes[idx] = part[::-1]
flippedFeatureGeom = QgsGeometry.fromMultiPolyline(nodes)
else:
nodes = geom.asPolyline()
nodes = nodes[::-1]
flippedFeatureGeom = QgsGeometry.fromPolyline(nodes)
elif geomType == 2:
if isMulti:
nodes = geom.asMultiPolygon()
for idx, part in enumerate(nodes):
nodes[idx] = part[::-1]
flippedFeatureGeom = QgsGeometry.fromMultiPolygon(nodes)
else:
nodes = geom.asPolygon()
nodes = nodes[::-1]
flippedFeatureGeom = QgsGeometry.fromPolygon(nodes)
# setting feature geometry to the flipped one
# feature.setGeometry(flippedFeatureGeom)
# layer.updateFeature(feature)
layer.changeGeometry(feature.id(), flippedFeatureGeom)
if refreshCanvas:
self.iface.mapCanvas().refresh()
return [layer, feature, geomType]
示例4: reclassify
# 需要導入模塊: from qgis.core import QgsWKBTypes [as 別名]
# 或者: from qgis.core.QgsWKBTypes import isMultiType [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)