Select to view content in your preferred language

How to find elevation profile of a polyline graphic (v100.0,WPF)?

2117
4
03-31-2017 08:15 AM
KeithGemeinhart1
Regular Contributor

Working with .NET Runtime v100.0 and a WPF desktop application ... I'd like to be able to draw an elevation profile that corresponds to a graphic that I've drawn on a map. Additionally, I'd like to inspect the line to find the elevation at any point along the line. Any help for these two items would be appreciated.

Here is what I have so far:

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

Then I can get elevation at any particular point via:   

 result = await Dted1Surface.GetElevationAsync(point);

I tried this, but the Z values are all zero:

var drapedOverlay = new GraphicsOverlay();
drapedOverlay.SceneProperties.SurfacePlacement = SurfacePlacement.Draped;
SceneView1.GraphicsOverlays.Add(drapedOverlay);

// existing polyline on a map layervar
var hose = hoselineLayer.Graphics.FirstOrDefault();
 
hose3d = new Graphic(hose.Geometry);
drapedOverlay.Graphics.Add(hose3d);‍‍‍‍‍‍‍‍
0 Kudos
4 Replies
TonyWakim
Esri Contributor

Try changing the SurfacePlacement to "Absolute"; and you will need to convert your polyline from 2D to 3D using something like:

```

            public static async Task<Polyline> CreatePolylineWithElevation(Surface s, Polyline geom, double zIncrement=0)
            {
                if ((s == null) || (geom == null) || !(geom is Polyline))
                    return null;
                List<MapPoint> mapPoints = new List<MapPoint>();
                for (int i = 0; i < geom.Parts[0].Points.Count - 1; i++)
                {
                    var pt1 = geom.Parts[0].Points;
                    var elevation = await s.GetElevationAsync(pt1);
                    mapPoints.Add(new MapPoint(pt1.X, pt1.Y, elevation + zIncrement, pt1.SpatialReference));
                }
                if (mapPoints.Count > 0)
                    return new Polyline(mapPoints);
                else
                    return null;
            }

```

You might also need to use "GeometryEngine.Densify()" to get more accurate 3D representation of the elevation.

I gave this code a simple test and seems to work; might need more testing.

0 Kudos
KeithGemeinhart1
Regular Contributor

Do you know what the units are on the maxSegmentLength parameter for Densify?

0 Kudos
TonyWakim
Esri Contributor

For this method, the maxSegmentLength parameter would have the same units as the geometry's spatial reference system

0 Kudos
KeithGemeinhart1
Regular Contributor

Heads up that this line has an error:

for (int i = 0; i < geom.Parts[0].Points.Count - 1; i++)

it should not have the -1:

for (int i = 0; i < geom.Parts[0].Points.Count; i++)
0 Kudos