Select to view content in your preferred language

Is it possible to use geoprocessing management.MakeFeatureLayer?

97
3
Jump to solution
Tuesday
RadekMandovec
Regular Contributor

In ArcObjects, I commonly used MakeFeatureLayer to create a layer from a Feature Class, which I then worked with further, for example for spatial selections. When I try to do the same thing in ArcGIS Pro, I get the following error message: ERROR 000732: Selecting Features: Dataset Extent_lyr does not exist or is not supported.

    await QueuedTask.Run(async () =>
    {
        string pathToFgdb = @"C:\ISSMD\Temp\Masking.gdb";
        string nameExtent = "Extent";
        string nameMasks= "Masks";
        string pathToFcExtent = Path.Combine(pathToFgdb, nameExtent);
        string pathToFcMasks = Path.Combine(pathToFgdb, nameMasks);
        
        var layerNameExtent = nameExtent + "_lyr";
        var layerNameMasks = nameMasks + "_lyr";

        var args1 = Geoprocessing.MakeValueArray(pathToFcExtent, layerNameExtent);
        IGPResult result1 = await Geoprocessing.ExecuteToolAsync("management.MakeFeatureLayer", args1, null, null, null, GPExecuteToolFlags.AddToHistory);
        var args2 = Geoprocessing.MakeValueArray(pathToFcMasks, layerNameMasks);
        IGPResult result2 = await Geoprocessing.ExecuteToolAsync("management.MakeFeatureLayer", args2, null, null, null, GPExecuteToolFlags.AddToHistory);

        IGPResult result3 = await GeoProcesy.GeoprocessingovaUlohaVysledek("management.SelectLayerByLocation",
                [layerNameMasks, "INTERSECT", layerNameExtent, "", "NEW_SELECTION", "NOT_INVERT"]);

    });
}

So is it even possible to do it this way or do I have to do it only like this?

FeatureLayer featureLayer = LayerFactory.Instance.CreateLayer<FeatureLayer>(featureLayerParams, map);

 

0 Kudos
1 Solution

Accepted Solutions
GKmieliauskas
Esri Regular Contributor

Hi,

You can use MakeFeatureLayer to create a layer from a Feature Class, but you need to change GPExecuteToolFlags from:

GPExecuteToolFlags.AddToHistory

to:

GPExecuteToolFlags.AddOutputsToMap | GPExecuteToolFlags.AddToHistory

ArcGIS Pro geoprocessing without GPExecuteToolFlags.AddOutputsToMap doesn't add layer to map, why your management.SelectLayerByLocation can't find layer from input parameters.

View solution in original post

3 Replies
GKmieliauskas
Esri Regular Contributor

Hi,

You can use MakeFeatureLayer to create a layer from a Feature Class, but you need to change GPExecuteToolFlags from:

GPExecuteToolFlags.AddToHistory

to:

GPExecuteToolFlags.AddOutputsToMap | GPExecuteToolFlags.AddToHistory

ArcGIS Pro geoprocessing without GPExecuteToolFlags.AddOutputsToMap doesn't add layer to map, why your management.SelectLayerByLocation can't find layer from input parameters.

RadekMandovec
Regular Contributor

Hi,

thanks a lot. It works:-)

So there is no way to do it without adding a layer to a map?

0 Kudos
GKmieliauskas
Esri Regular Contributor

I don't know another way. You can try to run all your code in Python without using Geoprocessing (call python code from .NET)