本文整理汇总了Python中sextante.algs.ftools.FToolsUtils.simpleMeasure方法的典型用法代码示例。如果您正苦于以下问题:Python FToolsUtils.simpleMeasure方法的具体用法?Python FToolsUtils.simpleMeasure怎么用?Python FToolsUtils.simpleMeasure使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sextante.algs.ftools.FToolsUtils
的用法示例。
在下文中一共展示了FToolsUtils.simpleMeasure方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: processAlgorithm
# 需要导入模块: from sextante.algs.ftools import FToolsUtils [as 别名]
# 或者: from sextante.algs.ftools.FToolsUtils import simpleMeasure [as 别名]
def processAlgorithm(self, progress):
layer = QGisLayers.getObjectFromUri(self.getParameterValue(self.INPUT))
method = self.getParameterValue(self.METHOD)
geometryType = layer.geometryType()
idx1 = -1
idx2 = -1
fields = layer.pendingFields()
if geometryType == QGis.Polygon:
idx1, fields = utils.findOrCreateField(layer, fields, "area", 21, 6)
idx2, fields = utils.findOrCreateField(layer, fields, "perimeter", 21, 6)
elif geometryType == QGis.Line:
idx1, fields = utils.findOrCreateField(layer, fields, "length", 21, 6)
idx2 = idx1
else:
idx1, fields = utils.findOrCreateField(layer, fields, "xcoord", 21, 6)
idx2, fields = utils.findOrCreateField(layer, fields, "ycoord", 21, 6)
writer = self.getOutputFromName(self.OUTPUT).getVectorWriter(fields.toList(),
layer.dataProvider().geometryType(), layer.crs())
print idx1, idx2
ellips = None
crs = None
coordTransform = None
# calculate with:
# 0 - layer CRS
# 1 - project CRS
# 2 - ellipsoidal
if method == 2:
ellips = QgsProject.instance().readEntry("Measure", "/Ellipsoid", GEO_NONE)[0]
crs = layer.crs().srsid()
elif method == 1:
mapCRS = QGisLayers.iface.mapCanvas().mapRenderer().destinationCrs()
layCRS = layer.crs()
coordTransform = QgsCoordinateTransform(layCRS, mapCRS)
outFeat = QgsFeature()
inGeom = QgsGeometry()
outFeat.initAttributes(len(fields))
outFeat.setFields(fields)
current = 0
features = QGisLayers.features(layer)
total = 100.0 / float(len(features))
for f in features:
inGeom = f.geometry()
if method == 1:
inGeom.transform(coordTransform)
(attr1, attr2) = utils.simpleMeasure(inGeom, method, ellips, crs)
outFeat.setGeometry(inGeom)
attrs = f.attributes()
attrs.insert(idx1, attr1)
if attr2 is not None:
attrs.insert(idx2, attr2)
outFeat.setAttributes(attrs)
writer.addFeature(outFeat)
current += 1
progress.setPercentage(int(current * total))
del writer
示例2: processAlgorithm
# 需要导入模块: from sextante.algs.ftools import FToolsUtils [as 别名]
# 或者: from sextante.algs.ftools.FToolsUtils import simpleMeasure [as 别名]
def processAlgorithm(self, progress):
useField = (self.getParameterValue(ConvexHull.METHOD) == 1)
fieldName = self.getParameterValue(ConvexHull.FIELD)
layer = QGisLayers.getObjectFromUri(self.getParameterValue(ConvexHull.INPUT))
f = QgsField("value")
f.setType(QVariant.String)
f.setLength(255)
if useField:
index = layer.fieldNameIndex(fieldName)
fType = layer.pendingFields()[index].type()
if fType == QVariant.Int:
f.setType(QVariant.Int)
f.setLength(20)
elif fType == QVariant.Double:
f.setType(QVariant.Double)
f.setLength(20)
f.setPrecision(6)
else:
f.setType(QVariant.String)
f.setLength(255)
fields = [QgsField("id", QVariant.Int, "", 20),
f,
QgsField("area", QVariant.Double, "", 20, 6),
QgsField("perim", QVariant.Double, "", 20, 6)
]
writer = self.getOutputFromName(ConvexHull.OUTPUT).getVectorWriter(fields, QGis.WKBPolygon, layer.dataProvider().crs())
outFeat = QgsFeature()
inGeom = QgsGeometry()
outGeom = QgsGeometry()
current = 0
fid = 0
val = ""
if useField:
unique = layer.uniqueValues(index)
total = 100.0 / float(layer.featureCount() * len (unique))
for i in unique:
hull = []
first = True
features = QGisLayers.features(layer)
for f in features:
idVar = f[fieldName]
if unicode(idVar).strip() == unicode(i).strip:
if first:
val = idVar
first = False
inGeom = QgsGeometry(f.geometry())
points = utils.extractPoints(inGeom)
hull.extend(points)
current += 1
progress.setPercentage(int(current * total))
if len(hull) >= 3:
tmpGeom = QgsGeometry(outGeom.fromMultiPoint(hull))
try:
outGeom = tmpGeom.convexHull()
(area, perim) = utils.simpleMeasure(outGeom)
outFeat.setGeometry(outGeom)
outFeat.setAttributes([fid,val,area,perim])
writer.addFeature(outFeat)
except:
raise GeoAlgorithmExecutionException("Exception while computing convex hull")
fid += 1
else:
hull = []
total = 100.0 / float(layer.featureCount())
features = QGisLayers.features(layer)
for f in features:
inGeom = QgsGeometry(f.geometry())
points = utils.extractPoints(inGeom)
hull.extend(points)
current += 1
progress.setPercentage(int(current * total))
tmpGeom = QgsGeometry(outGeom.fromMultiPoint(hull))
try:
outGeom = tmpGeom.convexHull()
(area, perim) = utils.simpleMeasure(outGeom)
outFeat.setGeometry(outGeom)
outFeat.setAttributes([0, "all", area, perim])
writer.addFeature(outFeat)
except:
raise GeoAlgorithmExecutionException("Exception while computing convex hull")
del writer