2

我正在开发一个 .net 项目,我必须将功能转换为图形以使用存储的符号显示它们。

我有一个单独的样式文件作为 .stylx 和地理数据库文件作为 .goedatabase.zip,我想利用它来显示我的样式文件的符号。

我成功执行了下面的代码并显示了可能的映射。但我无法访问存储在驱动器上的样式库和地理数据库。

以下是我的文件的规格

  • mil2525d.stylx - 用于 ArcGIS Runtime 100.0 - 100.4 的 stylx 文件,用于构建包含 MIL-STD-2525D 符号字典的自定义应用程序。
  • Militaryoverlay.geodatabase.zip - 这是从军事叠加模板创建的移动地理数据库,用于 ArcGIS 运行时示例

任何帮助

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");
            }
        }
}
}
4

1 回答 1

0

如果您尝试将公共样本与您自己的数据一起使用,您可以简单地替换代码中的数据,如下所示:

// 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";

或修改GetGeodatabasePathGetStyleDictionaryPath方法以指向您的数据位置。

于 2021-10-25T20:31:37.597 回答