Select to view content in your preferred language

how to parse the raster name into a table in model builder or python

865
2
03-24-2021 08:20 AM
MonicaRuano1
Emerging Contributor

Hi!

 

I need help to finish a task.

I am trying to use model builder to simplify a task with Zonal Statistics as Table. I have temperature and precipitation *. bil files in their folders.  Problem with model builder is that I have to generate two toolboxes. One for temperature and one for precipitation. Now I am trying with temperature. 

I am using the iterate rasters to read the rasters, but I wanted to use the Name to fill a new field that I want to create in the table created with the Zonal Statistics. But I don't manage to do it.  I am using a polygon of municipalities as feature zone data and the rasters as Input value display.

Can somebody help me with tips? I will appreciate it. I would like to have a table  like this.  By now I am able to get a table by dataset (one for temperature (tm), one for precipitation (rr)), but no raster name yet and not a merge table either.

raster_nameMunicipality_numberAltituderrtmsdsdfswfswswe
         

 

I am attaching the model builder example also. 

I was also trying some python, but I don't manage to add the name to the table either on Python. I was generating a listraster but I am new to python and do now how to add the rasters name in the table.  Here is the python example also attached.

 

 

 

0 Kudos
2 Replies
DavidPike
MVP Frequent Contributor

I've not really checked your script for errors but I guess it works (also if you want to share code in the future, add it as code formatted text - screenshots of code are awful to deal with)

If it works, you're creating a table in each for loop - so add a new field (TEXT) to the table Add Field (Data Management)—ArcGIS Pro | Documentation

then calculate field for all rows in the table (as you may have more than one zone I guess) - Calculate Field (Data Management)—ArcGIS Pro | Documentation

you can use the inRaster  variable as it's a string of your raster name (I think?) i.e. expression = inRaster

0 Kudos
MonicaRuano1
Emerging Contributor

Thanks for your reply and help. Yes, I will next time attach the script as text. I manage to workaround the model builder. I haven't tried it just as plain python script, but I will.  I am attaching the model I was using. I was creating a clean table with the same attributes from the table generated in the zonal statistics (including the new attribute, name of the raster). And I was appending each calculation to that table. 

0 Kudos