<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Export a feature layer to shapefile with clipping in ArcGIS Pro SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/export-a-feature-layer-to-shapefile-with-clipping/m-p/1191192#M8371</link>
    <description>&lt;P&gt;Thanks, Charles!! That's a much better solution&amp;nbsp; &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I just needed to pass my clip area to the GP as a List, like you do. I guess the docs could be more clear about accepting clip features as a list, but not a single feature. Anyway, thanks a lot!&lt;/P&gt;</description>
    <pubDate>Mon, 11 Jul 2022 07:34:52 GMT</pubDate>
    <dc:creator>sbayarri_gilytics</dc:creator>
    <dc:date>2022-07-11T07:34:52Z</dc:date>
    <item>
      <title>Export a feature layer to shapefile with clipping</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/export-a-feature-layer-to-shapefile-with-clipping/m-p/1190745#M8360</link>
      <description>&lt;P&gt;Hi everyone.&lt;/P&gt;&lt;P&gt;We need to export a feature layer in the map to a shapefile, but applying a clipping operation with a code-built polygon. The original layer must not be modified.&lt;/P&gt;&lt;P&gt;We've tried running the&amp;nbsp;"analysis.Clip" tool. Unlike the old "arcpy.Clip_analysis", the ArcGIS Pro SDK version seems to require providing the clipping polygon (second GP value) as a FeatureLayer.&lt;/P&gt;&lt;P&gt;We think we need to either:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Make an in-memory FeatureLayer containing the Polygon.&lt;/LI&gt;&lt;LI&gt;Save my polygon to a temporary file whose path can be used as input for the analysis.Clip process.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;We could find a way to do either one in C#. Maybe you can provide a sample or have other ideas. We would prefer not to create any intermediate visible layers in the Map.&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Fri, 08 Jul 2022 08:31:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/export-a-feature-layer-to-shapefile-with-clipping/m-p/1190745#M8360</guid>
      <dc:creator>sbayarri_gilytics</dc:creator>
      <dc:date>2022-07-08T08:31:53Z</dc:date>
    </item>
    <item>
      <title>Re: Export a feature layer to shapefile with clipping</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/export-a-feature-layer-to-shapefile-with-clipping/m-p/1190748#M8361</link>
      <description>&lt;P&gt;A feature layer is a temporary construct within an ArcMap/Pro session, and that is absolutely the way I would go. Really easy to call in arcpy via the "Make Feature Layer" tool. There has always been a little bit of inconsistency in both ArcMap and ArcGIS Pro about which tools require Feature Layers as inputs, and while it's a little bit of a faff, it's realistically only a single extra line of code&lt;/P&gt;</description>
      <pubDate>Fri, 08 Jul 2022 08:44:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/export-a-feature-layer-to-shapefile-with-clipping/m-p/1190748#M8361</guid>
      <dc:creator>RichardHowe</dc:creator>
      <dc:date>2022-07-08T08:44:59Z</dc:date>
    </item>
    <item>
      <title>Re: Export a feature layer to shapefile with clipping</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/export-a-feature-layer-to-shapefile-with-clipping/m-p/1190799#M8363</link>
      <description>&lt;P&gt;Thanks, Richard.&lt;/P&gt;&lt;P&gt;In the end, my solution is quite complex, but I don't see a shorter way. Basically:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;It creates an empty feature class (shapefile) and opens it as a layer (clipLayer), so the clip polygon can be added to it.&lt;/LI&gt;&lt;LI&gt;It calls the Clip GP tool with this clip layer to do the clipping and save the resulting shapefile.&lt;/LI&gt;&lt;/UL&gt;&lt;LI-CODE lang="csharp"&gt;public static async Task&amp;lt;Layer&amp;gt; CreateLayerFromPolygon(string tempDirectory, Polygon clipArea)
        {
            GPExecuteToolFlags flags = GPExecuteToolFlags.GPThread;  // instruct the tool run non-blocking GPThread

            // Create empty feature class
            var valueArrayCreateFCArea = Geoprocessing.MakeValueArray(tempDirectory, "clip_area.shp", "POLYGON");
            IGPResult gpResult = await Geoprocessing.ExecuteToolAsync("management.CreateFeatureclass", valueArrayCreateFCArea, null, null, null, flags);
            if (!Utils.VerifyGPToolResult(gpResult))
                return null;

            // Load feature class as layer
            Uri clipAreaFile = new Uri(Path.Combine(tempDirectory, "clip_area.shp"));
            Layer clipLayer = null;
            await QueuedTask.Run(() =&amp;gt;
                clipLayer = LayerFactory.Instance.CreateLayer(clipAreaFile, Utils.getActiveMap())
            );
            if (clipLayer == null)
                return null;

            // Add clip area to clip layer
            var editOp = new EditOperation();
            editOp.Create(clipLayer, clipArea);
            if (!editOp.Execute())
                return null;

            return clipLayer;
        }

Layer clipLayer = await Utils.CreateLayerFromPolygon(tempDirectory, clipArea);
GPExecuteToolFlags flags = GPExecuteToolFlags.GPThread;

var valueArray = await QueuedTask.Run(() =&amp;gt;
{
    List&amp;lt;string&amp;gt; inlayers = new List&amp;lt;string&amp;gt;();
    inlayers.Add(layerNameToBeClipped);
    string outpath = Path.Combine(outShpDirectory, layerNameToBeClipped + ".shp");
    return Geoprocessing.MakeValueArray(inlayers, clipLayer, outpath);
});

IGPResult gpResult = await Geoprocessing.ExecuteToolAsync("analysis.Clip", valueArray, null, null, null, flags); &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Jul 2022 13:20:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/export-a-feature-layer-to-shapefile-with-clipping/m-p/1190799#M8363</guid>
      <dc:creator>sbayarri_gilytics</dc:creator>
      <dc:date>2022-07-08T13:20:51Z</dc:date>
    </item>
    <item>
      <title>Re: Export a feature layer to shapefile with clipping</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/export-a-feature-layer-to-shapefile-with-clipping/m-p/1190892#M8364</link>
      <description>&lt;P&gt;try this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;internal class Button1 : Button
  {
    protected async void OnClickClip()
    {
      var tool_name = "analysis.Clip";
      var extent = MapView.Active.Extent;
      var sel_layer = MapView.Active.Map.GetLayersAsFlattenedList()
                        .OfType&amp;lt;FeatureLayer&amp;gt;().FirstOrDefault(l =&amp;gt; l.Name == "GreatLakes");
      if (sel_layer == null) return;

      var gdb = Project.Current.DefaultGeodatabasePath;
      var out_fc = System.IO.Path.Combine(gdb, "clipped_lakes_out");

      var val_array = await QueuedTask.Run(() =&amp;gt;
      {

        var rect = GeometryEngine.Instance.Scale(extent, extent.Center, 0.5, 0.5) as Envelope;
        var clip_poly = PolygonBuilderEx.CreatePolygon(rect, rect.SpatialReference);
        var geom = new List&amp;lt;object&amp;gt;() { clip_poly };
        return Geoprocessing.MakeValueArray(new object[] { sel_layer, geom, out_fc });

      });

      Geoprocessing.ExecuteToolAsync(tool_name, val_array,
        null, null, null, GPExecuteToolFlags.InheritGPOptions);
    }

    protected override void OnClick()
    {
      OnClickClip();
    }
  }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Jul 2022 16:31:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/export-a-feature-layer-to-shapefile-with-clipping/m-p/1190892#M8364</guid>
      <dc:creator>CharlesMacleod</dc:creator>
      <dc:date>2022-07-08T16:31:29Z</dc:date>
    </item>
    <item>
      <title>Re: Export a feature layer to shapefile with clipping</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/export-a-feature-layer-to-shapefile-with-clipping/m-p/1191192#M8371</link>
      <description>&lt;P&gt;Thanks, Charles!! That's a much better solution&amp;nbsp; &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I just needed to pass my clip area to the GP as a List, like you do. I guess the docs could be more clear about accepting clip features as a list, but not a single feature. Anyway, thanks a lot!&lt;/P&gt;</description>
      <pubDate>Mon, 11 Jul 2022 07:34:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/export-a-feature-layer-to-shapefile-with-clipping/m-p/1191192#M8371</guid>
      <dc:creator>sbayarri_gilytics</dc:creator>
      <dc:date>2022-07-11T07:34:52Z</dc:date>
    </item>
  </channel>
</rss>

