Select to view content in your preferred language

arcpy.management.Project() doesn't honor feature layer's query

1583
9
Jump to solution
11-08-2023 07:42 AM
Labels (3)
Matt-Goodman
Occasional Contributor

Hello, 

I'm running a stand alone script that, early on, uses arcpy.management.MakeFeatureLayer() with a simple where clause defining the data I want included.

Later in the script, I use that feature layer as the input for arcpy.management.Project(). Unfortunately, the output of the Project tool does not honor the SQL query applied to the feature layer. 

Is this expected behavior? If not, any suggestions on how to troubleshoot why it's not being honored?

P.S. I asked ChatGPT this question and received a self-contradicting answer: it initially stated that this behavior is expected and that the Project() tool does not honor a feature layer's definition query, but then went on to suggest creating a feature layer with a where clause and feeding that as the input to the Project() tool. 

EDIT: I just inserted a line into my script to return a message giving the feature count of the feature layer immediately before the Project() tool uses it as input and the feature count returned is still limited by the where clause. So, I have to conclude that the Project() tool just ignores the query (I'm still not sure if this is by design or not). 

0 Kudos
1 Solution

Accepted Solutions
Matt-Goodman
Occasional Contributor

I'm replying to my own post, since Esri provided an answer to me through a bug report. Essentially this is expected behavior in earlier versions of ArcGIS Pro and I was mis-referencing documentation from a more recent version of Pro. 

The management.Project() tool does not honor queried/selected features in versions of ArcGIS Pro up through 3.1. Here is a snippet of the documentation from earlier versions (up through 3.1):

Selection and definition queries on layers are ignored by this tool—all features in the dataset referenced by the layer will be projected. To project only selected features, consider using the Copy Features tool to create a temporary dataset, which will only contain the selected features, and use this intermediate dataset as input to the Project tool.

However, at version 3.2, the documentation correctly states:

Selection and definition queries on layers are supported by this tool. Only selected features in the layer will be projected when the selection or query is defined.

I hope this clarifies the issue for anyone else noticing it. 

View solution in original post

9 Replies
MarlonAmaya
Esri Contributor

Hi @Matt-Goodman ,

 

Per our documentation, the project tool will honor the definition query / selection set on the layer

https://pro.arcgis.com/en/pro-app/latest/tool-reference/data-management/project.htm#:~:text=Selectio....

 

Since the make feature layer is temp layer, I wonder if there is issue with the input you are providing. A quick test we can do is provide a selection/query to a feature class that is already created within your data source. Does this input combine with project provide the expected output?

 

Marlon

0 Kudos
Matt-Goodman
Occasional Contributor

Hi @MarlonAmaya , I did do some testing in my script, using the GetCount() function. I used GetCount() to compare the source feature class with the temporary MakeFeatureLayer version of it, and the query is correctly querying the data. I inserted the GetCount() function into my script in several different places, including immediately before the Project() tool runs, and the feature count indicates that the query is indeed working correctly, but the Project() tool is not honoring it. The count returned by the GetCount function is lower than the count of the output of the Project() tool. 

0 Kudos
MarlonAmaya
Esri Contributor

HI @Matt-Goodman ,

The steps below are to see if the behavior is across the board.

Do you get the same result if you use the geoprocessing tool instead of arcpy?

what happens if you set a definition query on the feature class and use this as the input (instead of temp layer)?

Marlon

0 Kudos
Matt-Goodman
Occasional Contributor

Hi @MarlonAmaya ,

Yes, this happens with the geoprocessing tool within ArcGIS Pro too. In the attached screenshot, I applied a definition query to the "source_rcl" layer (reducing it to 395 features) and then used it as input for the Project geoprocessing tool. The output, "map_rcl_out" had all 20, 727 features. 

0 Kudos
Matt-Goodman
Occasional Contributor

Also, I simplified my script to a very basic form, as a test. The attached shows the full text of the python as well as the message details after running it, demonstrating the feature counts before and after running the Project tool. 

0 Kudos
MarlonAmaya
Esri Contributor

Hi @Matt-Goodman ,

I am seeing the same behavior with a simple feature class with 4 records, add def query to show 2, run project, output is 4. 

Please contact technical support to further investigate.

Marlon

0 Kudos
RobThomas
New Contributor

I have the same issue with running project on a selection set in a stand-alone Python script. All features are in included in the output, not just the selection.  I have to export the selection to a new feature class before running the project.  Currently running ArcGIS Pro 3.1.3 installation package.  Tested at 3.1.1 and same issue there.

Matt-Goodman
Occasional Contributor

The Rob Thomas? 

0 Kudos
Matt-Goodman
Occasional Contributor

I'm replying to my own post, since Esri provided an answer to me through a bug report. Essentially this is expected behavior in earlier versions of ArcGIS Pro and I was mis-referencing documentation from a more recent version of Pro. 

The management.Project() tool does not honor queried/selected features in versions of ArcGIS Pro up through 3.1. Here is a snippet of the documentation from earlier versions (up through 3.1):

Selection and definition queries on layers are ignored by this tool—all features in the dataset referenced by the layer will be projected. To project only selected features, consider using the Copy Features tool to create a temporary dataset, which will only contain the selected features, and use this intermediate dataset as input to the Project tool.

However, at version 3.2, the documentation correctly states:

Selection and definition queries on layers are supported by this tool. Only selected features in the layer will be projected when the selection or query is defined.

I hope this clarifies the issue for anyone else noticing it.