本文整理汇总了Python中qgis.core.QgsRectangle方法的典型用法代码示例。如果您正苦于以下问题:Python core.QgsRectangle方法的具体用法?Python core.QgsRectangle怎么用?Python core.QgsRectangle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类qgis.core
的用法示例。
在下文中一共展示了core.QgsRectangle方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: zoomTo
# 需要导入模块: from qgis import core [as 别名]
# 或者: from qgis.core import QgsRectangle [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
示例2: test_copy
# 需要导入模块: from qgis import core [as 别名]
# 或者: from qgis.core import QgsRectangle [as 别名]
def test_copy(self):
source_folder = tempfile.mkdtemp()
export_folder = tempfile.mkdtemp()
shutil.copytree(os.path.join(test_data_folder(), 'simple_project'), os.path.join(source_folder,
'simple_project'))
project = self.load_project(os.path.join(source_folder, 'simple_project', 'project.qgs'))
extent = QgsRectangle()
offline_editing = QgsOfflineEditing()
offline_converter = OfflineConverter(project, export_folder, extent, offline_editing)
offline_converter.convert()
files = os.listdir(export_folder)
self.assertIn('project_qfield.qgs', files)
self.assertIn('france_parts_shape.shp', files)
self.assertIn('france_parts_shape.dbf', files)
self.assertIn('curved_polys.gpkg', files)
self.assertIn('spatialite.db', files)
dcim_folder = os.path.join(export_folder, "DCIM")
dcim_files = os.listdir(dcim_folder)
self.assertIn('qfield-photo_1.jpg', dcim_files)
self.assertIn('qfield-photo_2.jpg', dcim_files)
self.assertIn('qfield-photo_3.jpg', dcim_files)
dcim_subfolder = os.path.join(dcim_folder, "subfolder")
dcim_subfiles = os.listdir(dcim_subfolder)
self.assertIn('qfield-photo_sub_1.jpg', dcim_subfiles)
self.assertIn('qfield-photo_sub_2.jpg', dcim_subfiles)
self.assertIn('qfield-photo_sub_3.jpg', dcim_subfiles)
shutil.rmtree(export_folder)
shutil.rmtree(source_folder)
示例3: set_layer_extent
# 需要导入模块: from qgis import core [as 别名]
# 或者: from qgis.core import QgsRectangle [as 别名]
def set_layer_extent(map_canvas, gpx_layer):
"""
Sets the layer extent and zooms in to 1:1 scale
:param gpx_layer: GPX layer object
:param map_canvas: Map canvas object
:return: None
:rtype: None
"""
x_min, x_max, y_min, y_max = gpx_layer.GetExtent()
extent = q_core.QgsRectangle(x_min, y_min, x_max, y_max)
extent.scale(1.1)
map_canvas.setExtent(extent)
map_canvas.refresh()
示例4: centerObject
# 需要导入模块: from qgis import core [as 别名]
# 或者: from qgis.core import QgsRectangle [as 别名]
def centerObject(feature, zoom=None):
"""
Centers the map view on a given object.
https://developers.google.com/earth-engine/api_docs#map.centerobject
Uses:
>>> from ee_plugin import Map
>>> Map.centerObject(feature)
"""
feature = ee.Feature(feature)
if not zoom:
# make sure our geometry is in geo
rect = feature.geometry().transform(ee.Projection('EPSG:4326'), 1)
# get coordinates
coords = rect.bounds().getInfo()['coordinates'][0]
xmin = coords[0][0]
ymin = coords[0][1]
xmax = coords[2][0]
ymax = coords[2][1]
# construct QGIS geometry
rect = QgsRectangle(xmin, ymin, xmax, ymax)
# transform rect to a crs used by current project
crs_src = QgsCoordinateReferenceSystem(4326)
crs_dst = QgsCoordinateReferenceSystem(QgsProject.instance().crs())
geo2proj = QgsCoordinateTransform(crs_src, crs_dst, QgsProject.instance())
rect_proj = geo2proj.transform(rect)
# center geometry
iface.mapCanvas().zoomToFeatureExtent(rect_proj)
else:
# set map center to feature centroid at a specified zoom
center = feature.geometry().centroid().coordinates().getInfo()
setCenter(center[0], center[1], zoom)
示例5: geom_to_geo
# 需要导入模块: from qgis import core [as 别名]
# 或者: from qgis.core import QgsRectangle [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)
示例6: center_to_point
# 需要导入模块: from qgis import core [as 别名]
# 或者: from qgis.core import QgsRectangle [as 别名]
def center_to_point(self, point):
canvas = self.iface.mapCanvas()
new_extent = QgsRectangle(canvas.extent())
new_extent.scale(1, point)
canvas.setExtent(new_extent)
canvas.refresh()
示例7: toQgsRectangle
# 需要导入模块: from qgis import core [as 别名]
# 或者: from qgis.core import QgsRectangle [as 别名]
def toQgsRectangle(self):
return QgsRectangle(self.xmin, self.ymin, self.xmax, self.ymax)
示例8: extent
# 需要导入模块: from qgis import core [as 别名]
# 或者: from qgis.core import QgsRectangle [as 别名]
def extent(self):
size = self.tsize1 / 2 ** (self.zoom - 1)
if self.serviceInfo.tile_ranges is None:
return QgsRectangle(self.xmin * size - self.tsize1, self.tsize1 - (self.ymax + 1) * size,
(self.xmax + 1) * size - self.tsize1, self.tsize1 - self.ymin * size)
else:
originX = self.serviceInfo.originX
originY = self.serviceInfo.originY
return QgsRectangle(originX + self.xmin * size, originY - (self.ymax + 1) * size,
originX + (self.xmax + 1) * size, originY - self.ymin * size)
示例9: getTileRect
# 需要导入模块: from qgis import core [as 别名]
# 或者: from qgis.core import QgsRectangle [as 别名]
def getTileRect(self, zoom, x, y):
size = self.tsize1 / 2 ** (zoom - 1)
return QgsRectangle(x * size - self.tsize1, self.tsize1 - y * size, (x + 1) * size - self.tsize1,
self.tsize1 - (y + 1) * size)
示例10: on_zoomButton_clicked
# 需要导入模块: from qgis import core [as 别名]
# 或者: from qgis.core import QgsRectangle [as 别名]
def on_zoomButton_clicked(self):
"""
Slot used to zoom the mapcanvas to the features associated to a complex
"""
#case no item is selected we should warn the user
if len(self.treeWidget.selectedItems()) == 0:
QMessageBox.warning(self.iface.mainWindow(), self.tr("Warning!"), self.tr("Please, select an item to zoom."))
return
item = self.treeWidget.selectedItems()[0]
#checking if the item is a complex (it should have depth = 2)
if self.depth(item) == 2:
bbox = QgsRectangle()
for i in range(item.childCount()):
aggregated_item = item.child(i)
aggregated_class = aggregated_item.text(0)
#getting the layer the needs to be updated
aggregated_layer = None
layers = self.iface.mapCanvas().layers()
for layer in layers:
if layer.name() == aggregated_class:
aggregated_layer = layer
break
if not aggregated_layer:
QMessageBox.warning(self.iface.mainWindow(), self.tr("Warning!"), self.tr("The associated classes must be loaded in the table of contents."))
return
for j in range(aggregated_item.childCount()):
id = aggregated_item.child(j).text(0)
freq = QgsFeatureRequest()
freq.setFilterFid(int(id))
feature = next(layer.getFeatures( freq ))
if j==0 and i == 0:
bbox=feature.geometry().boundingBox()
bbox.combineExtentWith(feature.geometry().boundingBox())
self.iface.mapCanvas().setExtent(bbox)
self.iface.mapCanvas().refresh()
else:
QMessageBox.warning(self.iface.mainWindow(), self.tr("Warning!"), self.tr("Select a complex."))
return