I am working on a .net project where I have to convert features into graphics to show them with stored symbols.
I have a separate style file as .stylx and geodatabase file as .goedatabase.zip which I want to utilize to show my symbole of the style file.
I successfully execute the below code and show may map. But I am unable to access my style library and geodatabase which is stored on my drive.
Below are the specs of my files
- mil2525d.stylx - A stylx file for use with ArcGIS Runtime 100.0 - 100.4 to build custom applications that incorporate the MIL-STD-2525D symbol dictionary.
- militaryoverlay.geodatabase.zip - This is a mobile geodatabase created from the Military Overlay template for use in ArcGIS Runtime samples
Any help
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");
}
}
}
}
CodePudding user response:
You can get the file path for the style dictionary as follows:
private static string GetStyleDictionaryPath()
{
return DataManager.GetDataFolder("c78b149a1d52414682c86a5feeb13d30", "mil2525d.stylx");
}
And for the geodatabase folder, you can enter the file path for the geodatabase as follows:
private static string GetGeodatabasePath()
{
return DataManager.GetDataFolder("e0d41b4b409a49a5a7ba11939d8535dc", "militaryoverlay.geodatabase");
}
CodePudding user response:
If you are trying to use public sample with your own data, you could either simple replace data in code as follows:
// 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";
or modify GetGeodatabasePath
and GetStyleDictionaryPath
methods to point to your data locations.