本文整理汇总了Python中safe.gui.tools.rectangle_map_tool.RectangleMapTool.rectangle方法的典型用法代码示例。如果您正苦于以下问题:Python RectangleMapTool.rectangle方法的具体用法?Python RectangleMapTool.rectangle怎么用?Python RectangleMapTool.rectangle使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类safe.gui.tools.rectangle_map_tool.RectangleMapTool
的用法示例。
在下文中一共展示了RectangleMapTool.rectangle方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ExtentSelectorDialog
# 需要导入模块: from safe.gui.tools.rectangle_map_tool import RectangleMapTool [as 别名]
# 或者: from safe.gui.tools.rectangle_map_tool.RectangleMapTool import rectangle [as 别名]
class ExtentSelectorDialog(QDialog, FORM_CLASS):
"""Dialog for letting user determine analysis extents.
"""
extent_defined = pyqtSignal(QgsRectangle, QgsCoordinateReferenceSystem)
clear_extent = pyqtSignal()
extent_selector_closed = pyqtSignal()
def __init__(self, iface, parent=None, extent=None, crs=None):
"""Constructor for the dialog.
:param iface: A Quantum GIS QGisAppInterface instance.
:type iface: QGisAppInterface
:param parent: Parent widget of this dialog
:type parent: QWidget
:param extent: Extent of the user's preferred analysis area.
:type extent: QgsRectangle
:param crs: Coordinate reference system for user defined analysis
extent.
:type crs: QgsCoordinateReferenceSystem
"""
QDialog.__init__(self, parent)
self.setupUi(self)
self.iface = iface
self.parent = parent
self.canvas = iface.mapCanvas()
self.previous_map_tool = None
# Prepare the map tool
self.tool = RectangleMapTool(self.canvas)
self.previous_map_tool = self.canvas.mapTool()
if extent is None and crs is None:
# Use the current map canvas extents as a starting point
self.tool.set_rectangle(self.canvas.extent())
else:
# Ensure supplied extent is in current canvas crs
transform = QgsCoordinateTransform(
crs,
self.canvas.mapRenderer().destinationCrs())
transformed_extent = transform.transformBoundingBox(extent)
self.tool.set_rectangle(transformed_extent)
self._populate_coordinates()
# Observe inputs for changes
self.x_minimum.valueChanged.connect(self._coordinates_changed)
self.y_minimum.valueChanged.connect(self._coordinates_changed)
self.x_maximum.valueChanged.connect(self._coordinates_changed)
self.y_maximum.valueChanged.connect(self._coordinates_changed)
# Draw the rubberband
self._coordinates_changed()
# Wire up button events
self.capture_button.clicked.connect(self.start_capture)
# Handle cancel
cancel_button = self.button_box.button(QtGui.QDialogButtonBox.Cancel)
cancel_button.clicked.connect(self.reject)
# Make sure to reshow this dialog when rectangle is captured
self.tool.rectangle_created.connect(self.stop_capture)
# Setup ok button
self.ok_button = self.button_box.button(QtGui.QDialogButtonBox.Ok)
self.ok_button.clicked.connect(self.accept)
# Set up context help
self.help_button = self.button_box.button(QtGui.QDialogButtonBox.Help)
# Allow toggling the help button
self.help_button.setCheckable(True)
self.help_button.toggled.connect(self.help_toggled)
self.main_stacked_widget.setCurrentIndex(1)
# Reset / Clear button
clear_button = self.button_box.button(QtGui.QDialogButtonBox.Reset)
clear_button.setText(self.tr('Clear'))
clear_button.clicked.connect(self.clear)
# Populate the bookmarks list and connect the combobox
self._populate_bookmarks_list()
self.bookmarks_list.currentIndexChanged.connect(
self.bookmarks_index_changed)
# Reinstate the last used radio button
settings = QSettings()
mode = settings.value(
'inasafe/analysis_extents_mode',
'HazardExposureView')
if mode == 'HazardExposureView':
self.hazard_exposure_view_extent.setChecked(True)
elif mode == 'HazardExposure':
self.hazard_exposure_only.setChecked(True)
elif mode == 'HazardExposureBookmark':
self.hazard_exposure_bookmark.setChecked(True)
elif mode == 'HazardExposureBoundingBox':
self.hazard_exposure_user_extent.setChecked(True)
show_warnings = settings.value(
'inasafe/show_extent_warnings',
True,
#.........这里部分代码省略.........
示例2: OsmDownloaderDialog
# 需要导入模块: from safe.gui.tools.rectangle_map_tool import RectangleMapTool [as 别名]
# 或者: from safe.gui.tools.rectangle_map_tool.RectangleMapTool import rectangle [as 别名]
class OsmDownloaderDialog(QDialog, FORM_CLASS):
"""Downloader for OSM data."""
def __init__(self, parent=None, iface=None):
"""Constructor for import dialog.
:param parent: Optional widget to use as parent
:type parent: QWidget
:param iface: An instance of QGisInterface
:type iface: QGisInterface
"""
QDialog.__init__(self, parent)
self.parent = parent
self.setupUi(self)
self.setWindowTitle(self.tr('InaSAFE OpenStreetMap Downloader'))
self.iface = iface
self.help_context = 'openstreetmap_downloader'
# creating progress dialog for download
self.progress_dialog = QProgressDialog(self)
self.progress_dialog.setAutoClose(False)
title = self.tr('InaSAFE OpenStreetMap Downloader')
self.progress_dialog.setWindowTitle(title)
# Set up context help
self.help_button = self.button_box.button(QtGui.QDialogButtonBox.Help)
# Allow toggling the help button
self.help_button.setCheckable(True)
self.help_button.toggled.connect(self.help_toggled)
self.stacked_widget.setCurrentIndex(1)
# Disable boundaries group box until boundary checkbox is ticked
self.boundary_group.setEnabled(False)
# set up the validator for the file name prefix
expression = QRegExp('^[A-Za-z0-9-_]*$')
validator = QRegExpValidator(expression, self.filename_prefix)
self.filename_prefix.setValidator(validator)
self.restore_state()
# Setup the rectangle map tool
self.canvas = iface.mapCanvas()
self.rectangle_map_tool = \
RectangleMapTool(self.canvas)
self.rectangle_map_tool.rectangle_created.connect(
self.update_extent_from_rectangle)
self.capture_button.clicked.connect(
self.drag_rectangle_on_map_canvas)
# Setup pan tool
self.pan_tool = QgsMapToolPan(self.canvas)
self.canvas.setMapTool(self.pan_tool)
# Setup helper for admin_level
json_file_path = resources_path('osm', 'admin_level_per_country.json')
if os.path.isfile(json_file_path):
self.countries = json.load(open(json_file_path))
self.bbox_countries = None
self.populate_countries()
# connect
self.country_comboBox.currentIndexChanged.connect(
self.update_helper_political_level)
self.admin_level_comboBox.currentIndexChanged.connect(
self.update_helper_political_level)
self.update_extent_from_map_canvas()
def update_helper_political_level(self):
"""To update the helper about the country and the admin_level."""
current_country = self.country_comboBox.currentText()
index = self.admin_level_comboBox.currentIndex()
current_level = self.admin_level_comboBox.itemData(index)
content = None
try:
content = \
self.countries[current_country]['levels'][str(current_level)]
if content == 'N/A' or content == 'fixme' or content == '':
raise KeyError
except KeyError:
content = self.tr('undefined')
finally:
text = self.tr('which represents %s in') % (content)
self.boundary_helper.setText(text)
def populate_countries(self):
"""Populate the combobox about countries and levels."""
for i in range(1, 12):
self.admin_level_comboBox.addItem(self.tr("Level %s" % i), i)
# Set current index to admin_level 8, the most common one
self.admin_level_comboBox.setCurrentIndex(7)
list_countries = self.countries.keys()
list_countries.sort()
for country in list_countries:
self.country_comboBox.addItem(country)
self.bbox_countries = {}
#.........这里部分代码省略.........
示例3: ExtentSelectorDialog
# 需要导入模块: from safe.gui.tools.rectangle_map_tool import RectangleMapTool [as 别名]
# 或者: from safe.gui.tools.rectangle_map_tool.RectangleMapTool import rectangle [as 别名]
class ExtentSelectorDialog(QDialog, FORM_CLASS):
"""Dialog for letting user determine analysis extents.
"""
extent_defined = pyqtSignal(QgsRectangle, QgsCoordinateReferenceSystem)
clear_extent = pyqtSignal()
extent_selector_closed = pyqtSignal()
def __init__(self, iface, parent=None, extent=None, crs=None):
"""Constructor for the dialog.
:param iface: A Quantum GIS QGisAppInterface instance.
:type iface: QGisAppInterface
:param parent: Parent widget of this dialog
:type parent: QWidget
:param extent: Extent of the user's preferred analysis area.
:type extent: QgsRectangle
:param crs: Coordinate reference system for user defined analysis
extent.
:type crs: QgsCoordinateReferenceSystem
"""
QDialog.__init__(self, parent)
self.setupUi(self)
self.iface = iface
self.parent = parent
self.canvas = iface.mapCanvas()
self.previous_map_tool = None
self.show_info()
# Prepare the map tool
self.tool = RectangleMapTool(self.canvas)
self.previous_map_tool = self.canvas.mapTool()
if extent is None and crs is None:
# Use the current map canvas extents as a starting point
self.tool.set_rectangle(self.canvas.extent())
else:
# Ensure supplied extent is in current canvas crs
transform = QgsCoordinateTransform(
crs,
self.canvas.mapRenderer().destinationCrs())
transformed_extent = transform.transformBoundingBox(extent)
self.tool.set_rectangle(transformed_extent)
self._populate_coordinates()
# Observe inputs for changes
self.x_minimum.valueChanged.connect(self._coordinates_changed)
self.y_minimum.valueChanged.connect(self._coordinates_changed)
self.x_maximum.valueChanged.connect(self._coordinates_changed)
self.y_maximum.valueChanged.connect(self._coordinates_changed)
# Draw the rubberband
self._coordinates_changed()
# Wire up button events
self.capture_button.clicked.connect(self.start_capture)
# Handle cancel
cancel_button = self.button_box.button(QtGui.QDialogButtonBox.Cancel)
cancel_button.clicked.connect(self.reject)
# Make sure to reshow this dialog when rectangle is captured
self.tool.rectangle_created.connect(self.stop_capture)
# Setup ok button
self.ok_button = self.button_box.button(QtGui.QDialogButtonBox.Ok)
self.ok_button.clicked.connect(self.accept)
# Set up context help
self.help_context = 'user_extents'
help_button = self.button_box.button(QtGui.QDialogButtonBox.Help)
help_button.clicked.connect(self.show_help)
# Reset / Clear button
clear_button = self.button_box.button(QtGui.QDialogButtonBox.Reset)
clear_button.setText(self.tr('Clear'))
clear_button.clicked.connect(self.clear)
# Populate the bookmarks list and connect the combobox
self._populate_bookmarks_list()
self.comboBox_bookmarks_list.currentIndexChanged.connect(
self.bookmarks_index_changed)
def show_help(self):
"""Load the help text for the dialog."""
show_context_help(self.help_context)
def show_info(self):
"""Show usage info to the user."""
# Read the header and footer html snippets
header = html_header()
footer = html_footer()
string = header
heading = m.Heading(self.tr('User Extents Tool'), **INFO_STYLE)
body = self.tr(
'This tool allows you to specify exactly which geographical '
'region should be used for your analysis. You can either '
'enter the coordinates directly into the input boxes below '
'(using the same CRS as the canvas is currently set to), or '
#.........这里部分代码省略.........
示例4: OsmDownloaderDialog
# 需要导入模块: from safe.gui.tools.rectangle_map_tool import RectangleMapTool [as 别名]
# 或者: from safe.gui.tools.rectangle_map_tool.RectangleMapTool import rectangle [as 别名]
class OsmDownloaderDialog(QDialog, FORM_CLASS):
"""Downloader for OSM data."""
def __init__(self, parent=None, iface=None):
"""Constructor for import dialog.
:param parent: Optional widget to use as parent
:type parent: QWidget
:param iface: An instance of QGisInterface
:type iface: QGisInterface
"""
QDialog.__init__(self, parent)
self.parent = parent
self.setupUi(self)
self.setWindowTitle(self.tr('InaSAFE OpenStreetMap Downloader'))
self.iface = iface
self.buildings_url = 'http://osm.linfiniti.com/buildings-shp'
self.building_points_url = \
'http://osm.linfiniti.com/building-points-shp'
self.roads_url = 'http://osm.linfiniti.com/roads-shp'
self.help_context = 'openstreetmap_downloader'
# creating progress dialog for download
self.progress_dialog = QProgressDialog(self)
self.progress_dialog.setAutoClose(False)
title = self.tr('InaSAFE OpenStreetMap Downloader')
self.progress_dialog.setWindowTitle(title)
# Set up context help
help_button = self.button_box.button(QtGui.QDialogButtonBox.Help)
help_button.clicked.connect(self.show_help)
self.show_info()
# set up the validator for the file name prefix
expression = QRegExp('^[A-Za-z0-9-_]*$')
validator = QRegExpValidator(expression, self.filename_prefix)
self.filename_prefix.setValidator(validator)
# Set Proxy in webpage
proxy = get_proxy()
self.network_manager = QNetworkAccessManager(self)
if proxy is not None:
self.network_manager.setProxy(proxy)
self.restore_state()
# Setup the rectangle map tool
self.canvas = iface.mapCanvas()
self.rectangle_map_tool = \
RectangleMapTool(self.canvas)
self.rectangle_map_tool.rectangle_created.connect(
self.update_extent_from_rectangle)
self.button_extent_rectangle.clicked.connect(
self.drag_rectangle_on_map_canvas)
# Setup pan tool
self.pan_tool = QgsMapToolPan(self.canvas)
self.canvas.setMapTool(self.pan_tool)
self.update_extent_from_map_canvas()
def show_info(self):
"""Show usage info to the user."""
# Read the header and footer html snippets
header = html_header()
footer = html_footer()
string = header
heading = m.Heading(self.tr('OSM Downloader'), **INFO_STYLE)
body = self.tr(
'This tool will fetch building (\'structure\') or road ('
'\'highway\') data from the OpenStreetMap project for you. '
'The downloaded data will have InaSAFE keywords defined and a '
'default QGIS style applied. To use this tool effectively:'
)
tips = m.BulletedList()
tips.add(self.tr(
'Your current extent, when opening this window, will be used to '
'determine the area for which you want data to be retrieved.'
'You can interactively select the area by using the '
'\'select on map\' button - which will temporarily hide this '
'window and allow you to drag a rectangle on the map. After you '
'have finished dragging the rectangle, this window will '
'reappear.'))
tips.add(self.tr(
'Check the output directory is correct. Note that the saved '
'dataset will be called either roads.shp or buildings.shp (and '
'associated files).'
))
tips.add(self.tr(
'By default simple file names will be used (e.g. roads.shp, '
'buildings.shp). If you wish you can specify a prefix to '
'add in front of this default name. For example using a prefix '
'of \'padang-\' will cause the downloaded files to be saved as '
'\'padang-roads.shp\' and \'padang-buildings.shp\'. Note that '
'the only allowed prefix characters are A-Z, a-z, 0-9 and the '
'characters \'-\' and \'_\'. You can leave this blank if you '
'prefer.'
#.........这里部分代码省略.........
示例5: ExtentSelectorDialog
# 需要导入模块: from safe.gui.tools.rectangle_map_tool import RectangleMapTool [as 别名]
# 或者: from safe.gui.tools.rectangle_map_tool.RectangleMapTool import rectangle [as 别名]
class ExtentSelectorDialog(QDialog, FORM_CLASS):
"""Dialog for letting user determine analysis extents.
"""
extent_defined = pyqtSignal(QgsRectangle, QgsCoordinateReferenceSystem)
clear_extent = pyqtSignal()
extent_selector_closed = pyqtSignal()
def __init__(self, iface, parent=None, extent=None, crs=None):
"""Constructor for the dialog.
:param iface: A Quantum GIS QGisAppInterface instance.
:type iface: QGisAppInterface
:param parent: Parent widget of this dialog
:type parent: QWidget
:param extent: Extent of the user's preferred analysis area.
:type extent: QgsRectangle
:param crs: Coordinate reference system for user defined analysis
extent.
:type crs: QgsCoordinateReferenceSystem
"""
QDialog.__init__(self, parent)
self.setupUi(self)
self.iface = iface
self.parent = parent
self.canvas = iface.mapCanvas()
self.previous_map_tool = None
self.show_info()
# Prepare the map tool
self.tool = RectangleMapTool(self.canvas)
self.previous_map_tool = self.canvas.mapTool()
if extent is None and crs is None:
# Use the current map canvas extents as a starting point
self.tool.set_rectangle(self.canvas.extent())
else:
# Ensure supplied extent is in current canvas crs
transform = QgsCoordinateTransform(
crs,
self.canvas.mapRenderer().destinationCrs())
transformed_extent = transform.transformBoundingBox(extent)
self.tool.set_rectangle(transformed_extent)
self._populate_coordinates()
# Observe inputs for changes
self.x_minimum.valueChanged.connect(self._coordinates_changed)
self.y_minimum.valueChanged.connect(self._coordinates_changed)
self.x_maximum.valueChanged.connect(self._coordinates_changed)
self.y_maximum.valueChanged.connect(self._coordinates_changed)
# Draw the rubberband
self._coordinates_changed()
# Wire up button events
self.capture_button.clicked.connect(self.start_capture)
# Handle cancel
cancel_button = self.button_box.button(QtGui.QDialogButtonBox.Cancel)
cancel_button.clicked.connect(self.reject)
# Make sure to reshow this dialog when rectangle is captured
self.tool.rectangle_created.connect(self.stop_capture)
# Setup ok button
ok_button = self.button_box.button(QtGui.QDialogButtonBox.Ok)
ok_button.clicked.connect(self.accept)
# Set up context help
self.help_context = 'user_extents'
help_button = self.button_box.button(QtGui.QDialogButtonBox.Help)
help_button.clicked.connect(self.show_help)
# Reset / Clear button
clear_button = self.button_box.button(QtGui.QDialogButtonBox.Reset)
clear_button.setText(self.tr('Clear'))
clear_button.clicked.connect(self.clear)
def show_help(self):
"""Load the help text for the dialog."""
show_context_help(self.help_context)
def show_info(self):
"""Show usage info to the user."""
# Read the header and footer html snippets
header = html_header()
footer = html_footer()
string = header
heading = m.Heading(self.tr('User Extents Tool'), **INFO_STYLE)
body = self.tr(
'This tool allows you to specify exactly which geographical '
'region should be used for your analysis. You can either '
'enter the coordinates directly into the input boxes below '
'(using the same CRS as the canvas is currently set to), or '
'you can interactively select the area by using the \'select '
'on map\' button - which will temporarily hide this window and '
'allow you to drag a rectangle on the map. After you have '
'finished dragging the rectangle, this window will reappear. '
'If you enable the \'Toggle scenario outlines\' tool on the '
#.........这里部分代码省略.........