Select to view content in your preferred language

ArcGIS PRO SDK Spatial Join documentation

3199
12
06-03-2020 06:37 AM
by Anonymous User
Not applicable

I am building an Add-in (converting a PyQt app that I wrote) that will need to do a couple of spatial joins and I have been searching for the documentation / reference/ examples of how to do a spatial join (intersect/within) but it seems elusive. 

Intersect returns a boolean; join does not include spatial, searching "spatial join intersect" or "spatial+analyst+spatial+join" in the Pro API reference isn't much help and just returns stuff for table joining.  Besides a blog post I found with an example, "spatial analyst" documentation seems non-existent.  I'm used to python and the ample docs that are easy to find by searching... where is the docs for spatial join operations if it exists, or is the preferred method of running something like a spatial join a python script and toolbox?  I'd like to keep the Add-in 'tools' in C# and in the solution, without having to maintain a toolbox.  Wondering if that is possible though.  Thanks in advance!

0 Kudos
12 Replies
NobbirAhmed
Esri Regular Contributor

There could be several ways to joining data based on spatial relationship. However, using the GP tool Spatial Join is simpler and gives more leverage. Here is a complete code snippet for running Spatial Join with ArcGIS Pro SDK:


protected override async void OnClick()
{
      var environments = Geoprocessing.MakeEnvironmentArray(overwriteoutput: true);


      var parameters = await QueuedTask.Run(() =>
      {
            var target_feats = @"C:\\data.gdb\\Buildings";
            var join_feats = @"C:\\data.gdb\\Points";
            var output_feats =  @"C:\\data.gdb\\Points_to_Poly";
            var join_operation = "JOIN_ONE_TO_MANY";
            var match_option = "INTERSECT"; // WITHIN, WITHIN_A_DISTANCE, CONTAINS etc
            var search_radius = "220 Feet";
            var field_map = ""; // empty string means default field map that contains all the fields from target and join

            return Geoprocessing.MakeValueArray(target_feats, join_feats, output_feats, join_operation,

                                                                           "KEEP_ALL", field_map, match_option, search_radius);
      });

    

      GPExecuteToolFlags flags = GPExecuteToolFlags.AddOutputsToMap | GPExecuteToolFlags.GPThread;

      var toolResult = await Geoprocessing.ExecuteToolAsync("SpatialJoin_analysis", parameters, environments, null, null, flags);

      Geoprocessing.ShowMessageBox(toolResult.Messages, "GP Messages", toolResult.IsFailed ?
      GPMessageBoxStyle.Error : GPMessageBoxStyle.Default);

}

Jeff King‌ - we're in the process of bringing the tool syntax in SDK - like we have now for python for each tool. 

RajagopalManoharan
New Contributor

Hi Nobbir,

Can you please share an example of  how to add reference to shape file & the co-ordinates in the input parameters? We would like to perform spatial join to get attributes and features as a result. We are re-writing below R script,

geocoded_pts <- sf::st_as_sf(geocoded,
coords = c("masterlong", "masterlat"),
crs = "NAD83")

joined <- suppressMessages(sf::st_join(geocoded_pts, csa, join = sf::st_within))

Thanks in advance,

Raj

0 Kudos
GURRAMPALLYJHANSI
New Contributor

I am getting relationship failed error

0 Kudos