Hi,
How can i make a division of more than two raster with arcpy?
Do you mean how to do something like (raster1/raster2)/raster3? See help here. You just turn them into raster objects and divide:
outRaster <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">(</SPAN>Raster<SPAN class="punctuation token">(</SPAN>raster1<SPAN class="punctuation token">)</SPAN><SPAN class="operator token">/</SPAN>Raster<SPAN class="punctuation token">(</SPAN>raster2<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="operator token">/</SPAN>Raster<SPAN class="punctuation token">(</SPAN>raster3<SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN></SPAN>
I have two sets of rasters (r_rain_m1 * up to m10 and r_weight_m1 * up to10) in two folders (folder_rain and folder_weight), and I want to split r_rain rasters between r_weight.
For example, r_rain_m1 / r_weight_m1, r_rain_m2 / r_wieght_m2, ...
Thanks for the help!
I'd create a separate list of raster for each folder using the List Rasters function. http://pro.arcgis.com/en/pro-app/arcpy/functions/listrasters.htm
I'd iterate through one list to use as the first input for the Divide function and use an index to pull the appropriate raster from the second list of rasters.
<SPAN class="keyword token">import</SPAN> arcpy <SPAN class="keyword token">import</SPAN> os arcpy<SPAN class="punctuation token">.</SPAN>CheckOutExtension<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Spatial"</SPAN><SPAN class="punctuation token">)</SPAN> output_path <SPAN class="operator token">=</SPAN> r<SPAN class="string token">"pathtooutputfolder"</SPAN> rain_folder <SPAN class="operator token">=</SPAN> r<SPAN class="string token">"pathtorainfolder"</SPAN> weight_folder <SPAN class="operator token">=</SPAN> r<SPAN class="string token">"pathtoweightfolder"</SPAN> rain_list <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>ListRasters<SPAN class="punctuation token">(</SPAN>rainfolder<SPAN class="punctuation token">)</SPAN> weight_folder <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>ListRasters<SPAN class="punctuation token">(</SPAN>weight_folder<SPAN class="punctuation token">)</SPAN> count <SPAN class="operator token">=</SPAN> <SPAN class="number token">0</SPAN> <SPAN class="keyword token">for</SPAN> ras <SPAN class="keyword token">in</SPAN> rainlist<SPAN class="punctuation token">:</SPAN> outDivide <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>sa<SPAN class="punctuation token">.</SPAN>Divide<SPAN class="punctuation token">(</SPAN>ras<SPAN class="punctuation token">,</SPAN> weight_list<SPAN class="punctuation token">[</SPAN>count<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN> outDivide<SPAN class="punctuation token">.</SPAN>save<SPAN class="punctuation token">(</SPAN>os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>join<SPAN class="punctuation token">(</SPAN>output_path<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">" r_divide_m"</SPAN> <SPAN class="operator token">+</SPAN> str<SPAN class="punctuation token">(</SPAN>count <SPAN class="operator token">+</SPAN> <SPAN class="number token">1</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">+</SPAN> <SPAN class="string token">".tif"</SPAN><SPAN class="punctuation token">)</SPAN> count <SPAN class="operator token">+=</SPAN> <SPAN class="number token">1</SPAN> <SPAN class="keyword token">del</SPAN> outDivide <SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
Signed in members can post, follow updates, and more. New here? Register a free account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.