Select to view content in your preferred language

Add elevation surface programmatically

1908
3
Jump to solution
09-26-2017 06:56 AM
RehmSoftware
Regular Contributor

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

0 Kudos
1 Solution

Accepted Solutions
CraigWilliams
Esri Contributor

Updating the ElevationSources of a map requires updating the MapDefinition.  The basic approach is:

  • Call GetDefinition (to get the CIMMap definition)
  • Work through the array of ElevationSources to either update an existing source of add a new source.  You'll need a CIMDataConnection for the data source path.
  • Call SetDefintion to push the changed back into the map.

Craig

View solution in original post

3 Replies
CraigWilliams
Esri Contributor

Updating the ElevationSources of a map requires updating the MapDefinition.  The basic approach is:

  • Call GetDefinition (to get the CIMMap definition)
  • Work through the array of ElevationSources to either update an existing source of add a new source.  You'll need a CIMDataConnection for the data source path.
  • Call SetDefintion to push the changed back into the map.

Craig

RehmSoftware
Regular Contributor

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

0 Kudos
CraigWilliams
Esri Contributor

I obviously haven't run it, but that seems right reading it over.

0 Kudos