Select to view content in your preferred language

arcpy command for "Select by location" tool ?

2717
9
Jump to solution
10-17-2018 05:51 AM
FredCoud
Occasional Contributor

Hi,

I have the following data :

- a raster catalog

- a feature class composed of several polygons.

I want to get the polygons (the ENTIRE polygon) which contain the raster catalog or part of it.

I checked some tools in ArcMap, and I observed that the "Select by location" tool works perfectly (not the tool Select Layer by location). The result is a selection of only the polygons (from the feature class layer) that contain the raster catalog. But I can't find anything about an arcpy command...

I found the "SelectLayerByLocation_management" (Select Layer by location tool) but the resulting selection is empty, so it doesn't do the job.

Does anyone have information regarding the "Select by location" tool adptation to arcpy ?

I have to use a tool that can handle raster catalog.

0 Kudos
1 Solution

Accepted Solutions
FredCoud
Occasional Contributor

Hello,

At the end I decided not to use the raster catalog, but the map index provided with the images used to create the catalog.

I then used the arcpy command "Select Layer by Location" with this map index and, hurray !, it works !!

Thanks for the answers.

View solution in original post

0 Kudos
9 Replies
DanPatterson_Retired
MVP Emeritus

Select Layer By Location—Data Management toolbox | ArcGIS Desktop 

in_layer

The features that will be evaluated against the select_features parameter. The selection will be applied to this layer.

Feature Layer; Raster Layer; Mosaic Layer

Could be that it stipulates a raster layer and not a raster catalog. 

JoeBorgione
MVP Emeritus

To add to Dan's response:  Make Feature Layer—Help | ArcGIS Desktop , Make Raster Layer—Help | ArcGIS Desktop & Make Table View—Help | ArcGIS Desktop 

When interacting with features, rasters, or tables, in the arcpy environment you need to turn them into 'layers' or 'views' respectively and interact with those.

That should just about do it....
0 Kudos
FredCoud
Occasional Contributor

I do not quite understand what you are both saying.

I was referring only to the Select by location tool in ArcMap, and wondering if the arcpy version of this tool actually existed. This tool works fine with my raster catalog.

If you mean to use the function MakeRasterCatalogLayer_management on my raster catalog and then to use SelectLayerByLocation_management on its result, it does not work, I have already tried it.I set the raster catalog into the "in_layer" field.When I say it does not work, I mean it returns something that is empty. When i printed the result, it only returned the name of the catalog. Nothing more.

So I tried the opposite, I set the raster catalog in the filed "select_features". Then I had the mistake saying that the input data is not a feature data.

So I think I tried pretty much everything with this SelectLayerByLocation.

My question is : is there a python equivalent to SelectByLocation ? It seems everyone use SelectLayerByLocation on the net, but it's not the one I want... Unless both functions are in fact one ? Then I would be interested in knowing how it is called..  Because I cannot reproduce anything with the other function...

0 Kudos
JoeBorgione
MVP Emeritus

...is there a python equivalent to SelectByLocation ...   It seems everyone use SelectLayerByLocation 

When you use an actual geoprocessing tool, (as I understand them) it's doing some work behind the scenes for you.  As mentioned above; When interacting with features, rasters, or tables, in the arcpy environment...  you don't have the luxury of the tool doing the work behind the scenes.  You need to do some additional lifting.

Make sense?

That should just about do it....
0 Kudos
DanPatterson_Retired
MVP Emeritus

There is an equivalent for everything that exists in ArcToolbox regardless of whether it is ArcGIS pro or arcmap.

You can access the functionality of any tool in arctoolbox.

But 'tools' on a toolbar, or any other shortcut, are the domain of arcobjects.

You have probably explored arcpy... but some may not have

ArcGIS Pro Python Reference—ArcGIS Pro | ArcGIS Desktop 

As for tool functionality and accessing it through scripts, then the code examples are given at the bottom of each tool

ArcGIS Pro tool reference—ArcGIS Pro | ArcGIS Desktop 

FredCoud
Occasional Contributor

Oh, I think I see !

Indeed, the SelectByLocation is on a toolbar, and I could not find it in the toolbox... So that means that it is an arcobject...hum...

Alright, so I have to go through with SelectLayerByLocation and some additional processes, is that what you were trying say ?

Well then , as I wrote earlier, I tryied the following :

  1. set the paths for the raster catalog and the polygon feature class;
  2. use the arcpy function MakeFeatureLayer_management to set the polygon feature class as layer;
  3. use the arcpy function MakeRasterCatalogLayer_management to set the raster catalog as a layer;
  4. use the arcpy function SelectLayerByLocation_management on the results from step 2 and step 3, according to the following :
    • in_layer -> raster catalog as layer;
    • overlap_type = "CONTAINS";
    • select_features -> polygon feature class as layer;
    • search_distance -> null;
    • selection_type -> "NEW_SELECTION";
    • invert_spatial_relationship = "NOT_INVERT"

Did I miss a step when doing this ?

When I print the resulting selection in my python terminal, I receive the name of the raster catalog layer.

When I launch all of the commands in ArcMap Python window, I can see the polygon layer and the raster catalog layer appear at steps 2 and 3. But then, when I run step 4, the resulting selection is empty. There is nothing to even clear (I mean the button "clear selection").

What do you think of this process ?

0 Kudos
JoeBorgione
MVP Emeritus

Can you provide the code you are using?  When replying, expand the toolbar to the 'More' pulldown and select Syntax Highlighter and paste your code in a Python window...

That should just about do it....
0 Kudos
DanPatterson_Retired
MVP Emeritus

I suggest you try it manually using the tool.

A mosaic layer, I suspect isn't a raster layer, and if the select by... in arctoolbox has only specific things that it will select (ie feature and raster layers), then it wouldn't surprise me if it doesn't work.

I suspect it is the type of layer that is more important and not the fact that it is a layer at all

FredCoud
Occasional Contributor

Hello,

At the end I decided not to use the raster catalog, but the map index provided with the images used to create the catalog.

I then used the arcpy command "Select Layer by Location" with this map index and, hurray !, it works !!

Thanks for the answers.

0 Kudos