Get Elevation point on raster map from Dted local file using wpf

1778
5
01-31-2019 05:15 PM
MohamadFathin
New Contributor II

Hi,

How can i get elevation point from the local Dted file that store in pc directory. This cause my project need to work offline without a internet. I need the elevation value display on my raster map on mouse move when i point the mouse tip on the raster map.tif.

Regards and thank you,

0 Kudos
5 Replies
MohamadFathin
New Contributor II

Can Someone can guide me through this process?

0 Kudos
KeithGemeinhart1
New Contributor III

We are doing that in our applications. See my responses in this thread: https://community.esri.com/thread/209862-how-to-use-elevation-data-in-a-mapview 

0 Kudos
MohamadFathin
New Contributor II

Hi Keith Gemeinhart‌,

Thank you sir, i managed to get the elevation value from the thread you share. Just an issues that i need help that i can't rendered the map, i can't move the mouse the other part of map and the zoom function does not trigger. I just able to move the mouse cursor on the current view when the application start up. I put my sceneview in the same user control of my mapview, Is that the correct way to do that?

namespace ArcGISDTeD
{
 /// <summary>
 /// Interaction logic for Elevation.xaml
 /// </summary>
 public partial class Elevation : UserControl
 {
 string dtedDirectory = @"C:\Users\User\Desktop\User Stuff\DSI REFERENCE\Map Data\Elevation\DTED PEKAN\dted\E103\N03.dt2";
 string shapeFilePath = @"C:\Users\User\Desktop\Map Data\Shape File\countries_shp";
 string rasterMapMosaicPath = @"C:\Users\User\Desktop\Map Data\MosaicSqliteFile\RasterMapMosaic.sqlite";

 public Surface Dted1Surface { get; private set; }
 public SceneView SceneView1 { get; private set; }

 Raster mapRaster;
 RasterLayer rasterMapLayer;
 ShapefileFeatureTable myShapefile;

 public Elevation()
 {
 InitializeComponent();
 Dted1Surface = new Surface();
 SceneView1 = new SceneView();
 Initialize();
 }

 private async void Initialize()
 {

 MyMapView.Map = new Map(new SpatialReference(4326));

 foreach (string filepath in Directory.EnumerateFiles(shapeFilePath, "*.shp"))
 {
 // Open the shapefile
 myShapefile = await ShapefileFeatureTable.OpenAsync(filepath);
 }

 // Create a feature layer to display the shapefile
 FeatureLayer newFeatureLayer = new FeatureLayer(myShapefile);

 // Add the feature layer to the map
 MyMapView.Map.OperationalLayers.Add(newFeatureLayer);

 await myShapefile.LoadAsync();

 //MyMapView.Map.InitialViewpoint = new Viewpoint(rasterLayer.FullExtent);

 await MyMapView.SetViewpointAsync(new Viewpoint(3.7966815987, 103.0526707750, 100000));

 await MyMapView.Map.LoadAsync();



 //Get mosaic dataset names in the SQLite database.
 var names = MosaicDatasetRaster.GetNames(rasterMapMosaicPath);
 var rasterName = names[0];

 //Create a raster from a mosaic dataset
 mapRaster = new MosaicDatasetRaster(rasterMapMosaicPath, "RasterMapTable");


 // Create a RasterLayer to display the Raster
 rasterMapLayer = new RasterLayer(mapRaster);

 MyMapView.Map.OperationalLayers.Add(rasterMapLayer);

 await rasterMapLayer.LoadAsync();


 //await MyMapView.SetViewpointAsync(new Viewpoint(2.856364, 101.787213, 400000));

 await MyMapView.Map.LoadAsync();



 var Dted1Files = new List<string>();

 Dted1Files.Add(dtedDirectory);

 // Create a raster elevation source based on all files in dted1Files
 RasterElevationSource dted1ElevSource = new RasterElevationSource(Dted1Files);
 await dted1ElevSource.LoadAsync();
 dted1ElevSource.Name = "DTED1";

 // Create a Surface based on the elevation source
 Dted1Surface.ElevationSources.Add(dted1ElevSource);
 Dted1Surface.Name = "DTED1 Surface";
 await Dted1Surface.LoadAsync();

 // Create a Scene and assign the created surface to its BaseSurface
 Scene dted1Scene = new Scene();
 dted1Scene.BaseSurface = Dted1Surface;
 await dted1Scene.LoadAsync();

 // Create a SceneView and assign created scene to its Scene
 SceneView1.Scene = dted1Scene;

 
 
 }

 private async void MyMapView_MouseMove(object sender, MouseEventArgs e)
 {
 if (MyMapView != null)
 {
 Point screenPoint = e.GetPosition(MyMapView);

 MapPoint mapPoint = MyMapView.ScreenToLocation(screenPoint);

 if (mapPoint != null)
 {
 // point = GetDesiredElevationLocation();
 double result = await Dted1Surface.GetElevationAsync(mapPoint);

 if (MyMapView.IsWrapAroundEnabled)
 {
 

 mapPoint = GeometryEngine.Project(mapPoint, SpatialReferences.Wgs84) as MapPoint;

 textBox.Text = String.Format("x: {0}, y: {1} | Lat:{2},Lon:{3} | Scale:{4} | Elevation : {5}", screenPoint.X, screenPoint.Y, Math.Round(mapPoint.Y, 6), Math.Round(mapPoint.X, 6), MyMapView.MapScale, result );
 }

 }
 else
 return;
 }

 }

 }
 

 
}
0 Kudos
KeithGemeinhart1
New Contributor III

Nothing jumps out at me right away. I'll just offer some general debugging advice. You have a lot going on in the Initialize method. Consider breaking that up into separate methods. For debugging, try commenting out some stuff until you get your map responding the way you want. Then when you know which lines are causing the problem, you can make adjustments or corrections.

0 Kudos
MohamadFathin
New Contributor II

HI Keith Gemeinhart

Thank you for your advice sir, i am able to solve my issues by make the SceneView Visibility=Hidden.