Access layer's resolution and tolerance C#, pro sdk

268
4
05-27-2020 01:53 PM
MarvisKisakye1
Occasional Contributor

How can I access the resolution and tolerance of a layer as shown in the image below?

Wolfgang KaiserUma Harano

0 Kudos
4 Replies
UmaHarano
Esri Regular Contributor

Hi Marvis,

Resolution and Tolerance are properties of the Layer's SpatialReference.

var lyr = MapView.Active.Map.GetLayersAsFlattenedList().OfType<FeatureLayer>().FirstOrDefault();
QueuedTask.Run( () => {
   var spatialReference = lyr.GetSpatialReference();
   var lyrResolution = spatialReference.XYResolution;
   var lyrTolerance = spatialReference.XYTolerance;
});

Thanks!

Uma

0 Kudos
MarvisKisakye1
Occasional Contributor

Thanks Uma Harano. I was able to retrieve the tolerance and resolution values. I am attempting to use those tolerance and resolution values and apply them to a feature class that is created by the create routes tool like below:

double xyResolution = -1;
double xyTolerance = -1;
double mTolerance = -1;
await QueuedTask.Run(() =>
     {
       var sr_Template = TemplateLayer.GetSpatialReference();
       xyResolution = sr_Template.XYResolution;
       xyTolerance = sr_Template.XYTolerance;
       mTolerance = sr_Template.MTolerance;
     });

var environments = Geoprocessing.MakeEnvironmentArray(XYResolution: xyResolution, XYTolerance: xyTolerance, MTolerance: mTolerance);               
await Geoprocessing.ExecuteToolAsync("CreateRoutes_lr", Geoprocessing.MakeValueArray(infc, "Name", "memory\\routes", "LENGTH", "#", "#", "LOWER_LEFT", 1.89393939393939E-04, 0, false, true),environments,null,null, GPExecuteToolFlags.AddOutputsToMap);                   ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

When I scrutinize the output file 'routes' however, the tolerance and resolution values are not applied. The output file has completely different values than the ones assigned by environments. Do you know what could be causing this issue?

The other issue is that the spatial reference object has the MTolerance but I am unable to locate the MResolution among the properties. The layer properties shown in the image in the original question does show the MResolution. Am I missing something?

0 Kudos
UmaHarano
Esri Regular Contributor

Hi

When you use this GP tool using the UI, do you see a different behavior?

For example, are you able to specify this same tolerance/resolution in the tool and run it? Do you get the expected results?

I am trying to see if there an issue using the Pro API or is the result the same with the GP Tool.

Thanks

Uma

0 Kudos
MarvisKisakye1
Occasional Contributor

It looks like while saving to memory, the environment settings aren't applied. When I saved my outputs to a file gdb, the resolution and tolerance were set as expected. 

I however, would still appreciate any insight into the issue of the spatial reference object having the MTolerance property but not the MResolution property.

0 Kudos