Hi,
is there a way to programmatically add a elevation surface to a map in ArcGis Pro? And while we're at it.. also add a elevation source to the new elevation surface? I know how to query a elevation surface and list the available surfaces but I didn't find a way to add new elevation surfaces.
Thanks in advance! 🙂
Christian
Solved! Go to Solution.
Updating the ElevationSources of a map requires updating the MapDefinition. The basic approach is:
Craig
Updating the ElevationSources of a map requires updating the MapDefinition. The basic approach is:
Craig
Hi Craig,
thanks a lot for you reply. Your solution seems to work 🙂 If you don't mind, would you look over my code to check whether it's okay? I use it to add a new elevation surface whose source is a TIN.
private Task CreateNewElevationSurface(ArcGIS.Desktop.Mapping.Map map, string surfaceName) {
return ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() => {
var dataConnection = new ArcGIS.Core.CIM.CIMStandardDataConnection();
dataConnection.WorkspaceConnectionString = String.Format("DATABASE={0}", System.IO.Path.GetDirectoryName(ArcGIS.Desktop.Core.Project.Current.DefaultGeodatabasePath));
dataConnection.WorkspaceFactory = ArcGIS.Core.CIM.WorkspaceFactory.Tin;
dataConnection.Dataset = "Tin";
dataConnection.DatasetType = ArcGIS.Core.CIM.esriDatasetType.esriDTTin;
var newElevationSource = new ArcGIS.Core.CIM.CIMElevationSource();
newElevationSource.VerticalUnit = ArcGIS.Core.Geometry.LinearUnit.Meters;
newElevationSource.DataConnection = dataConnection;
var newElevationSurface = new ArcGIS.Core.CIM.CIMMapElevationSurface();
newElevationSurface.Name = surfaceName;
newElevationSurface.BaseSources = new ArcGIS.Core.CIM.CIMElevationSource[1] { newElevationSource };
var definition = map.GetDefinition();
int numElevationSurfaces = definition.ElevationSurfaces.Length;
var newElevationSurfaces = new ArcGIS.Core.CIM.CIMMapElevationSurface[numElevationSurfaces + 1];
Array.Copy(definition.ElevationSurfaces, 0, newElevationSurfaces, 0, numElevationSurfaces);
newElevationSurfaces[numElevationSurfaces] = newElevationSurface;
definition.ElevationSurfaces = newElevationSurfaces;
map.SetDefinition(definition);
});
}
Thanks again and Best regards
Christian
I obviously haven't run it, but that seems right reading it over.