本文整理汇总了Python中qgis.core.QgsPointXY方法的典型用法代码示例。如果您正苦于以下问题:Python core.QgsPointXY方法的具体用法?Python core.QgsPointXY怎么用?Python core.QgsPointXY使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类qgis.core
的用法示例。
在下文中一共展示了core.QgsPointXY方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: canvasReleaseEvent
# 需要导入模块: from qgis import core [as 别名]
# 或者: from qgis.core import QgsPointXY [as 别名]
def canvasReleaseEvent(self, event):
'''Capture the coordinate when the mouse button has been released,
format it, and copy it to the clipboard. pt is QgsPointXY'''
pt = self.snappoint(event.originalPixelPoint())
self.removeVertexMarker()
if settings.captureShowLocation:
if self.marker is None:
self.marker = QgsVertexMarker(self.canvas)
self.marker.setIconSize(18)
self.marker.setPenWidth(2)
self.marker.setIconType(QgsVertexMarker.ICON_CROSS)
self.marker.setCenter(pt)
else:
self.removeMarker()
try:
msg = self.formatCoord(pt, self.settings.delimiter)
formatString = self.coordFormatString()
if msg is not None:
clipboard = QApplication.clipboard()
clipboard.setText(msg)
self.iface.messageBar().pushMessage("", "{} coordinate {} copied to the clipboard".format(formatString, msg), level=Qgis.Info, duration=4)
except Exception as e:
self.iface.messageBar().pushMessage("", "Invalid coordinate: {}".format(e), level=Qgis.Warning, duration=4)
示例2: GCgetPointsOnLine
# 需要导入模块: from qgis import core [as 别名]
# 或者: from qgis.core import QgsPointXY [as 别名]
def GCgetPointsOnLine(lat1, lon1, lat2, lon2, minSegLength=1000.0, maxNodes=500):
'''Get points along a great circle line between the two coordinates.
minSegLength is the minimum segment length in meters before a new
node point is created. maxNodes is the maximum number of points on
the line to create.'''
dist = GCdistanceTo(lat1, lon1, lat2, lon2)
numPoints = int(dist / minSegLength)
if numPoints > maxNodes:
numPoints = maxNodes
pts = [QgsPointXY(lon1, lat1)]
f = 1.0 / (numPoints - 1.0)
i = 1
while i < numPoints - 1:
newlat, newlon = GCintermediatePointTo(lat1, lon1, lat2, lon2, f * i)
pts.append(QgsPointXY(newlon, newlat))
i += 1
pts.append(QgsPointXY(lon2, lat2))
return pts
示例3: showCircle
# 需要导入模块: from qgis import core [as 别名]
# 或者: from qgis.core import QgsPointXY [as 别名]
def showCircle(self, startPoint):
"""
Draws a circle in the canvas
"""
nPoints = 50
x = startPoint.x()
y = startPoint.y()
if self.type == self.tr('distance'):
r = self.param
self.rubberBand.reset(QgsWkbTypes.PolygonGeometry)
for itheta in range(nPoints+1):
theta = itheta*(2.0*pi/nPoints)
self.rubberBand.addPoint(QgsPointXY(x+r*cos(theta), y+r*sin(theta)))
self.rubberBand.show()
else:
r = sqrt(self.param/pi)
self.rubberBand.reset(QgsWkbTypes.PolygonGeometry)
for itheta in range(nPoints+1):
theta = itheta*(2.0*pi/nPoints)
self.rubberBand.addPoint(QgsPointXY(x+r*cos(theta), y+r*sin(theta)))
self.rubberBand.show()
示例4: processAlgorithm
# 需要导入模块: from qgis import core [as 别名]
# 或者: from qgis.core import QgsPointXY [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}
示例5: zoomTo
# 需要导入模块: from qgis import core [as 别名]
# 或者: from qgis.core import QgsPointXY [as 别名]
def zoomTo(self, srcCrs, lat, lon):
canvasCrs = self.canvas.mapSettings().destinationCrs()
transform = QgsCoordinateTransform(srcCrs, canvasCrs, QgsProject.instance())
x, y = transform.transform(float(lon), float(lat))
rect = QgsRectangle(x, y, x, y)
self.canvas.setExtent(rect)
pt = QgsPointXY(x, y)
self.highlight(pt)
self.canvas.refresh()
return pt
示例6: snappoint
# 需要导入模块: from qgis import core [as 别名]
# 或者: from qgis.core import QgsPointXY [as 别名]
def snappoint(self, qpoint):
match = self.canvas.snappingUtils().snapToMap(qpoint)
if match.isValid():
if self.vertex is None:
self.vertex = QgsVertexMarker(self.canvas)
self.vertex.setIconSize(12)
self.vertex.setPenWidth(2)
self.vertex.setColor(self.snapcolor)
self.vertex.setIconType(QgsVertexMarker.ICON_BOX)
self.vertex.setCenter(match.point())
return (match.point()) # Returns QgsPointXY
else:
self.removeVertexMarker()
return self.toMapCoordinates(qpoint) # QPoint input, returns QgsPointXY
示例7: utmString2Crs
# 需要导入模块: from qgis import core [as 别名]
# 或者: from qgis.core import QgsPointXY [as 别名]
def utmString2Crs(utm, crs=epsg4326):
parts = re.split(r'[\s]+', utm.upper())
utmlen = len(parts)
if utmlen == 3:
m = re.findall(r'(\d+)([NS])', parts[0])
if len(m) != 1 or len(m[0]) != 2:
raise ValueError('Invalid UTM Coordinate')
zone = int(m[0][0])
hemisphere = m[0][1]
easting = float(parts[1])
northing = float(parts[2])
elif utmlen == 4:
if parts[1] != 'N' and parts[1] != 'S':
raise ValueError('Invalid UTM Coordinate')
zone = int(parts[0])
easting = float(parts[2])
northing = float(parts[3])
else:
raise ValueError('Invalid UTM Coordinate')
if zone < 1 or zone > 60:
raise ValueError('Invalid UTM Coordinate')
utmcrs = QgsCoordinateReferenceSystem(utm_epsg_codes['{}{}'.format(zone, hemisphere)])
pt = QgsPointXY(easting, northing)
utmtrans = QgsCoordinateTransform(utmcrs, crs, QgsProject.instance())
return(utmtrans.transform(pt))
示例8: canvasReleaseEvent
# 需要导入模块: from qgis import core [as 别名]
# 或者: from qgis.core import QgsPointXY [as 别名]
def canvasReleaseEvent(self, event):
'''Capture the coordinate when the mouse button has been released,
format it, and copy it to the clipboard. pt is QgsPointXY'''
pt = self.snappoint(event.originalPixelPoint())
self.removeVertexMarker()
try:
canvasCRS = self.canvas.mapSettings().destinationCrs()
transform = QgsCoordinateTransform(canvasCRS, epsg4326, QgsProject.instance())
pt4326 = transform.transform(pt.x(), pt.y())
self.capturePoint.emit(pt4326)
except Exception as e:
pass
示例9: panToAction
# 需要导入模块: from qgis import core [as 别名]
# 或者: from qgis.core import QgsPointXY [as 别名]
def panToAction(self):
crsCanvas = self.module.iface.mapCanvas().mapSettings().destinationCrs() # get current crs
crsWGS84 = QgsCoordinateReferenceSystem(4326) # WGS 84
xform = QgsCoordinateTransform(crsWGS84, crsCanvas, QgsProject.instance())
sourcePoint = QgsPointXY(float(self.field_longitude.text()),float(self.field_latitude.text()))
self.module.iface.mapCanvas().setCenter(xform.transform(sourcePoint))
self.module.iface.mapCanvas().refresh()
示例10: setCenter
# 需要导入模块: from qgis import core [as 别名]
# 或者: from qgis.core import QgsPointXY [as 别名]
def setCenter(lon, lat, zoom=None):
"""
Centers the map view at the given coordinates with the given zoom level. If no zoom level is provided, it uses the most recent zoom level on the map.
https://developers.google.com/earth-engine/api_docs#map.setcenter
Uses:
>>> from ee_plugin import Map
>>> Map.setCenter(lon, lat, zoom)
"""
### center
center_point_in = QgsPointXY(lon, lat)
# convert coordinates
crsSrc = QgsCoordinateReferenceSystem(4326) # WGS84
crsDest = QgsCoordinateReferenceSystem(QgsProject.instance().crs())
xform = QgsCoordinateTransform(crsSrc, crsDest, QgsProject.instance())
# forward transformation: src -> dest
center_point = xform.transform(center_point_in)
iface.mapCanvas().setCenter(center_point)
### zoom
if zoom is not None:
# transform the zoom level to scale
scale_value = 591657550.5 / 2 ** (zoom - 1)
iface.mapCanvas().zoomScale(scale_value)
示例11: geom_to_geo
# 需要导入模块: from qgis import core [as 别名]
# 或者: from qgis.core import QgsPointXY [as 别名]
def geom_to_geo(geom):
crs_src = QgsCoordinateReferenceSystem(QgsProject.instance().crs())
crs_dst = QgsCoordinateReferenceSystem(4326)
proj2geo = QgsCoordinateTransform(crs_src, crs_dst, QgsProject.instance())
if isinstance(geom, QgsPointXY):
return proj2geo.transform(geom)
elif isinstance(geom, QgsRectangle):
return proj2geo.transformBoundingBox(geom)
else:
return geom.transform(proj2geo)
示例12: checkIdlCrossings
# 需要导入模块: from qgis import core [as 别名]
# 或者: from qgis.core import QgsPointXY [as 别名]
def checkIdlCrossings(pts):
outseg = []
ptlen = len(pts)
pts2 = [pts[0]]
for i in range(1, ptlen):
if pts[i - 1].x() < -120 and pts[i].x() > 120: # We have crossed the date line going west
ld = geod.Inverse(pts[i - 1].y(), pts[i - 1].x(), pts[i].y(), pts[i].x())
try:
(intrlat, intrlon) = intersection_point(-89, -180, 0, pts[i - 1].y(), pts[i - 1].x(), ld['azi1'])
ptnew = QgsPointXY(-180, intrlat)
pts2.append(ptnew)
outseg.append(pts2)
ptnew = QgsPointXY(180, intrlat)
pts2 = [ptnew]
except Exception:
pts2.append(pts[i])
if pts[i - 1].x() > 120 and pts[i].x() < -120: # We have crossed the date line going east
ld = geod.Inverse(pts[i - 1].y(), pts[i - 1].x(), pts[i].y(), pts[i].x())
try:
(intrlat, intrlon) = intersection_point(-89, 180, 0, pts[i - 1].y(), pts[i - 1].x(), ld['azi1'])
ptnew = QgsPointXY(180, intrlat)
pts2.append(ptnew)
outseg.append(pts2)
ptnew = QgsPointXY(-180, intrlat)
pts2 = [ptnew]
except Exception:
pts2.append(pts[i])
else:
pts2.append(pts[i])
outseg.append(pts2)
return(outseg)
示例13: showRect
# 需要导入模块: from qgis import core [as 别名]
# 或者: from qgis.core import QgsPointXY [as 别名]
def showRect(self, startPoint, param, rotAngle=0):
"""
Draws a rectangle in the canvas
"""
self.rubberBand.reset(QgsWkbTypes.PolygonGeometry)
x = startPoint.x() # center point x
y = startPoint.y() # center point y
# rotation angle is always applied in reference to center point
# to avoid unnecessary calculations
c = cos(rotAngle)
s = sin(rotAngle)
# translating coordinate system to rubberband centroid
point1 = QgsPointXY((- param), (- param))
point2 = QgsPointXY((- param), ( param))
point3 = QgsPointXY((param), ( param))
point4 = QgsPointXY((param), (- param))
# rotating and moving to original coord. sys.
point1_ = QgsPointXY(point1.x()*c - point1.y()*s + x, point1.y()*c + point1.x()*s + y)
point2_ = QgsPointXY(point2.x()*c - point2.y()*s + x, point2.y()*c + point2.x()*s + y)
point3_ = QgsPointXY(point3.x()*c - point3.y()*s + x, point3.y()*c + point3.x()*s + y)
point4_ = QgsPointXY(point4.x()*c - point4.y()*s + x, point4.y()*c + point4.x()*s + y)
self.rubberBand.addPoint(point1_, False)
self.rubberBand.addPoint(point2_, False)
self.rubberBand.addPoint(point3_, False)
self.rubberBand.addPoint(point4_, True)
self.rubberBand.show()
self.currentCentroid = startPoint
示例14: startEdition
# 需要导入模块: from qgis import core [as 别名]
# 或者: from qgis.core import QgsPointXY [as 别名]
def startEdition(self, event):
#Método para iniciar a aquisição
#Parâmetro de entrada: event (Evento)
event.snapPoint()
snapRubberBand = self.getSnapRubberBand()
if snapRubberBand:
snapRubberBand.reset(geometryType=core.QgsWkbTypes.PointGeometry)
snapRubberBand.hide()
self.setSnapRubberBand(None)
pointMap = core.QgsPointXY(event.mapPoint())
layer = self.getCanvas().currentLayer()
if layer:
self.startRubberBand(pointMap, layer)
示例15: canvasMoveEvent
# 需要导入模块: from qgis import core [as 别名]
# 或者: from qgis.core import QgsPointXY [as 别名]
def canvasMoveEvent(self, event):
#Método para receber os eventos canvas move do Qgis
#Parâmetro de entrada: event (Evento que chamou o método)
if self.getRubberBand():
endPoint = self.toMapCoordinates( event.pos() )
snapRubberBand = self.getSnapRubberBand()
if not(self.getStopedState()):
if snapRubberBand:
snapRubberBand.hide()
snapRubberBand.reset(geometryType=core.QgsWkbTypes.PointGeometry)
self.setSnapRubberBand(None)
oldPoint = core.QgsPointXY(event.mapPoint())
event.snapPoint()
point = core.QgsPointXY(event.mapPoint())
if oldPoint != point:
self.createSnapCursor(point)
if self.getRubberBand():
if self.contadorVert == 0:
self.getRubberBand().addPoint(point)
self.contadorVert+=1
else:
self.getRubberBand().addPoint(oldPoint)
if self.getRubberBandToStopState():
self.updateRubberBandToStopState(
self.toMapCoordinates( event.pos() )
)