ArcGIS Pro二次開發打開對話框
在ArcGIS Pro的二次開發中,很多時候需要加載或者保存特定格式的數據庫,如選擇FileGDB中的數據進行加載、選擇.sde數據庫中的文件進行加載、加載支持的柵格數據等等,很多時候需要需要利用Windows自帶的打開或者保存對話框,進行數據的過濾和保存,這樣做起來比較繁瑣,最新的ArcGIS Pro開發包針對GIS的各種格式,封裝了專門的打開和保存的對話框,如下
ArcGIS.Desktop.Catalog.OpenItemDialog
ArcGIS.Desktop.Catalog.SaveItemDialog
在線的幫助地址爲https://pro.arcgis.com/en/pro-app/sdk/api-reference/#topic8992.html
和https://pro.arcgis.com/en/pro-app/sdk/api-reference/#topic9001.html
這兩個對話框使用的使用方式簡單
如打開對話框
OpenItemDialog searchGdbDialog = new OpenItemDialog
{
Title = "Find GDB",
InitialLocation = @"C:\Data",
MultiSelect = false,
Filter = ItemFilters.geodatabases
};
var ok = searchGdbDialog.ShowDialog();
if (ok != true) return;
var selectedItems = searchGdbDialog.Items;
foreach (var selectedItem in selectedItems)
GdbPath = selectedItem.Path;
這個例子是打開GDB的數據,通過Filter屬性進行選擇過濾,運行結果如下:
保存對話框如下
// Create the log file and write the current Folder-Connection's to it
SaveItemDialog saveDialog = new SaveItemDialog();
saveDialog.Title = "Export the current selected map series item";
saveDialog.OverwritePrompt = true;
saveDialog.DefaultExt = "pdf";
// If the save dialog was not dismissed, create the file
if (saveDialog.ShowDialog() == true)
{
await QueuedTask.Run(() =>
{
Layout layout = layoutItem.GetLayout();
if (layout == null)
return;
// Create PDF format with appropriate settings
PDFFormat PDF = new PDFFormat()
{
Resolution = 300,
OutputFileName = saveDialog.FilePath
};
if (PDF.ValidateOutputFilePath())
{
layout.Export(PDF);
}
});
這個是保存當前地圖爲PDF的例子,運行結果如下
可以通過過濾屬性Filter進行需要數據格式的過濾操作,支持過濾的格式基本上涵蓋了所有GIS支持的格式,支持的格式如下:
Name |
Description |
annotation |
Supports browsing for annotation feature classes |
cad |
Supports browsing CAD datasets and the feature classes they contain |
composite_addToMap |
Supports browsing for items and datasets that can be added to a map. As a composite filter, the default filter allows you to browse for anything that is supported, but focused filters are also available to browse just for layers or geodatabase items, for example, that you want to add to a map. |
composite_addToStereoMap |
Supports browsing for items and datasets that can be added to a stereo map. As a composite filter, the default filter allows you to browse for anything that is supported, but focused filters are also available to browse just for layers or geodatabase items, for example, that you want to add to a stereo map. |
composite_elevationSource |
Supports browsing for web layers and datasets that can be used to define the elevation surface of a globe. As a composite filter, the default filter allows you to browse for anything that is supported, but focused filters are also available to browse just for images services, for example, that you want to define the ground. |
composite_maps_import |
Supports browsing for maps and layouts that can be imported to a project. As a composite filter, the default filter allows you to browse for anything that is supported, but focused filters are also available to browse just for ArcGIS Pro map or layout files, for example, that you want to import. |
databases |
Supports browsing all types of databases supported by ArcGIS Pro. Both database connections in a project and databases stored on a local or network computer can be browsed. |
default_addToMap |
Supports browsing all items or datasets that can be added to a map. This is the default filter in the composite_addToMap filter. |
default_addToStereoMap |
Supports browsing all items or datasets that can be added to a stereo map. This is the default filter in the composite_addToStereoMap filter. |
default_import |
Supports browsing all items that can be imported to a project. This is the default filter in the composite_maps_import filter. |
dimensions |
Supports browsing for dimension feature classes |
featureClasses_all |
Supports browsing all types of feature classes |
featureDatasets_all |
Supports browsing all types of feature datasets |
folders |
Supports browsing folder connections in the project and folders on a local or network computer |
geodatabaseItems_all |
Supports browsing all types of items stored in a geodatabase |
geodatabases |
Supports browsing all types of geodatabases supported by ArcGIS Pro. Both database connections in a project and databases stored on a local or network computer can be browsed. |
kml |
Supports browsing Keyhole Markup Language files |
layers_allFileTypes |
Supports browsing layer files and layer packages available from the active portal and from a local or network computer |
locators_allTypes |
Supports browsing all types of locators, including locator files and ArcGIS Server geocoding services |
maps_all |
Supports browsing maps in the project and all types of maps stored on a local or network computer |
packages |
Supports browsing all types of packages available from the active portal and stored on a local or network computer |
project_templates |
Supports browsing project templates available from the active portal and from a local or network computer |
projects |
Supports browsing projects and project packages available from the active portal and from a local or network computer |
rasters |
Supports browsing all types of rasters, including mosaic datasets and file-based raster datasets |
services_addToMap |
Supports browsing all types of web layers from the active portal and services from server connections in the project that can be added to maps |
services_addToStereoMap |
Supports browsing all types of web layers from the active portal and services from server connections in the project that can be added to stereo maps |
services_all |
Supports browsing all types of web layers from the active portal and services from server connections in the project that can be used in ArcGIS Pro |
services_feature |
Supports browsing feature services from the active portal and services from server connections in the project that can be added to maps |
services_image |
Supports browsing image services from the active portal and services from server connections in the project that can be added to maps |
services_map |
Supports browsing map services from the active portal and services from server connections in the project that can be added to maps |
shapefiles |
Supports browsing for shapefiles stored on a local or network computer |
styleFiles |
Supports browsing styles accessed from the active portal or stored on a local or network computer |
tables_all |
Supports browsing all types of tables |
taskFiles |
Supports browsing for task files stored on a local or network computer |
textFiles |
Supports browsing all types of text files |
tinDatasets |
Supports browsing for TIN datasets stored on a local or network computer |
toolboxes |
Supports browsing for all types of toolboxes |
tools |
Supports browsing for tools stored in toolboxes |
videos |
Support browsing for video files |
workspaces_all |
Supports browsing for all types of workspaces, including folders, geodatabases, and feature datasets |
相關地址如下
https://pro.arcgis.com/en/pro-app/sdk/api-reference/#topic8982.html