本文整理匯總了Python中qgis.core.QgsGeometry.fromPointXY方法的典型用法代碼示例。如果您正苦於以下問題:Python QgsGeometry.fromPointXY方法的具體用法?Python QgsGeometry.fromPointXY怎麽用?Python QgsGeometry.fromPointXY使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類qgis.core.QgsGeometry
的用法示例。
在下文中一共展示了QgsGeometry.fromPointXY方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: getPixelValue
# 需要導入模塊: from qgis.core import QgsGeometry [as 別名]
# 或者: from qgis.core.QgsGeometry import fromPointXY [as 別名]
def getPixelValue(self, mousePos, rasterLayer):
"""
"""
rasterCrs = rasterLayer.crs()
mousePosGeom = QgsGeometry.fromPointXY(mousePos)
canvasCrs = self.canvas.mapSettings().destinationCrs()
self.geometryHandler.reprojectFeature(mousePosGeom, rasterCrs, canvasCrs)
mousePos = mousePosGeom.asPoint()
# identify pixel(s) information
i = rasterLayer.dataProvider().identify( mousePos, QgsRaster.IdentifyFormatValue )
if i.isValid():
text = ", ".join(['{0:g}'.format(r) for r in list(i.results().values()) if r is not None] )
else:
text = ""
return text
示例2: sortFeatures
# 需要導入模塊: from qgis.core import QgsGeometry [as 別名]
# 或者: from qgis.core.QgsGeometry import fromPointXY [as 別名]
def sortFeatures(self, geom, features):
"""
Sorts features according to the distance
"""
#sorting by distance
distances = []
firstPoint = geom.asPolyline()[0]
pointGeom = QgsGeometry.fromPointXY(firstPoint)
for intersected in features:
intersection = geom.intersection(intersected.geometry())
if intersection.type() == QgsWkbTypes.PointGeometry:
distance = intersection.distance(pointGeom)
distances.append((distance, intersected))
ordered = sorted(distances, key=self.getKey)
#returning a list of tuples (distance, feature)
return ordered
示例3: processAlgorithm
# 需要導入模塊: from qgis.core import QgsGeometry [as 別名]
# 或者: from qgis.core.QgsGeometry import fromPointXY [as 別名]
def processAlgorithm(self, parameters, context, feedback):
source = self.parameterAsSource(parameters, self.PrmInputLayer, context)
mgrsfieldname = self.parameterAsString(parameters, self.PrmMgrsField, context)
if not mgrsfieldname:
msg = 'Select an MGRS field to process'
feedback.reportError(msg)
raise QgsProcessingException(msg)
epsg4326 = QgsCoordinateReferenceSystem("EPSG:4326")
(sink, dest_id) = self.parameterAsSink(
parameters, self.PrmOutputLayer,
context, source.fields(), QgsWkbTypes.Point, epsg4326)
featureCount = source.featureCount()
total = 100.0 / featureCount if featureCount else 0
badFeatures = 0
iterator = source.getFeatures()
for cnt, feature in enumerate(iterator):
if feedback.isCanceled():
break
m = feature[mgrsfieldname]
try:
m = re.sub(r'\s+', '', str(m)) # Remove all white space
lat, lon = mgrs.toWgs(m)
except Exception:
# traceback.print_exc()
badFeatures += 1
continue
f = QgsFeature()
f.setGeometry(QgsGeometry.fromPointXY(QgsPointXY(lon, lat)))
f.setAttributes(feature.attributes())
sink.addFeature(f)
if cnt % 100 == 0:
feedback.setProgress(int(cnt * total))
if badFeatures > 0:
msg = "{} out of {} features contained MGRS coordinates".format(featureCount - badFeatures, featureCount)
feedback.pushInfo(msg)
return {self.PrmOutputLayer: dest_id}
示例4: getFeatureFromPointParameter
# 需要導入模塊: from qgis.core import QgsGeometry [as 別名]
# 或者: from qgis.core.QgsGeometry import fromPointXY [as 別名]
def getFeatureFromPointParameter(qgs_point_xy):
feature = QgsFeature()
fields = QgsFields()
fields.append(QgsField('point_id', QVariant.String, '', 254, 0))
feature.setFields(fields)
feature.setGeometry(QgsGeometry.fromPointXY(qgs_point_xy))
feature['point_id']="Start Point"
return feature
示例5: accept
# 需要導入模塊: from qgis.core import QgsGeometry [as 別名]
# 或者: from qgis.core.QgsGeometry import fromPointXY [as 別名]
def accept(self):
try:
distance = float(self.distLineEdit.text())
azimuth = float(self.azimuthLineEdit.text())
units = self.unitsComboBox.currentIndex() # 0 km, 1 m, 2 nm, 3 miles, 4 yards, 5 ft, 6 inches, 7 cm
start = self.checkBox.isChecked()
except Exception:
self.iface.messageBar().pushMessage("", tr("Either distance or azimuth were invalid"), level=Qgis.Warning, duration=4)
return
layer = self.iface.activeLayer()
if layer is None:
self.iface.messageBar().pushMessage("", tr("No point or line layer selected"), level=Qgis.Warning, duration=4)
return
measureFactor = conversionToMeters(units)
distance = distance * measureFactor
pt = self.pt
destCRS = layer.crs()
transform = QgsCoordinateTransform(epsg4326, destCRS, QgsProject.instance())
if layer.wkbType() == QgsWkbTypes.Point:
g = geod.Direct(pt.y(), pt.x(), azimuth, distance, Geodesic.LATITUDE | Geodesic.LONGITUDE)
if start:
ptStart = transform.transform(self.pt.x(), self.pt.y())
feat = QgsFeature(layer.fields())
feat.setGeometry(QgsGeometry.fromPointXY(ptStart))
layer.addFeature(feat)
pt = transform.transform(g['lon2'], g['lat2'])
feat = QgsFeature(layer.fields())
feat.setGeometry(QgsGeometry.fromPointXY(pt))
layer.addFeature(feat)
else: # It will either be a LineString or MultiLineString
maxseglen = settings.maxSegLength * 1000.0 # Needs to be in meters
maxSegments = settings.maxSegments
gline = geod.Line(pt.y(), pt.x(), azimuth)
n = int(math.ceil(distance / maxseglen))
if n > maxSegments:
n = maxSegments
seglen = distance / n
pts = []
for i in range(0, n + 1):
s = seglen * i
g = gline.Position(s, Geodesic.LATITUDE | Geodesic.LONGITUDE | Geodesic.LONG_UNROLL)
ptc = transform.transform(g['lon2'], g['lat2'])
pts.append(ptc)
feat = QgsFeature(layer.fields())
if layer.wkbType() == QgsWkbTypes.LineString:
feat.setGeometry(QgsGeometry.fromPolylineXY(pts))
else:
feat.setGeometry(QgsGeometry.fromMultiPolylineXY([pts]))
layer.addFeatures([feat])
layer.updateExtents()
self.iface.mapCanvas().refresh()
self.close()