本文整理汇总了Python中qgis.core.QgsPointXY.x方法的典型用法代码示例。如果您正苦于以下问题:Python QgsPointXY.x方法的具体用法?Python QgsPointXY.x怎么用?Python QgsPointXY.x使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类qgis.core.QgsPointXY
的用法示例。
在下文中一共展示了QgsPointXY.x方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: transformedCornerCoordinates
# 需要导入模块: from qgis.core import QgsPointXY [as 别名]
# 或者: from qgis.core.QgsPointXY import x [as 别名]
def transformedCornerCoordinates(self, center, rotation, xScale, yScale):
# scale
topLeft = QgsPointXY(-self.image.width() / 2.0 * xScale,
self.image.height() / 2.0 * yScale)
topRight = QgsPointXY(self.image.width() / 2.0 * xScale,
self.image.height() / 2.0 * yScale)
bottomLeft = QgsPointXY(-self.image.width() / 2.0 * xScale,
- self.image.height() / 2.0 * yScale)
bottomRight = QgsPointXY(self.image.width() / 2.0 * xScale,
- self.image.height() / 2.0 * yScale)
# rotate
# minus sign because rotation is CW in this class and Qt)
rotationRad = -rotation * math.pi / 180
cosRot = math.cos(rotationRad)
sinRot = math.sin(rotationRad)
topLeft = self._rotate(topLeft, cosRot, sinRot)
topRight = self._rotate(topRight, cosRot, sinRot)
bottomRight = self._rotate(bottomRight, cosRot, sinRot)
bottomLeft = self._rotate(bottomLeft, cosRot, sinRot)
topLeft.set(topLeft.x() + center.x(), topLeft.y() + center.y())
topRight.set(topRight.x() + center.x(), topRight.y() + center.y())
bottomRight.set(bottomRight.x() + center.x(),
bottomRight.y() + center.y())
bottomLeft.set(bottomLeft.x() + center.x(),
bottomLeft.y() + center.y())
return (topLeft, topRight, bottomRight, bottomLeft)
示例2: TestQgsPointXY
# 需要导入模块: from qgis.core import QgsPointXY [as 别名]
# 或者: from qgis.core.QgsPointXY import x [as 别名]
class TestQgsPointXY(unittest.TestCase):
def __init__(self, methodName):
"""Run once on class initialization."""
unittest.TestCase.__init__(self, methodName)
def setUp(self):
self.mPoint = QgsPointXY(10.0, 10.0)
def test_Point(self):
myExpectedValue = 10.0
myActualValue = self.mPoint.x()
myMessage = 'Expected: %s Got: %s' % (myExpectedValue, myActualValue)
assert myExpectedValue == myActualValue, myMessage
def test_pointToString(self):
myExpectedValue = '10, 10'
myActualValue = self.mPoint.toString()
myMessage = 'Expected: %s Got: %s' % (myExpectedValue, myActualValue)
assert myExpectedValue == myActualValue, myMessage
def test_hash(self):
a = QgsPointXY(2.0, 1.0)
b = QgsPointXY(2.0, 2.0)
c = QgsPointXY(1.0, 2.0)
d = QgsPointXY(1.0, 1.0)
e = QgsPointXY(2.0, 1.0)
assert a.__hash__() != b.__hash__()
assert e.__hash__() == a.__hash__()
mySet = set([a, b, c, d, e])
assert len(mySet) == 4
示例3: transformedCornerCoordinatesFromPoint
# 需要导入模块: from qgis.core import QgsPointXY [as 别名]
# 或者: from qgis.core.QgsPointXY import x [as 别名]
def transformedCornerCoordinatesFromPoint(self, startPoint, rotation,
xScale, yScale):
# startPoint is a fixed point for this new movement (rotation and
# scale)
# rotation is the global rotation of the image
# xScale is the new xScale factor to be multiplied by self.xScale
# idem for yScale
# Calculate the coordinate of the center in a startPoint origin
# coordinate system and apply scales
dX = (self.center.x() - startPoint.x()) * xScale
dY = (self.center.y() - startPoint.y()) * yScale
# Half width and half height in the current transformation
hW = (self.image.width() / 2.0) * self.xScale * xScale
hH = (self.image.height() / 2.0) * self.yScale * yScale
# Actual rectangle coordinates :
pt1 = QgsPointXY(-hW, hH)
pt2 = QgsPointXY(hW, hH)
pt3 = QgsPointXY(hW, -hH)
pt4 = QgsPointXY(-hW, -hH)
# Actual rotation from the center
# minus sign because rotation is CW in this class and Qt)
rotationRad = -self.rotation * math.pi / 180
cosRot = math.cos(rotationRad)
sinRot = math.sin(rotationRad)
pt1 = self._rotate(pt1, cosRot, sinRot)
pt2 = self._rotate(pt2, cosRot, sinRot)
pt3 = self._rotate(pt3, cosRot, sinRot)
pt4 = self._rotate(pt4, cosRot, sinRot)
# Second transformation
# displacement of the origin
pt1 = QgsPointXY(pt1.x() + dX, pt1.y() + dY)
pt2 = QgsPointXY(pt2.x() + dX, pt2.y() + dY)
pt3 = QgsPointXY(pt3.x() + dX, pt3.y() + dY)
pt4 = QgsPointXY(pt4.x() + dX, pt4.y() + dY)
# Rotation
# minus sign because rotation is CW in this class and Qt)
rotationRad = -rotation * math.pi / 180
cosRot = math.cos(rotationRad)
sinRot = math.sin(rotationRad)
pt1 = self._rotate(pt1, cosRot, sinRot)
pt2 = self._rotate(pt2, cosRot, sinRot)
pt3 = self._rotate(pt3, cosRot, sinRot)
pt4 = self._rotate(pt4, cosRot, sinRot)
# translate to startPoint
pt1 = QgsPointXY(pt1.x() + startPoint.x(), pt1.y() + startPoint.y())
pt2 = QgsPointXY(pt2.x() + startPoint.x(), pt2.y() + startPoint.y())
pt3 = QgsPointXY(pt3.x() + startPoint.x(), pt3.y() + startPoint.y())
pt4 = QgsPointXY(pt4.x() + startPoint.x(), pt4.y() + startPoint.y())
return (pt1, pt2, pt3, pt4)
示例4: testPoint
# 需要导入模块: from qgis.core import QgsPointXY [as 别名]
# 或者: from qgis.core.QgsPointXY import x [as 别名]
def testPoint(self):
point = QgsReferencedPointXY(QgsPointXY(1.0, 2.0), QgsCoordinateReferenceSystem('epsg:3111'))
self.assertEqual(point.x(), 1.0)
self.assertEqual(point.y(), 2.0)
self.assertEqual(point.crs().authid(), 'EPSG:3111')
point.setCrs(QgsCoordinateReferenceSystem('epsg:28356'))
self.assertEqual(point.crs().authid(), 'EPSG:28356')
# in variant
v = QVariant(QgsReferencedPointXY(QgsPointXY(3.0, 4.0), QgsCoordinateReferenceSystem('epsg:3111')))
self.assertEqual(v.value().x(), 3.0)
self.assertEqual(v.value().y(), 4.0)
self.assertEqual(v.value().crs().authid(), 'EPSG:3111')
# to QgsPointXY
p = QgsPointXY(point)
self.assertEqual(p.x(), 1.0)
self.assertEqual(p.y(), 2.0)
示例5: checkPoint
# 需要导入模块: from qgis.core import QgsPointXY [as 别名]
# 或者: from qgis.core.QgsPointXY import x [as 别名]
def checkPoint(self, point):
state = 'yellow'
if type(point) != QgsPointXY:
try:
if type(point) == list and len(point) == 2:
point = QgsPointXY(point[0], point[1])
else:
point = QgsPointXY(point)
except TypeError:
return state, None
if self.dhm != {}:
extent = self.dhm['extent']
[extLx, extHy, extHx, extLy] = extent
if extLx <= float(point.x()) <= extHx \
and extLy <= float(point.y()) <= extHy:
state = 'green'
else:
state = 'red'
return state, point
示例6: FreehandRasterGeoreferencerLayer
# 需要导入模块: from qgis.core import QgsPointXY [as 别名]
# 或者: from qgis.core.QgsPointXY import x [as 别名]
class FreehandRasterGeoreferencerLayer(QgsPluginLayer):
LAYER_TYPE = "FreehandRasterGeoreferencerLayer"
transformParametersChanged = pyqtSignal(tuple)
def __init__(self, plugin, filepath, title, screenExtent):
QgsPluginLayer.__init__(
self, FreehandRasterGeoreferencerLayer.LAYER_TYPE, title)
self.plugin = plugin
self.iface = plugin.iface
self.title = title
self.filepath = filepath
self.screenExtent = screenExtent
self.history = []
# set custom properties
self.setCustomProperty("title", title)
self.setCustomProperty("filepath", self.filepath)
self.setValid(True)
self.setTransparency(LayerDefaultSettings.TRANSPARENCY)
self.setBlendModeByName(LayerDefaultSettings.BLEND_MODE)
# dummy data: real init is done in intializeLayer
self.center = QgsPointXY(0, 0)
self.rotation = 0.0
self.xScale = 1.0
self.yScale = 1.0
self.error = False
self.initializing = False
self.initialized = False
self.initializeLayer(screenExtent)
self._extent = None
self.provider = FreehandRasterGeoreferencerLayerProvider(self)
def dataProvider(self):
# issue with DBManager if the dataProvider of the QgsLayerPlugin
# returns None
return self.provider
def setScale(self, xScale, yScale):
self.xScale = xScale
self.yScale = yScale
def setRotation(self, rotation):
rotation = round(rotation, 1)
# keep in -180,180 interval
if rotation < -180:
rotation += 360
if rotation > 180:
rotation -= 360
self.rotation = rotation
def setCenter(self, center):
self.center = center
def commitTransformParameters(self):
QgsProject.instance().setDirty(True)
self._extent = None
self.setCustomProperty("xScale", self.xScale)
self.setCustomProperty("yScale", self.yScale)
self.setCustomProperty("rotation", self.rotation)
self.setCustomProperty("xCenter", self.center.x())
self.setCustomProperty("yCenter", self.center.y())
self.transformParametersChanged.emit(
(self.xScale, self.yScale, self.rotation, self.center))
def reprojectTransformParameters(self, oldCrs, newCrs):
transform = QgsCoordinateTransform(oldCrs, newCrs,
QgsProject.instance())
newCenter = transform.transform(self.center)
newExtent = transform.transform(self.extent())
# transform the parameters except rotation
# TODO rotation could be better handled (maybe check rotation between
# old and new extent)
# but not really worth the effort ?
self.setCrs(newCrs)
self.setCenter(newCenter)
self.resetScale(newExtent.width(), newExtent.height())
def resetTransformParametersToNewCrs(self):
"""
Attempts to keep the layer on the same region of the map when
the map CRS is changed
"""
oldCrs = self.crs()
newCrs = self.iface.mapCanvas().mapSettings().destinationCrs()
self.reprojectTransformParameters(oldCrs, newCrs)
self.commitTransformParameters()
def setupCrsEvents(self):
layerId = self.id()
def removeCrsChangeHandler(layerIds):
if layerId in layerIds:
#.........这里部分代码省略.........
示例7: run
# 需要导入模块: from qgis.core import QgsPointXY [as 别名]
# 或者: from qgis.core.QgsPointXY import x [as 别名]
def run(sources_layer_path, receivers_layer_path, emission_pts_layer_path, research_ray):
sources_layer = QgsVectorLayer(sources_layer_path, "input layer", "ogr")
receivers_layer = QgsVectorLayer(receivers_layer_path, "output layer", "ogr")
sources_feat_all = sources_layer.dataProvider().getFeatures()
receivers_feat_all_dict = {}
receivers_feat_all = receivers_layer.dataProvider().getFeatures()
receivers_spIndex = QgsSpatialIndex()
for receivers_feat in receivers_feat_all:
receivers_spIndex.insertFeature(receivers_feat)
receivers_feat_all_dict[receivers_feat.id()] = receivers_feat
emission_pts_fields = QgsFields()
emission_pts_fields.append(QgsField("id_emi", QVariant.Int))
emission_pts_fields.append(QgsField("id_emi_source", QVariant.Int))
emission_pts_fields.append(QgsField("id_source", QVariant.Int))
emission_pts_fields.append(QgsField("d_rTOe", QVariant.Double, len=10, prec=2))
# update for QGIS 3 converting VectorWriter to QgsVectorFileWriter
# emission_pts_writer = VectorWriter(emission_pts_layer_path, None, emission_pts_fields, 0, sources_layer.crs())
emission_pts_writer = QgsVectorFileWriter(emission_pts_layer_path, "System",
emission_pts_fields, QgsWkbTypes.Point, sources_layer.crs(),
"ESRI Shapefile")
# initializes ray and emission point id
emission_pt_id = 0
for sources_feat in sources_feat_all:
# researches the receiver points in a rectangle created by the research_ray
# creates the search rectangle
rect = QgsRectangle()
rect.setXMinimum(sources_feat.geometry().boundingBox().xMinimum() - research_ray)
rect.setXMaximum(sources_feat.geometry().boundingBox().xMaximum() + research_ray)
rect.setYMinimum(sources_feat.geometry().boundingBox().yMinimum() - research_ray)
rect.setYMaximum(sources_feat.geometry().boundingBox().yMaximum() + research_ray)
receiver_pts_request = receivers_spIndex.intersects(rect)
distance_min = []
for receiver_pts_id in receiver_pts_request:
receiver_pts_feat = receivers_feat_all_dict[receiver_pts_id]
result = sources_feat.geometry().closestSegmentWithContext(receiver_pts_feat.geometry().asPoint())
distance_min_tmp = sqrt(result[0])
if distance_min_tmp <= research_ray:
distance_min.append(distance_min_tmp)
# defines segment max length
if len(distance_min) >= 1:
segment_max = min(distance_min) / 2
if segment_max < 2:
segment_max = 2
else:
continue
# splits the sources line in emission points at a fix distance (minimum distance/2) and create the emission point layer
# gets vertex
sources_geom = sources_feat.geometry()
if sources_geom.isMultipart():
sources_geom.convertToSingleType()
sources_feat_vertex_pt_all = sources_geom.asPolyline()
emission_pt_id_road = 0
for i in range(0, len(sources_feat_vertex_pt_all)):
pt1 = QgsPointXY(sources_feat_vertex_pt_all[i])
add_point_to_layer(emission_pts_writer, pt1,
[emission_pt_id, emission_pt_id_road, sources_feat.id(), segment_max])
emission_pt_id = emission_pt_id + 1
emission_pt_id_road = emission_pt_id_road + 1
if i < len(sources_feat_vertex_pt_all) - 1:
pt2 = QgsPoint(sources_feat_vertex_pt_all[i + 1])
x1 = pt1.x()
y1 = pt1.y()
x2 = pt2.x()
y2 = pt2.y()
if y2 == y1:
dx = segment_max
dy = 0
m = 0
elif x2 == x1:
dx = 0
dy = segment_max
else:
m = (y2 - y1) / (x2 - x1)
dx = sqrt((segment_max ** 2) / (1 + m ** 2))
dy = sqrt(((segment_max ** 2) * (m ** 2)) / (1 + m ** 2))
pt = pt1
while compute_distance(pt, pt2) > segment_max:
#.........这里部分代码省略.........