Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I would like the following to select (highlight) the "project" layer that intersects the grid, and then pull a record from the selected "Grid". I do not need to save the layer.

Note: Running the script from within ArcMap in the Python Console window.

import arcpy

# Make a layer from the feature class
arcpy.MakeFeatureLayer_management("project","project_lyr")

# Then add a selection to the layer based on location to features in another feature class 
arcpy.SelectLayerByLocation_management("project_lyr","INTERSECT","Grid")

This code runs and no errors are given, yet it does not select(highlight) any features. Any Idea why? Also runs really slow.

Results

Basically I'm trying to do this:

enter image description here

This runs really fast almost instant, but I want to do the same using python. I just need a value from the selected feature's table, I don't need a copy of the layer.

Part of the solution may be to use the in-memory workspace which is

Writing data to the in-memory workspace is often significantly faster than writing to other formats...

Just not sure how to implement in-memory workspace

share|improve this question
    
Are you running this script from within ArcMap (i.e. in the Python console)? Or from outside ArcMap (i.e. within IDLE or another Python editor)? The only way ArcMap will "select(highlight) any features" is from within ArcMap. I suspect that you are running the script from outside ArcMap, because the import arcpy command takes awhile to run. –  dmahr Jul 4 '12 at 16:05
    
I'm running the script from within ArcMap in the Python Console window. –  TForward Jul 4 '12 at 16:07
    
If you're running it from within ArcMap, you do not need the arcpy.MakeFeatureLayer() line, since project is already a layer. Just do arcpy.SelectLayerByLocation_management("project","INTERSECT","Grid"). –  dmahr Jul 4 '12 at 16:48
    
great question format! –  Brad Nesom Jul 4 '12 at 17:06
    
Thanks @dmahr, still runs slower than the built-in Select by Attribute but works. –  TForward Jul 4 '12 at 17:35
add comment

1 Answer 1

Good question!

Dmahr is right, it's quicker to simply just select the layer instead of creating a feature layer. I would also add the rest of the variables, even though they are optional.

arcpy.SelectLayerByLocation_management ("project_lyr", "INTERSECT", "Grid", "#", "NEW_SELECTION")

Another thing I find, is that running things in the python window of ArcMap is always slower. I find that if you write the code to a .py file, add it as a script to the toolbox and then run it, the processing will go faster.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.