我正在一個 .net 專案中作業,我必須將特征轉換為圖形以使用存盤的符號顯示它們。
我有一個單獨的樣式檔案 .stylx 和地理資料庫檔案 .goedatabase.zip 我想用它來顯示樣式檔案的符號。
我成功執行了以下代碼并顯示可能映射。但是我無法訪問存盤在驅動器上的樣式庫和地理資料庫。
以下是我的檔案的規格
- mil2525d.stylx - 與 ArcGIS Runtime 100.0 - 100.4 一起使用的 stylx 檔案,用于構建包含 MIL-STD-2525D 符號字典的自定義應用程式。
- Militaryoverlay.geodatabase.zip - 這是一個從軍事覆寫模板創建的移動地理資料庫,用于 ArcGIS Runtime 示例
任何幫助
using System;
using System.Windows;
using ArcGISRuntime.Samples.Managers;
using Esri.ArcGISRuntime.Data;
using Esri.ArcGISRuntime.Geometry;
using Esri.ArcGISRuntime.Mapping;
using Esri.ArcGISRuntime.Symbology;
namespace ArcGISRuntime.WPF.Samples.FeatureLayerDictionaryRenderer
{
[ArcGISRuntime.Samples.Shared.Attributes.Sample(
name: "Dictionary renderer with feature layer",
category: "Layers",
description: "Convert features into graphics to show them with mil2525d symbols.",
instructions: "Pan and zoom around the map. Observe the displayed military symbology on the map.",
tags: new[] { "military", "symbol" })]
[ArcGISRuntime.Samples.Shared.Attributes.OfflineData("c78b149a1d52414682c86a5feeb13d30", "e0d41b4b409a49a5a7ba11939d8535dc")]
public partial class FeatureLayerDictionaryRenderer
{
public FeatureLayerDictionaryRenderer()
{
InitializeComponent();
// Setup the control references and execute initialization
Initialize();
}
private async void Initialize()
{
// Create new Map with basemap
Map myMap = new Map(BasemapStyle.ArcGISTopographic);
// Provide Map to the MapView
MyMapView.Map = myMap;
// Get the path to the geodatabase
string geodbFilePath = GetGeodatabasePath();
// Load the geodatabase from local storage
Geodatabase baseGeodatabase = await Geodatabase.OpenAsync(geodbFilePath);
// Get the path to the symbol dictionary
string symbolFilepath = GetStyleDictionaryPath();
try
{
// Load the symbol dictionary from local storage
DictionarySymbolStyle symbolStyle = await DictionarySymbolStyle.CreateFromFileAsync(symbolFilepath);
// Add geodatabase features to the map, using the defined symbology
foreach (FeatureTable table in baseGeodatabase.GeodatabaseFeatureTables)
{
// Load the table
await table.LoadAsync();
// Create the feature layer from the table
FeatureLayer myLayer = new FeatureLayer(table);
// Load the layer
await myLayer.LoadAsync();
// Create a Dictionary Renderer using the DictionarySymbolStyle
DictionaryRenderer dictRenderer = new DictionaryRenderer(symbolStyle);
// Apply the dictionary renderer to the layer
myLayer.Renderer = dictRenderer;
// Add the layer to the map
myMap.OperationalLayers.Add(myLayer);
}
// Create geometry for the center of the map
MapPoint centerGeometry = new MapPoint(-13549402.587055, 4397264.96879385, SpatialReference.Create(3857));
// Set the map's viewpoint to highlight the desired content
MyMapView.SetViewpoint(new Viewpoint(centerGeometry, 201555));
}
catch (Exception e)
{
MessageBox.Show(e.ToString(), "Error");
}
}
}
}
uj5u.com熱心網友回復:
您可以按如下方式獲取樣式字典的檔案路徑:
private static string GetStyleDictionaryPath()
{
return DataManager.GetDataFolder("c78b149a1d52414682c86a5feeb13d30", "mil2525d.stylx");
}
對于地理資料庫檔案夾,您可以輸入地理資料庫的檔案路徑,如下所示:
private static string GetGeodatabasePath()
{
return DataManager.GetDataFolder("e0d41b4b409a49a5a7ba11939d8535dc", "militaryoverlay.geodatabase");
}
uj5u.com熱心網友回復:
如果您嘗試將公共示例與您自己的資料一起使用,您可以簡單地替換代碼中的資料,如下所示:
// Get the path to the geodatabase
string geodbFilePath = "c:/path_to_gdb/mygdb.geodatabase";
// Load the geodatabase from local storage
Geodatabase baseGeodatabase = await Geodatabase.OpenAsync(geodbFilePath);
// Get the path to the symbol dictionary
string symbolFilepath = "c:/path_to_style/mystylx.stylx";
或修改GetGeodatabasePath和GetStyleDictionaryPath方法以指向您的資料位置。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/337108.html
