Select to view content in your preferred language

Need help in automating a clip and selection task

1058
8
Jump to solution
03-04-2023 08:33 PM
QuintinChua
New Contributor II

Running ArcGIS Pro 3.0.3

Hello! I'm currently working on my first GIS project where I want to analyze the relationship between built density, population density, and a series of economic indicators on a national level. In trying to format the data I've been clipping global data rasters using polygons from another data set. On a country by country basis this is no problem since I can just select by by attribute and then crop the raster.

Table for national boundaries: 

QuintinChua_0-1677989759787.png

 

Sample output:

QuintinChua_1-1677989817724.png

This works fine on a country by country level but becomes unsustainable when considering all the countries in the world, and then all those countries through time.  So then I tried to create a model in order to automate this task.  Initially I tried to replicate this task on a small scale using select and manually imputing the ISO code e.g. ISO = AFG

QuintinChua_2-1677990240338.png

This seem to work well enough so I then attempted to scale up by iterating through all the features:

QuintinChua_3-1677990364881.png

This model though ran in just a few seconds and didn't output anything.

Here are the logs:

Executing (Clip Raster): Clip "Build Layer 2022\GHS_BUILT_V_2020_Normalized" "-7374014.36551057 -6393314.96175094 7505723.76745417 6930686.77697801" C***test.gdb\Test I_ppp_1k_mask_Di_ExportFeature2_OBJECTID 0 ClippingGeometry NO_MAINTAIN_EXTENT
Start Time: Sunday, March 5, 2023 12:26:26 PM
Building Pyramids...
Succeeded at Sunday, March 5, 2023 12:26:28 PM (Elapsed Time: 1.74 seconds)

Now though I am a little unsure on how to move forward with my project. Am I doing something wrong with the 2nd model making it output nothing? Am I taking the wrong approach in splitting the raster? Any thoughts and assistance would be greatly appreciated!  

 

Additional Info!

The data I'm using for the polygons comes from here: https://hub.arcgis.com/datasets/WorldPop::national-boundaries-1km/about

and the population and build density data originates from: https://ghsl.jrc.ec.europa.eu/download.php

 

0 Kudos
1 Solution

Accepted Solutions
DavidPike
MVP Frequent Contributor

For your Iterate Feature Selection add a Group By field of 'ISO' this will then mean you 'Value' output from each iteration will be the string of each iterated row e.g. 'ABW' for the first iteration.  You will use this value as an inline variable for your output raster name.

Clip Raster - what's the exclamation mark popup message?  What workspace are you saving to - folder or geodatabase?  If a folder it would need the filename to have an extension e.g. .tif

Output Raster Dataset - this is where you use the Value output name to name your file. Try:

%Value%_test.tif 

if in a folder workspace or

%Value%_test

if in a gdb.  I'd also suggest saving as a tif in a folder rather than a gdb if so anyway.

View solution in original post

8 Replies
DavidPike
MVP Frequent Contributor

The first model runs OK without the iterator?  If so then we can fortunately rule out a data issue.

Are you using inline variable substitution to name the output rasters?  Can you share a screenshot of the properties of:

Iterate feature selection

Selected features

Clip raster

in the second model.

QuintinChua
New Contributor II

Thank you so much for your response!

- Yup! the first one works fine if I manually assign the country.

- I am not using inline variable substitution since I am not too familiar with the process.

-Iterate feature selection

QuintinChua_5-1678066000848.png

-Selected features

QuintinChua_7-1678066036977.png

-Clip raster

QuintinChua_8-1678066072658.png

Again thank you so much for your help!

0 Kudos
DavidPike
MVP Frequent Contributor

For your Iterate Feature Selection add a Group By field of 'ISO' this will then mean you 'Value' output from each iteration will be the string of each iterated row e.g. 'ABW' for the first iteration.  You will use this value as an inline variable for your output raster name.

Clip Raster - what's the exclamation mark popup message?  What workspace are you saving to - folder or geodatabase?  If a folder it would need the filename to have an extension e.g. .tif

Output Raster Dataset - this is where you use the Value output name to name your file. Try:

%Value%_test.tif 

if in a folder workspace or

%Value%_test

if in a gdb.  I'd also suggest saving as a tif in a folder rather than a gdb if so anyway.

QuintinChua
New Contributor II

Hello! Thank you so much your solution worked brilliantly! I just have one last question, is it possible to automatically export attribute tables to csv?

I've attempted to add the export table tool in the model builder but it only seems to output 1 file with missing data.

-model

QuintinChua_0-1678179089815.png

 

-export table

QuintinChua_1-1678179126224.png

-output 

QuintinChua_2-1678179152570.png

- Actual output

QuintinChua_3-1678179201400.png

-Excel output

QuintinChua_4-1678179243826.png

The error warning is just Warning 000258, showing that an output with that name already exists.

Once again thank you so much for your help! I really appreciate it.

 

0 Kudos
DavidPike
MVP Frequent Contributor

It looks ok, did you delete the CSV that's already in there?  Does it run once, produce then error?
Your filename in the screenshot doesn't match up with the other screenshots so I'm not quite understnading.

0 Kudos
QuintinChua
New Contributor II

Hello! Just to clarify I was able to run the export rasters part of the model and was able to extract the needed information. 

QuintinChua_0-1678210898053.png

Meaning that this segment of the model was able to run perfectly without error!

The follow up question that I'm asking is why the export table tool does not seem to work as expected. 

QuintinChua_2-1678211100020.png

for instance when I examine the attribute table of VNM I would get the following information.

QuintinChua_4-1678211350044.png

Which is verified when I would manually use the export table tool.

- Details

QuintinChua_5-1678211394084.png

 

- Result

QuintinChua_3-1678211296785.png

but when I would run it using the model builder the output is missing the 2nd and 3rd column 

QuintinChua_6-1678211474996.png

Here are the specifications of the export table tool:

QuintinChua_7-1678211535765.png

 

Thank you so much for your time! you've been incredibly patient with me, my apologies if I am a little slow!

 

 

 

0 Kudos
DavidPike
MVP Frequent Contributor

I'm guessing the clip raster tool in model builder isn't calculating statistics or somehow not producing a raster attribute table.  I would ensure RasterStatistics options are set in the environments settings of the clip raster tool in model builder https://pro.arcgis.com/en/pro-app/latest/tool-reference/environment-settings/raster-statistics.htm and maybe play around with adding the build raster attribute table tool as a process after the raster is generated and before export table https://pro.arcgis.com/en/pro-app/latest/tool-reference/data-management/build-raster-attribute-table... 

Can you check in the attribute table of the iterated output rasters and see what columns are available?

I'd also recommend posting this new issue as a separate problem so it gets more traction for new views, and it helps to logically separate issues for posterity.

0 Kudos
QuintinChua
New Contributor II

Once again thank you so much for your response

-The Raster Statistics box is checked 

QuintinChua_0-1678240579217.png

-I've played a bit with the build raster attribute table to the same result
-model

QuintinChua_1-1678240651023.png

 

-build raster

QuintinChua_2-1678240673763.png

 

-result

QuintinChua_3-1678240702089.png

- Value from iterated raster table shows full data

QuintinChua_4-1678240759915.png

 

Thank you so much for your time! and ill post this as a new question. You've helped me immensely! 

 

0 Kudos