【问题标题】:Unable to give the file path to the style dictionary无法提供样式字典的文件路径
【发布时间】:2021-12-10 09:10:36
【问题描述】:

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

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

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

以下是我的文件的规格

  • mil2525d.stylx - 用于 ArcGIS Runtime 100.0 的 stylx 文件 - 100.4 以构建包含 MIL-STD-2525D 符号字典的自定义应用程序。
  • militaryoverlay.geodatabase.zip - 这是一个移动地理数据库 从 Military Overlay 模板创建以在 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");
            }
        }
}
}

【问题讨论】:

    标签: .net arcgis arcgis-server arcgis-runtime arcgis-runtime-net


    【解决方案1】:

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

    // 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 方法以指向您的数据位置。

    【讨论】:

    • 正如目前所写,您的答案尚不清楚。请edit 添加其他详细信息,以帮助其他人了解这如何解决所提出的问题。你可以找到更多关于如何写好答案的信息in the help center
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多