内容

项目

创建一个空项目

1
2
3
//Create an empty project. The project will be created in the default folder
//It will be named MyProject1, MyProject2, or similar...
await Project.CreateAsync();

创建具有指定名称的新项目

1
2
3
4
5
6
7
8
//Settings used to create a new project
CreateProjectSettings projectSettings = new CreateProjectSettings()
{
//Sets the name of the project that will be created
Name = @"C:\Data\MyProject1\MyProject1.aprx"
};
//Create the new project
await Project.CreateAsync(projectSettings);

使用 Pro 的默认设置创建新项目

1
2
3
4
//Get Pro's default project settings.
var defaultProjectSettings = Project.GetDefaultProjectSettings();
//Create a new project using the default project settings
await Project.CreateAsync(defaultProjectSettings);

使用自定义模板文件新建项目

1
2
3
4
5
6
7
8
9
10
11
12
//Settings used to create a new project
CreateProjectSettings projectSettings = new CreateProjectSettings()
{
//Sets the project's name
Name = "New Project",
//Path where new project will be stored in
LocationPath = @"C:\Data\NewProject",
//Sets the project template that will be used to create the new project
TemplatePath = @"C:\Data\MyProject1\CustomTemplate.aptx"
};
//Create the new project
await Project.CreateAsync(projectSettings);

使用 ArcGIS Pro 提供的模板创建工程

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
//Settings used to create a new project
CreateProjectSettings proTemplateSettings = new CreateProjectSettings()
{
//Sets the project's name
Name = "New Project",
//Path where new project will be stored in
LocationPath = @"C:\Data\NewProject",
//Select which Pro template you like to use
TemplateType = TemplateType.Catalog
//TemplateType = TemplateType.LocalScene
//TemplateType = TemplateType.GlobalScene
//TemplateType = TemplateType.Map
};
//Create the new project
await Project.CreateAsync(proTemplateSettings);

打开现有项目

1
2
//Opens an existing project or project package
await Project.OpenAsync(@"C:\Data\MyProject1\MyProject1.aprx");

获取当前项目

1
2
//Gets the current project
var project = Project.Current;

获取当前项目的位置

1
2
//Gets the location of the current project; that is, the path to the current project file (*.aprx)  
string projectPath = Project.Current.URI;

获取项目的默认 gdb 路径

1
var projGDBPath = Project.Current.DefaultGeodatabasePath;

保存项目

1
2
//Saves the project
await Project.Current.SaveAsync();

检查是否需要保存项目

1
2
//The project's dirty state indicates changes made to the project have not yet been saved. 
bool isProjectDirty = Project.Current.IsDirty;

另存为项目

1
2
3
//Saves a copy of the current project file (*.aprx) to the specified location with the specified file name, 
//then opens the new project file
await Project.Current.SaveAsAsync(@"C:\Data\MyProject1\MyNewProject1.aprx");

关闭项目

1
2
//A project cannot be closed using the ArcGIS Pro API. 
//A project is only closed when another project is opened, a new one is created, or the application is shutdown.

如何向工程添加新地图

1
2
3
4
5
6
await QueuedTask.Run(() =>
{
//Note: see also MapFactory in ArcGIS.Desktop.Mapping
var map = MapFactory.Instance.CreateMap("New Map", MapType.Map, MapViewingMode.Map, Basemap.Oceans);
ProApp.Panes.CreateMapPaneAsync(map);
});

项目项

将文件夹连接项添加到当前项目

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
//Adding a folder connection
string folderPath = "@C:\\myDataFolder";
var folder = await QueuedTask.Run(() =>
{
//Create the folder connection project item
var item = ItemFactory.Instance.Create(folderPath) as IProjectItem;
//If it is succesfully added to the project, return it otherwise null
return Project.Current.AddItem(item) ? item as FolderConnectionProjectItem : null;
});

//Adding a Geodatabase:
string gdbPath = "@C:\\myDataFolder\\myData.gdb";
var newlyAddedGDB = await QueuedTask.Run(() =>
{
//Create the File GDB project item
var item = ItemFactory.Instance.Create(gdbPath) as IProjectItem;
//If it is succesfully added to the project, return it otherwise null
return Project.Current.AddItem(item) ? item as GDBProjectItem : null;
});

获取所有项目项

1
2
3
4
5
IEnumerable<Item> allProjectItems = Project.Current.GetItems<Item>();
foreach (var pi in allProjectItems)
{
//Do Something
}

获取项目的所有“MapProjectItems”

1
2
3
4
5
6
7
8
9
10
IEnumerable<MapProjectItem> newMapItemsContainer = project.GetItems<MapProjectItem>();

await QueuedTask.Run(() =>
{
foreach (var mp in newMapItemsContainer)
{
//Do Something with the map. For Example:
Map myMap = mp.GetMap();
}
});

获取特定的“MapProjectItem”

1
MapProjectItem mapProjItem = Project.Current.GetItems<MapProjectItem>().FirstOrDefault(item => item.Name.Equals("EuropeMap"));

获取所有“样式项目项”

1
2
3
4
5
6
IEnumerable<StyleProjectItem> newStyleItemsContainer = null;
newStyleItemsContainer = Project.Current.GetItems<StyleProjectItem>();
foreach (var styleItem in newStyleItemsContainer)
{
//Do Something with the style.
}

获取特定的“样式项目项”

1
2
3
4
5
var container = Project.Current.GetItems<StyleProjectItem>();
StyleProjectItem testStyle = container.FirstOrDefault(style => (style.Name == "ArcGIS 3D"));
StyleItem cone = null;
if (testStyle != null)
cone = testStyle.LookupItem(StyleItemType.PointSymbol, "Cone_Volume_3");

获取“收藏夹”样式项目项

1
2
3
4
5
var fav_style_item = await QueuedTask.Run(() =>
{
var containerStyle = Project.Current.GetProjectItemContainer("Style");
return containerStyle.GetItems().OfType<StyleProjectItem>().First(item => item.TypeID == "personal_style");
});

获取所有“GDBProjectItems”

1
2
3
4
5
6
IEnumerable<GDBProjectItem> newGDBItemsContainer = null;
newGDBItemsContainer = Project.Current.GetItems<GDBProjectItem>();
foreach (var GDBItem in newGDBItemsContainer)
{
//Do Something with the GDB.
}

获取特定的“GDBProjectItem”

1
GDBProjectItem GDBProjItem = Project.Current.GetItems<GDBProjectItem>().FirstOrDefault(item => item.Name.Equals("myGDB"));

获取所有“服务器连接项目项”

1
2
3
4
5
6
IEnumerable<ServerConnectionProjectItem> newServerConnections = null;
newServerConnections = project.GetItems<ServerConnectionProjectItem>();
foreach (var serverItem in newServerConnections)
{
//Do Something with the server connection.
}

获取特定的“服务器连接项目项”

1
ServerConnectionProjectItem serverProjItem = Project.Current.GetItems<ServerConnectionProjectItem>().FirstOrDefault(item => item.Name.Equals("myServer"));

获取项目中的所有文件夹连接

1
2
3
4
5
6
//Gets all the folder connections in the current project
var projectFolders = Project.Current.GetItems<FolderConnectionProjectItem>();
foreach (var FolderItem in projectFolders)
{
//Do Something with the Folder connection.
}

获取特定文件夹连接

1
2
//Gets a specific folder connection in the current project
FolderConnectionProjectItem myProjectFolder = Project.Current.GetItems<FolderConnectionProjectItem>().FirstOrDefault(folderPI => folderPI.Name.Equals("myDataFolder"));

删除特定文件夹连接

1
2
3
4
// Remove a folder connection from a project; the folder stored on the local disk or the network is not deleted
FolderConnectionProjectItem folderToRemove = Project.Current.GetItems<FolderConnectionProjectItem>().FirstOrDefault(myfolder => myfolder.Name.Equals("PlantSpecies"));
if (folderToRemove != null)
Project.Current.RemoveItem(folderToRemove as IProjectItem);

获取特定的“布局项目项”

1
LayoutProjectItem layoutProjItem = Project.Current.GetItems<LayoutProjectItem>().FirstOrDefault(item => item.Name.Equals("myLayout"));

获取项目中的所有布局

1
2
3
4
5
6
//Gets all the layouts in the current project
var projectLayouts = Project.Current.GetItems<LayoutProjectItem>();
foreach (var layoutItem in projectLayouts)
{
//Do Something with the layout
}

获取特定的“地理处理项目项”

1
GeoprocessingProjectItem GPProjItem = Project.Current.GetItems<GeoprocessingProjectItem>().FirstOrDefault(item => item.Name.Equals("myToolbox"));

获取工程中的所有地理处理工程项

1
2
3
4
5
6
//Gets all the GeoprocessingProjectItem in the current project
var GPItems = Project.Current.GetItems<GeoprocessingProjectItem>();
foreach (var tbx in GPItems)
{
//Do Something with the toolbox
}

在项目中搜索特定项目

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
List<Item> _mxd = new List<Item>();
//Gets all the folder connections in the current project
var allFoldersItem = Project.Current.GetItems<FolderConnectionProjectItem>();
if (allFoldersItem != null)
{
//iterate through all the FolderConnectionProjectItems found
foreach (var folderItem in allFoldersItem)
{
//Search for mxd files in that folder connection and add it to the List<T>
//Note:ArcGIS Pro automatically creates and dynamically updates a searchable index as you build and work with projects.
//Items are indexed when they are added to a project.
//The first time a folder or database is indexed, indexing may take a while if it contains a large number of items.
//While the index is being created, searches will not return any results.
_mxd.AddRange(folderItem.GetItems());
}
}

获取默认项目文件夹

1
2
3
4
5
6
7
8
9
10
11
12
//Get Pro's default project settings.
var defaultSettings = Project.GetDefaultProjectSettings();
var defaultProjectPath = defaultSettings.LocationPath;
if (defaultProjectPath == null)
{
// If not set, projects are saved in the user's My Documents\ArcGIS\Projects folder;
// this folder is created if it doesn't already exist.
defaultProjectPath = System.IO.Path.Combine(
System.Environment.GetFolderPath(
Environment.SpecialFolder.MyDocuments),
@"ArcGIS\Projects");
}

刷新文件夹连接项的子项

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
var contentItem = Project.Current.GetItems<FolderConnectionProjectItem>().First();
//var contentItem = ...
//Check if the MCT is required for Refresh()
if (contentItem.IsMainThreadRequired)
{
//QueuedTask.Run must be used if item.IsMainThreadRequired
//returns true
QueuedTask.Run(() => contentItem.Refresh());
}
else
{
//if item.IsMainThreadRequired returns false, any
//thread can be used to invoke Refresh(), though
//BackgroundTask is preferred.
contentItem.Refresh();

//Or, via BackgroundTask
ArcGIS.Core.Threading.Tasks.BackgroundTask.Run(() =>
contentItem.Refresh(), ArcGIS.Core.Threading.Tasks.BackgroundProgressor.None);
}

获取项目类别

1
2
3
// Get the ItemCategories with which an item is associated
Item gdb = ItemFactory.Instance.Create(@"E:\CurrentProject\RegionalPolling\polldata.gdb");
List<ItemCategory> gdbItemCategories = gdb.ItemCategories;

使用项目类别

1
2
3
4
// Browse items using an ItemCategory as a filter
IEnumerable<Item> gdbContents = gdb.GetItems();
IEnumerable<Item> filteredGDBContents1 = gdbContents.Where(item => item.ItemCategories.OfType<ItemCategoryDataSet>().Any());
IEnumerable<Item> filteredGDBContents2 = new ItemCategoryDataSet().Items(gdbContents);

使用模板创建项目

1
2
3
4
5
6
7
8
9
10
11
12
13
var projectFolder = System.IO.Path.Combine(
System.Environment.GetFolderPath(
Environment.SpecialFolder.MyDocuments),
@"ArcGIS\Projects");

CreateProjectSettings ps = new CreateProjectSettings()
{
Name = "MyProject",
LocationPath = projectFolder,
TemplatePath = @"C:\data\my_templates\custom_template.aptx"
};

var project = await Project.CreateAsync(ps);

选择项目容器 - 用于 SelectItemAsync

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
//Use Project.Current.ProjectItemContainers
var folderContainer = Project.Current.ProjectItemContainers.First(c => c.Path == "FolderConnection");
var gdbContainer = Project.Current.ProjectItemContainers.First(c => c.Path == "GDB");
var mapContainer = Project.Current.ProjectItemContainers.First(c => c.Path == "Map");
var layoutContainer = Project.Current.ProjectItemContainers.First(c => c.Path == "Layout");
var toolboxContainer = Project.Current.ProjectItemContainers.First(c => c.Path == "GP");
//etc.

//or...use Project.Current.GetProjectItemContainer

folderContainer = Project.Current.GetProjectItemContainer("FolderConnection");
gdbContainer = Project.Current.GetProjectItemContainer("GDB");
mapContainer = Project.Current.GetProjectItemContainer("Map");
layoutContainer = Project.Current.GetProjectItemContainer("Layout");
toolboxContainer = Project.Current.GetProjectItemContainer("GP");
//etc.

项目项:获取项或查找项

1
2
3
4
5
6
7
8
9
10
11
12
13
14
//GetItems searches project content
var map = Project.Current.GetItems<MapProjectItem>().FirstOrDefault(m => m.Name == "Map1");
var layout = Project.Current.GetItems<LayoutProjectItem>().FirstOrDefault(m => m.Name == "Layout1");
var folders = Project.Current.GetItems<FolderConnectionProjectItem>();
var style = Project.Current.GetItems<StyleProjectItem>().FirstOrDefault(s => s.Name == "ArcGIS 3D");

//Find item uses a catalog path. The path can be to a file or dataset
var fcPath = @"C:\Pro\CommunitySampleData\Interacting with Maps\Interacting with Maps.gdb\Crimes";
var pdfPath = @"C:\Temp\Layout1.pdf";
var imgPath = @"C:\Temp\AddinDesktop16.png";

var fc = Project.Current.FindItem(fcPath);
var pdf = Project.Current.FindItem(pdfPath);
var img = Project.Current.FindItem(imgPath);

在目录窗格中选择一个项目

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
//Get the catalog pane
ArcGIS.Desktop.Core.IProjectWindow projectWindow = Project.GetCatalogPane();
//or get the active catalog view...
//ArcGIS.Desktop.Core.IProjectWindow projectWindow = Project.GetActiveCatalogWindow();

//eg Find a toolbox in the project
string gpName = "Interacting with Maps.tbx";
var toolbox = Project.Current.GetItems<GeoprocessingProjectItem>().FirstOrDefault(tbx => tbx.Name == gpName);
//Select it under Toolboxes
projectWindow.SelectItemAsync(toolbox, true, true, null);//null selects it in the first container - optionally await
//Note: Project.Current.GetProjectItemContainer("GP") would get toolbox container...

//assume toolbox is also under Folders container. Select it under Folders instead of Toolboxes
var foldersContainer = Project.Current.ProjectItemContainers.First(c => c.Path == "FolderConnection");
//We must specify the container because Folders comes second (after Toolboxes)
projectWindow.SelectItemAsync(toolbox, true, true, foldersContainer);//optionally await

//Find a map and select it
var mapItem = Project.Current.GetItems<MapProjectItem>().FirstOrDefault(m => m.Name == "Map");
//Map only occurs under "Maps" so the container need not be specified
projectWindow.SelectItemAsync(mapItem, true, false, null);

地理数据库内容

浏览对话框中的地理数据库内容

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
var openDlg = new OpenItemDialog
{
Title = "Select a Feature Class",
InitialLocation = @"C:\Data",
MultiSelect = false,
BrowseFilter = BrowseProjectFilter.GetFilter(ArcGIS.Desktop.Catalog.ItemFilters.GeodatabaseItems_All)
};

//show the browse dialog
bool? ok = openDlg.ShowDialog();
if (!ok.HasValue || openDlg.Items.Count() == 0)
return; //nothing selected

await QueuedTask.Run(() =>
{
// get the item
var item = openDlg.Items.First();

// see if the item has a dataset
if (ItemFactory.Instance.CanGetDataset(item))
{
// get it
using (var ds = ItemFactory.Instance.GetDataset(item))
{
// access some properties
var name = ds.GetName();
var path = ds.GetPath();

// if it's a featureclass
if (ds is ArcGIS.Core.Data.FeatureClass fc)
{
// create a layer
var featureLayerParams = new FeatureLayerCreationParams(fc)
{
MapMemberIndex = 0
};
var layer = LayerFactory.Instance.CreateLayer<FeatureLayer>(featureLayerParams, MapView.Active.Map);

// continue
}
}
}
});

目录中的地理数据库内容

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// subscribe to event
ProjectWindowSelectedItemsChangedEvent.Subscribe(async (ProjectWindowSelectedItemsChangedEventArgs args) =>
{
if (args.IProjectWindow.SelectionCount > 0)
{
// get the first selected item
var selectedItem = args.IProjectWindow.SelectedItems.First();

await QueuedTask.Run(() =>
{
// datasetType
var dataType = ItemFactory.Instance.GetDatasetType(selectedItem);

// get the dataset Defintion
if (ItemFactory.Instance.CanGetDefinition(selectedItem))
{
using (var def = ItemFactory.Instance.GetDefinition(selectedItem))
{
if (def is ArcGIS.Core.Data.FeatureClassDefinition fcDef)
{
var oidField = fcDef.GetObjectIDField();
var shapeField = fcDef.GetShapeField();
var shapeType = fcDef.GetShapeType();
}
else if (def is ArcGIS.Core.Data.Parcels.ParcelFabricDefinition pfDef)
{
string ver = pfDef.GetSchemaVersion();
bool enabled = pfDef.GetTopologyEnabled();
}

// etc
}
}

// get the dataset
if (ItemFactory.Instance.CanGetDataset(selectedItem))
{
using (var ds = ItemFactory.Instance.GetDataset(selectedItem))
{
if (ds is ArcGIS.Core.Data.FeatureDataset fds)
{
// open featureclasses within the feature dataset
// var fcPoint = fds.OpenDataset<FeatureClass>("Point");
// var fcPolyline = fds.OpenDataset<FeatureClass>("Polyline");
}
else if (ds is FeatureClass fc)
{
var name = fc.GetName() + "_copy";

// create
var featureLayerParams = new FeatureLayerCreationParams(fc)
{
Name = name,
MapMemberIndex = 0
};
LayerFactory.Instance.CreateLayer<FeatureLayer>(featureLayerParams, MapView.Active.Map);
}
else if (ds is Table table)
{
var name = table.GetName() + "_copy";
var tableParams = new StandaloneTableCreationParams(table)
{
Name = name
};
// create
StandaloneTableFactory.Instance.CreateStandaloneTable(tableParams, MapView.Active.Map);
}
}
}
});
}
});

收藏 夹

添加收藏夹 - 文件夹

1
2
3
4
5
6
7
8
9
10
11
var itemFolder = ItemFactory.Instance.Create(@"d:\data");

// is the folder item already a favorite?
var fav = FavoritesManager.Current.GetFavorite(itemFolder);
if (fav == null)
{
if (FavoritesManager.Current.CanAddAsFavorite(itemFolder))
{
fav = FavoritesManager.Current.AddFavorite(itemFolder);
}
}

插入收藏夹 - 地理数据库路径

1
2
3
4
5
6
7
8
9
10
11
12
string gdbPath = "@C:\\myDataFolder\\myData.gdb";

var itemGDB = ItemFactory.Instance.Create(gdbPath);

// is the item already a favorite?
var fav = FavoritesManager.Current.GetFavorite(itemGDB);
// no; add it with IsAddedToAllNewProjects set to true
if (fav != null)
{
if (FavoritesManager.Current.CanAddAsFavorite(itemGDB))
FavoritesManager.Current.InsertFavorite(itemGDB, 1, true);
}

添加收藏夹 - 设置项目项的样式

1
2
3
4
5
6
7
8
StyleProjectItem styleItem = Project.Current.GetItems<StyleProjectItem>().
FirstOrDefault(style => (style.Name == "ArcGIS 3D"));

if (FavoritesManager.Current.CanAddAsFavorite(styleItem))
{
// add to favorites with IsAddedToAllNewProjects set to false
FavoritesManager.Current.AddFavorite(styleItem);
}

切换标志是添加到所有新项目为收藏夹

1
2
3
4
5
6
7
8
9
10
11
var itemFolder = ItemFactory.Instance.Create(@"d:\data");

// is the folder item already a favorite?
var fav = FavoritesManager.Current.GetFavorite(itemFolder);
if (fav != null)
{
if (fav.IsAddedToAllNewProjects)
FavoritesManager.Current.ClearIsAddedToAllNewProjects(fav.Item);
else
FavoritesManager.Current.SetIsAddedToAllNewProjects(fav.Item);
}

获取收藏夹集并迭代

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
var favorites = FavoritesManager.Current.GetFavorites();
foreach (var favorite in favorites)
{
bool isAddedToAllProjects = favorite.IsAddedToAllNewProjects;
// retrieve the underlying item of the favorite
Item item = favorite.Item;

// Item properties
var itemType = item.TypeID;
var path = item.Path;

// if it's a folder item
if (item is FolderConnectionProjectItem)
{
}
// if it's a goedatabase item
else if (item is GDBProjectItem)
{
}
// else
}

删除所有收藏夹

1
2
3
var favorites = FavoritesManager.Current.GetFavorites();
foreach (var favorite in favorites)
FavoritesManager.Current.RemoveFavorite(favorite.Item);

收藏夹更改事件

1
2
3
4
5
ArcGIS.Desktop.Core.Events.FavoritesChangedEvent.Subscribe((args) =>
{
// favorites have changed
int count = FavoritesManager.Current.GetFavorites().Count;
});

元数据

项目:获取其 IMetadata 接口

1
2
Item gdbItem = ItemFactory.Instance.Create(@"C:\projectAlpha\GDBs\regionFive.gdb");
IMetadata gdbMetadataItem = gdbItem as IMetadata;

项目:获取项目的元数据:获取XML

1
2
3
4
5
6
7
string gdbXMLMetadataXmlAsString = string.Empty;
gdbXMLMetadataXmlAsString = await QueuedTask.Run(() => gdbMetadataItem.GetXml());
//check metadata was returned
if (!string.IsNullOrEmpty(gdbXMLMetadataXmlAsString))
{
//use the metadata
}

项目:设置项目的元数据:设置XML项

1
2
3
4
5
6
7
8
await QueuedTask.Run(() =>
{
var xml = System.IO.File.ReadAllText(@"E:\Data\Metadata\MetadataForFeatClass.xml");
//Will throw InvalidOperationException if the metadata cannot be changed
//so check "CanEdit" first
if (featureClassMetadataItem.CanEdit())
featureClassMetadataItem.SetXml(xml);
});

项目:检查元数据是否可以编辑:可以编辑

1
2
3
bool canEdit1;
//Call CanEdit before calling SetXml
await QueuedTask.Run(() => canEdit1 = metadataItemToCheck.CanEdit());

项目:使用项目的当前属性更新元数据:同步

1
2
string syncedMetadataXml = string.Empty;
await QueuedTask.Run(() => syncedMetadataXml = metadataItemToSync.Synchronize());

项目:从源项目的元数据复制元数据:复制元数据从项目

1
2
Item featureClassItem = ItemFactory.Instance.Create(@"C:\projectAlpha\GDBs\regionFive.gdb\SourceFeatureClass");
await QueuedTask.Run(() => metadataItemImport.CopyMetadataFromItem(featureClassItem));

项目:从当前项目的元数据中删除某些内容:删除元数据内容

1
2
3
Item featureClassWithMetadataItem = ItemFactory.Instance.Create(@"C:\projectBeta\GDBs\regionFive.gdb\SourceFeatureClass");
//Delete thumbnail content from item's metadata
await QueuedTask.Run(() => featureClassWithMetadataItem.DeleteMetadataContent(MDDeleteContentOption.esriMDDeleteThumbnail));

项目:使用导入的元数据更新元数据 - 输入路径可以是包含元数据的项目的路径,也可以是 XML 文件的 URI:导入元数据

1
2
3
// the input path can be the path to an item with metadata, or a URI to an XML file
IMetadata metadataItemImport1 = null;
await QueuedTask.Run(() => metadataItemImport1.ImportMetadata(@"E:\YellowStone.gdb\MyDataset\MyFeatureClass", MDImportExportOption.esriCurrentMetadataStyle));

项目:使用导入的元数据更新元数据:导入元数据

1
2
3
// the input path can be the path to an item with metadata, or a URI to an XML file

await QueuedTask.Run(() => metadataItemImport2.ImportMetadata(@"E:\YellowStone.gdb\MyDataset\MyFeatureClass", MDImportExportOption.esriCustomizedStyleSheet, @"E:\StyleSheets\Import\MyImportStyleSheet.xslt"));

项目:导出当前选定项目的元数据:导出元数据

1
await QueuedTask.Run(() => metadataItemExport1.ExportMetadata(@"E:\Temp\OutputXML.xml", MDImportExportOption.esriCurrentMetadataStyle, MDExportRemovalOption.esriExportExactCopy));

项目:导出当前选定项目的元数据:导出元数据

1
await QueuedTask.Run(() => metadataItemExport2.ExportMetadata(@"E:\Temp\OutputXML.xml", MDImportExportOption.esriCustomizedStyleSheet, MDExportRemovalOption.esriExportExactCopy, @"E:\StyleSheets\Export\MyExportStyleSheet.xslt"));

项目:将当前项目的元数据另存为 XML:将元数据另存为 XML

1
await QueuedTask.Run(() => metadataItemToSaveAsXML.SaveMetadataAsXML(@"E:\Temp\OutputXML.xml", MDSaveAsXMLOption.esriExactCopy));

项目:将当前项目的元数据另存为 HTML:将元数据另存为HTML

1
await QueuedTask.Run(() => metadataItemToSaveAsHTML.SaveMetadataAsHTML(@"E:\Temp\OutputHTML.htm", MDSaveAsHTMLOption.esriCurrentMetadataStyle));

项目:使用自定义 XSLT 保存当前项目的元数据:保存元数据作为使用自定义 XSLT

1
await QueuedTask.Run(() => metadataItemToSaveAsUsingCustomXSLT.SaveMetadataAsUsingCustomXSLT(@"E:\Data\Metadata\CustomXSLT.xsl", @"E:\Temp\OutputXMLCustom.xml"));

项目:升级当前项目的元数据:升级元数据

1
2
var fgdcItem = ItemFactory.Instance.Create(@"C:\projectAlpha\GDBs\testData.gdb");
await QueuedTask.Run(() => fgdcItem.UpgradeMetadata(MDUpgradeOption.esriUpgradeFgdcCsdgm));

项目单位

获取所有可用单位格式的完整列表

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
//Must be on the QueuedTask.Run()

var unit_formats = Enum.GetValues(typeof(UnitFormatType))
.OfType<UnitFormatType>().ToList();
System.Diagnostics.Debug.WriteLine("All available units\r\n");

foreach (var unit_format in unit_formats)
{
var units = DisplayUnitFormats.Instance.GetPredefinedProjectUnitFormats(unit_format);
System.Diagnostics.Debug.WriteLine(unit_format.ToString());

foreach (var display_unit_format in units)
{
var line = $"{display_unit_format.DisplayName}, {display_unit_format.UnitCode}";
System.Diagnostics.Debug.WriteLine(line);
}
System.Diagnostics.Debug.WriteLine("");
}

获取当前项目的单位格式列表

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
//Must be on the QueuedTask.Run()

var unit_formats = Enum.GetValues(typeof(UnitFormatType))
.OfType<UnitFormatType>().ToList();
System.Diagnostics.Debug.WriteLine("Project units\r\n");

foreach (var unit_format in unit_formats)
{
var units = DisplayUnitFormats.Instance.GetProjectUnitFormats(unit_format);
System.Diagnostics.Debug.WriteLine(unit_format.ToString());

foreach (var display_unit_format in units)
{
var line = $"{display_unit_format.DisplayName}, {display_unit_format.UnitCode}";
System.Diagnostics.Debug.WriteLine(line);
}
System.Diagnostics.Debug.WriteLine("");
}

获取当前项目的特定单位格式列表

1
2
3
4
5
6
//Must be on the QueuedTask.Run()

//UnitFormatType.Angular, UnitFormatType.Area, UnitFormatType.Distance,
//UnitFormatType.Direction, UnitFormatType.Location, UnitFormatType.Page
//UnitFormatType.Symbol2D, UnitFormatType.Symbol3D
var units = DisplayUnitFormats.Instance.GetProjectUnitFormats(UnitFormatType.Distance);

获取当前项目的默认格式列表

1
2
3
4
5
6
7
8
9
10
11
12
13
//Must be on the QueuedTask.Run()

var unit_formats = Enum.GetValues(typeof(UnitFormatType))
.OfType<UnitFormatType>().ToList();
System.Diagnostics.Debug.WriteLine("Default project units\r\n");

foreach (var unit_format in unit_formats)
{
var default_unit = DisplayUnitFormats.Instance.GetDefaultProjectUnitFormat(unit_format);
var line = $"{unit_format.ToString()}: {default_unit.DisplayName}, {default_unit.UnitCode}";
System.Diagnostics.Debug.WriteLine(line);
}
System.Diagnostics.Debug.WriteLine("");

获取当前项目的特定默认单位格式

1
2
3
4
5
6
7
//Must be on the QueuedTask.Run()

//UnitFormatType.Angular, UnitFormatType.Area, UnitFormatType.Distance,
//UnitFormatType.Direction, UnitFormatType.Location, UnitFormatType.Page
//UnitFormatType.Symbol2D, UnitFormatType.Symbol3D
var default_unit = DisplayUnitFormats.Instance.GetDefaultProjectUnitFormat(
UnitFormatType.Distance);

为当前项目设置特定的单位格式列表

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
//Must be on the QueuedTask.Run()

//UnitFormatType.Angular, UnitFormatType.Area, UnitFormatType.Distance,
//UnitFormatType.Direction, UnitFormatType.Location

//Get the full list of all available location units
var all_units = DisplayUnitFormats.Instance.GetPredefinedProjectUnitFormats(
UnitFormatType.Location);
//keep units with an even factory code
var list_units = all_units.Where(du => du.UnitCode % 2 == 0).ToList();

//set them as the new location unit collection. A new default is not being specified...
DisplayUnitFormats.Instance.SetProjectUnitFormats(list_units);

//set them as the new location unit collection along with a new default
DisplayUnitFormats.Instance.SetProjectUnitFormats(
list_units, list_units.First());

//Note: UnitFormatType.Page, UnitFormatType.Symbol2D, UnitFormatType.Symbol3D
//cannot be set.

设置项目单位格式的默认值

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
//Must be on the QueuedTask.Run()

var unit_formats = Enum.GetValues(typeof(UnitFormatType)).OfType<UnitFormatType>().ToList();
foreach (var unit_type in unit_formats)
{
var current_default = DisplayUnitFormats.Instance.GetDefaultProjectUnitFormat(unit_type);
//Arbitrarily pick the last unit in each unit format list
var replacement = DisplayUnitFormats.Instance.GetProjectUnitFormats(unit_type).Last();
DisplayUnitFormats.Instance.SetDefaultProjectUnitFormat(replacement);

var line = $"{current_default.DisplayName}, {current_default.UnitName}, {current_default.UnitCode}";
var line2 = $"{replacement.DisplayName}, {replacement.UnitName}, {replacement.UnitCode}";

System.Diagnostics.Debug.WriteLine($"Format: {unit_type.ToString()}");
System.Diagnostics.Debug.WriteLine($" Current default: {line}");
System.Diagnostics.Debug.WriteLine($" Replacement default: {line2}");
}

更新项目的单位格式

1
2
3
4
5
6
7
8
9
10
11
12
13
//UnitFormatType.Angular, UnitFormatType.Area, UnitFormatType.Distance, 
//UnitFormatType.Direction, UnitFormatType.Location
var angle_units = DisplayUnitFormats.Instance.GetProjectUnitFormats(UnitFormatType.Angular);

//Edit the display name of each unit - append the abbreviation
foreach (var unit in angle_units)
{
unit.DisplayName = $"{unit.DisplayName} ({unit.Abbreviation})";
}
//apply the changes to the units and set the default to be the first entry
DisplayUnitFormats.Instance.SetProjectUnitFormats(angle_units, angle_units.First());

//The project must be saved to persist the changes...

应用选项

获取常规选项

1
2
3
4
5
6
7
8
9
10
11
12
13
var startMode = ApplicationOptions.GeneralOptions.StartupOption;
var aprx_path = ApplicationOptions.GeneralOptions.StartupProjectPath;

var hf_option = ApplicationOptions.GeneralOptions.HomeFolderOption;
var folder = ApplicationOptions.GeneralOptions.CustomHomeFolder;

var gdb_option = ApplicationOptions.GeneralOptions.DefaultGeodatabaseOption;
var def_gdb = ApplicationOptions.GeneralOptions.CustomDefaultGeodatabase;

var tbx_option = ApplicationOptions.GeneralOptions.DefaultToolboxOption;
var def_tbx = ApplicationOptions.GeneralOptions.CustomDefaultToolbox;

var create_in_folder = ApplicationOptions.GeneralOptions.ProjectCreateInFolder;

将“常规选项”设置为使用自定义设置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
//Set the application to use a custom project, home folder, gdb, and toolbox
//In each case, the custom _path_ must be set _first_ before
//setting the "option". This ensures the application remains
//in a consistent state. This is the same behavior as on the Pro UI.
if (string.IsNullOrEmpty(ApplicationOptions.GeneralOptions.StartupProjectPath))
ApplicationOptions.GeneralOptions.StartupProjectPath = @"D:\data\usa.aprx";//custom project path first
ApplicationOptions.GeneralOptions.StartupOption = StartProjectMode.WithDefaultProject;//option to use it second

if (string.IsNullOrEmpty(ApplicationOptions.GeneralOptions.CustomHomeFolder))
ApplicationOptions.GeneralOptions.CustomHomeFolder = @"D:\home_folder";//custom home folder first
ApplicationOptions.GeneralOptions.HomeFolderOption = OptionSetting.UseCustom;//option to use it second

if (string.IsNullOrEmpty(ApplicationOptions.GeneralOptions.CustomDefaultGeodatabase))
ApplicationOptions.GeneralOptions.CustomDefaultGeodatabase = @"D:\data\usa.gdb";//custom gdb path first
ApplicationOptions.GeneralOptions.DefaultGeodatabaseOption = OptionSetting.UseCustom;//option to use it second

if (string.IsNullOrEmpty(ApplicationOptions.GeneralOptions.CustomDefaultToolbox))
ApplicationOptions.GeneralOptions.CustomDefaultToolbox = @"D:\data\usa.tbx";//custom toolbox path first
ApplicationOptions.GeneralOptions.DefaultToolboxOption = OptionSetting.UseCustom;//option to use it second

设置常规选项以使用默认值

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
//Default options can be set regardless of the value of the "companion"
//path (to a project, folder, gdb, toolbox, etc.). The path value is ignored if
//the option setting does not use it. This is the same behavior as on the Pro UI.
ApplicationOptions.GeneralOptions.StartupOption = StartProjectMode.ShowStartPage;
ApplicationOptions.GeneralOptions.HomeFolderOption = OptionSetting.UseDefault;
ApplicationOptions.GeneralOptions.DefaultGeodatabaseOption = OptionSetting.UseDefault;
ApplicationOptions.GeneralOptions.DefaultToolboxOption = OptionSetting.UseDefault;//set default option first

//path values can (optionally) be set (back) to null if their
//"companion" option setting is the default option.
if (ApplicationOptions.GeneralOptions.StartupOption != StartProjectMode.WithDefaultProject)
ApplicationOptions.GeneralOptions.StartupProjectPath = null;
if (ApplicationOptions.GeneralOptions.HomeFolderOption == OptionSetting.UseDefault)
ApplicationOptions.GeneralOptions.CustomHomeFolder = null;
if (ApplicationOptions.GeneralOptions.DefaultGeodatabaseOption == OptionSetting.UseDefault)
ApplicationOptions.GeneralOptions.CustomDefaultGeodatabase = null;
if (ApplicationOptions.GeneralOptions.DefaultToolboxOption == OptionSetting.UseDefault)
ApplicationOptions.GeneralOptions.CustomDefaultToolbox = null;

获取下载选项

1
2
3
4
5
6
7
8
9
10
11
12
var staging = ApplicationOptions.DownloadOptions.StagingLocation;

var ppkx_loc = ApplicationOptions.DownloadOptions.UnpackPPKXLocation;
var ask_ppkx_loc = ApplicationOptions.DownloadOptions.AskForUnpackPPKXLocation;

var other_loc = ApplicationOptions.DownloadOptions.UnpackOtherLocation;
var ask_other_loc = ApplicationOptions.DownloadOptions.AskForUnpackOtherLocation;
var use_proj_folder = ApplicationOptions.DownloadOptions.UnpackOtherToProjectLocation;

var offline_loc = ApplicationOptions.DownloadOptions.OfflineMapsLocation;
var ask_offline_loc = ApplicationOptions.DownloadOptions.AskForOfflineMapsLocation;
var use_proj_folder_offline = ApplicationOptions.DownloadOptions.OfflineMapsToProjectLocation;

设置共享和发布的暂存位置

1
ApplicationOptions.DownloadOptions.StagingLocation = @"D:\data\staging";

设置 PPKX 的下载选项

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
//Options are mutually exclusive.

//Setting ApplicationOptions.DownloadOptions.AskForUnpackPPKXLocation = true
//superseeds any value in ApplicationOptions.DownloadOptions.UnpackPPKXLocation
//and will prompt the user on an unpack. The value of
//ApplicationOptions.DownloadOptions.UnpackPPKXLocation will be unaffected
//and is ignored. This is the same behavior as on the Pro UI.
ApplicationOptions.DownloadOptions.AskForUnpackPPKXLocation = true;//override location

//The default location is typically <My Documents>\ArcGIS\Packages
//Setting ApplicationOptions.DownloadOptions.UnpackPPKXLocation to any
//location overrides ApplicationOptions.DownloadOptions.AskForUnpackPPKXLocation
//and sets it to false. This is the same behavior as on the Pro UI.
ApplicationOptions.DownloadOptions.UnpackPPKXLocation = @"D:\data\for_ppkx";

//Or, if ApplicationOptions.DownloadOptions.UnpackPPKXLocation already
//contains a valid path, set ApplicationOptions.DownloadOptions.AskForUnpackPPKXLocation
//explicitly to false to use the UnpackPPKXLocation
if (!string.IsNullOrEmpty(ApplicationOptions.DownloadOptions.UnpackPPKXLocation))
ApplicationOptions.DownloadOptions.AskForUnpackPPKXLocation = false;

设置解压缩的下载选项其他

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
//UnpackOther settings control unpacking of anything _other than_
//a ppkx or aptx. Options are mutually exclusive.

//Set ApplicationOptions.DownloadOptions.UnpackOtherLocation explicitly to
//toggle ApplicationOptions.DownloadOptions.AskForUnpackOtherLocation and
//ApplicationOptions.DownloadOptions.UnpackOtherToProjectLocation to false
//Note: default is typically <My Documents>\ArcGIS\Packages, _not_ null.
//This is the same behavior as on the Pro UI.
ApplicationOptions.DownloadOptions.UnpackOtherLocation = @"D:\data\for_other";

//or...to use a location already stored in UnpackOtherLocation as the
//default without changing it,
//set ApplicationOptions.DownloadOptions.AskForUnpackOtherLocation and
//ApplicationOptions.DownloadOptions.UnpackOtherToProjectLocation to false
//explicitly. This is the same behavior as on the Pro UI.
if (!string.IsNullOrEmpty(ApplicationOptions.DownloadOptions.UnpackOtherLocation))
{
ApplicationOptions.DownloadOptions.AskForUnpackOtherLocation = false;
ApplicationOptions.DownloadOptions.UnpackOtherToProjectLocation = false;
}

//Setting ApplicationOptions.DownloadOptions.AskForUnpackOtherLocation to
//true overrides any UnpackOtherLocation value and sets
//ApplicationOptions.DownloadOptions.UnpackOtherToProjectLocation to false.
//This is the same behavior as on the Pro UI.
ApplicationOptions.DownloadOptions.AskForUnpackOtherLocation = true;

//Setting ApplicationOptions.DownloadOptions.UnpackOtherToProjectLocation to
//true overrides any UnpackOtherLocation value and sets
//ApplicationOptions.DownloadOptions.AskForUnpackOtherLocation to false.
//This is the same behavior as on the Pro UI.
ApplicationOptions.DownloadOptions.UnpackOtherToProjectLocation = false;

设置离线地图的下载选项

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
//OfflineMaps settings control where map content that is taken
//offline is copied to on the local machine. Options are mutually exclusive.

//Set ApplicationOptions.DownloadOptions.OfflineMapsLocation explicitly to
//toggle ApplicationOptions.DownloadOptions.AskForOfflineMapsLocation and
//ApplicationOptions.DownloadOptions.OfflineMapsToProjectLocation to false
//Note: default is typically <My Documents>\ArcGIS\OfflineMaps, _not_ null.
//This is the same behavior as on the Pro UI.
ApplicationOptions.DownloadOptions.OfflineMapsLocation = @"D:\data\for_offline";

//or...to use a location already stored in OfflineMapsLocation as the
//default without changing it,
//set ApplicationOptions.DownloadOptions.AskForOfflineMapsLocation and
//ApplicationOptions.DownloadOptions.OfflineMapsToProjectLocation to false
//explicitly.
if (!string.IsNullOrEmpty(ApplicationOptions.DownloadOptions.OfflineMapsLocation))
{
ApplicationOptions.DownloadOptions.AskForOfflineMapsLocation = false;
ApplicationOptions.DownloadOptions.OfflineMapsToProjectLocation = false;
}

//Setting ApplicationOptions.DownloadOptions.AskForOfflineMapsLocation to
//true overrides any OfflineMapsLocation value and sets
//ApplicationOptions.DownloadOptions.OfflineMapsToProjectLocation to false.
//This is the same behavior as on the Pro UI.
ApplicationOptions.DownloadOptions.AskForOfflineMapsLocation = true;

//Setting ApplicationOptions.DownloadOptions.OfflineMapsToProjectLocation to
//true overrides any OfflineMapsLocation value and sets
//ApplicationOptions.DownloadOptions.AskForOfflineMapsLocation to false.
//This is the same behavior as on the Pro UI.
ApplicationOptions.DownloadOptions.OfflineMapsToProjectLocation = true;

``