Python qgis.core.QgsRectangle() Examples
The following are 10
code examples of qgis.core.QgsRectangle().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
qgis.core
, or try the search function
.
Example #1
Source File: latLonTools.py From qgis-latlontools-plugin with GNU General Public License v2.0 | 7 votes |
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
Example #2
Source File: utils.py From qgis-earthengine-plugin with MIT License | 7 votes |
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)
Example #3
Source File: test_export.py From qfieldsync with GNU Lesser General Public License v3.0 | 5 votes |
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)
Example #4
Source File: gps_tool_data_view_utils.py From stdm with GNU General Public License v2.0 | 5 votes |
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()
Example #5
Source File: Map.py From qgis-earthengine-plugin with MIT License | 5 votes |
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)
Example #6
Source File: rb_result_renderer.py From quickmapservices with GNU General Public License v2.0 | 5 votes |
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()
Example #7
Source File: tiles.py From quickmapservices with GNU General Public License v2.0 | 5 votes |
def toQgsRectangle(self): return QgsRectangle(self.xmin, self.ymin, self.xmax, self.ymax)
Example #8
Source File: tiles.py From quickmapservices with GNU General Public License v2.0 | 5 votes |
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)
Example #9
Source File: tiles.py From quickmapservices with GNU General Public License v2.0 | 5 votes |
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)
Example #10
Source File: complexWindow.py From DsgTools with GNU General Public License v2.0 | 4 votes |
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