本文整理汇总了Python中qgis.core.QgsWkbTypes.Point方法的典型用法代码示例。如果您正苦于以下问题:Python QgsWkbTypes.Point方法的具体用法?Python QgsWkbTypes.Point怎么用?Python QgsWkbTypes.Point使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类qgis.core.QgsWkbTypes
的用法示例。
在下文中一共展示了QgsWkbTypes.Point方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __export_raster
# 需要导入模块: from qgis.core import QgsWkbTypes [as 别名]
# 或者: from qgis.core.QgsWkbTypes import Point [as 别名]
def __export_raster(self, outDir, field):
xspacing = self.__xspacing()
yspacing = self.__yspacing()
with self.connect() as con:
uri = QgsDataSourceUri()
uri.setConnection(con.info.host, str(con.info.port), con.info.dbname, con.info.user, con.info.password)
uri.setDataSource("_albion", "current_raster", "geom")
uri.setParam("checkPrimaryKeyUnicity", "0")
uri.setSrid("32632")
uri.setWkbType(QgsWkbTypes.Point)
v = QgsVectorLayer(uri.uri(), "current_raster", "postgres")
res = processing.run("gdal:rasterize", {'INPUT':v,'FIELD':field,'BURN':0,'UNITS':1,'WIDTH':xspacing,'HEIGHT':yspacing,'EXTENT':v.extent(),'NODATA':-9999,'OPTIONS':'','DATA_TYPE':5,'INIT':None,'INVERT':False,'EXTRA':'','OUTPUT':os.path.join(outDir, 'dem.tif')})
processing.run("qgis:slope", {'INPUT':res['OUTPUT'],'Z_FACTOR':1,'OUTPUT':os.path.join(outDir, 'slope.tif')})
processing.run("qgis:aspect", {'INPUT':res['OUTPUT'],'Z_FACTOR':1,'OUTPUT':os.path.join(outDir, 'aspect.tif')})
processing.run("qgis:ruggednessindex", {'INPUT':res['OUTPUT'],'Z_FACTOR':1,'OUTPUT':os.path.join(outDir, 'ruggednessindex.tif')})
示例2: canvasPressEvent
# 需要导入模块: from qgis.core import QgsWkbTypes [as 别名]
# 或者: from qgis.core.QgsWkbTypes import Point [as 别名]
def canvasPressEvent(self, event):
"""Capture the coordinate when the mouse button has been released."""
pt = self.snappoint(event.originalPixelPoint())
self.removeVertexMarker()
if self.azDigitizerDialog is None:
from .azDigitizer import AzDigitizerWidget
self.azDigitizerDialog = AzDigitizerWidget(self.iface, self.iface.mainWindow())
layer = self.iface.activeLayer()
if layer is None or layer.wkbType() != QgsWkbTypes.Point:
self.azDigitizerDialog.includeStartLabel.setEnabled(False)
self.azDigitizerDialog.checkBox.setEnabled(False)
else:
self.azDigitizerDialog.includeStartLabel.setEnabled(True)
self.azDigitizerDialog.checkBox.setEnabled(True)
try:
canvasCRS = self.canvas.mapSettings().destinationCrs()
transform = QgsCoordinateTransform(canvasCRS, epsg4326, QgsProject.instance())
pt4326 = transform.transform(pt.x(), pt.y())
self.azDigitizerDialog.setPoint(pt4326)
self.azDigitizerDialog.show()
except Exception:
self.iface.messageBar().pushMessage("", tr("Clicked location is invalid"), level=Qgis.Warning, duration=4)
示例3: processAlgorithm
# 需要导入模块: from qgis.core import QgsWkbTypes [as 别名]
# 或者: from qgis.core.QgsWkbTypes import Point [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: canvasReleaseEvent
# 需要导入模块: from qgis.core import QgsWkbTypes [as 别名]
# 或者: from qgis.core.QgsWkbTypes import Point [as 别名]
def canvasReleaseEvent(self, event):
# Make sure the point is transfored to 4326
self.clearSelection()
pt = self.toMapCoordinates(event.pos())
canvasCRS = self.canvas.mapSettings().destinationCrs()
transform = QgsCoordinateTransform(canvasCRS, self.epsg4326, QgsProject.instance())
pt = transform.transform(pt.x(), pt.y())
url = '{}?format=json&lat={:f}&lon={:f}&zoom={:d}&addressdetails=0&polygon_text=1'.format(self.settings.reverseURL(), pt.y(), pt.x(), self.settings.levelOfDetail)
# print( url )
jsondata = self.request(url)
try:
jd = json.loads(jsondata)
try:
display_name = jd['display_name']
self.setText(display_name)
except KeyError:
self.setText("[Could not find address]")
try:
wkt = jd['geotext']
geometry = QgsGeometry.fromWkt(wkt)
if geometry.wkbType() == QgsWkbTypes.Point:
pt = geometry.asPoint()
lon = pt.x()
lat = pt.y()
self.addMarker(lat, lon)
else:
geometry = self.transform_geom(geometry)
self.rubber.addGeometry(geometry, None)
self.rubber.show()
except KeyError:
try:
lon = float(jd['lon'])
lat = float(jd['lat'])
self.addMarker(lat, lon)
except:
pass
except Exception:
self.setText("Error: "+jsondata)
if not self.reverseGeoCodeDialog.isVisible():
self.show()
示例5: accept
# 需要导入模块: from qgis.core import QgsWkbTypes [as 别名]
# 或者: from qgis.core.QgsWkbTypes import Point [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()