I think the problem was that I set the nodata value for the current_raster, but forgot to set it for the previous_raster. In addition, I should have calculated accumulation amounts by setting Null values to zero before subtracting.
<SPAN class="keyword token">from</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>sa <SPAN class="keyword token">import</SPAN> <SPAN class="operator token">*</SPAN> current_raster <SPAN class="operator token">=</SPAN> Raster<SPAN class="punctuation token">(</SPAN>current_raster_name<SPAN class="punctuation token">)</SPAN> previous_raster <SPAN class="operator token">=</SPAN> Raster<SPAN class="punctuation token">(</SPAN>previous_raster_name<SPAN class="punctuation token">)</SPAN> current <SPAN class="operator token">=</SPAN> SetNull<SPAN class="punctuation token">(</SPAN>current_raster<SPAN class="punctuation token">,</SPAN> current_raster<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"VALUE < 0"</SPAN><SPAN class="punctuation token">)</SPAN> previous <SPAN class="operator token">=</SPAN> SetNull<SPAN class="punctuation token">(</SPAN>previous_raster<SPAN class="punctuation token">,</SPAN> previous_raster<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"VALUE < 0"</SPAN><SPAN class="punctuation token">)</SPAN> current_raster <SPAN class="operator token">=</SPAN> Con<SPAN class="punctuation token">(</SPAN>IsNull<SPAN class="punctuation token">(</SPAN>current<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">0</SPAN><SPAN class="punctuation token">,</SPAN> current<SPAN class="punctuation token">)</SPAN> previous_raster <SPAN class="operator token">=</SPAN> Con<SPAN class="punctuation token">(</SPAN>IsNull<SPAN class="punctuation token">(</SPAN>previous<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">0</SPAN><SPAN class="punctuation token">,</SPAN> previous<SPAN class="punctuation token">)</SPAN> accum <SPAN class="operator token">=</SPAN> current_raster <SPAN class="operator token">-</SPAN> previous_raster out_con <SPAN class="operator token">=</SPAN> Con<SPAN class="punctuation token">(</SPAN>accum <SPAN class="operator token">></SPAN> <SPAN class="number token">0</SPAN><SPAN class="punctuation token">,</SPAN> accum<SPAN class="punctuation token">)</SPAN> out_con<SPAN class="punctuation token">.</SPAN>save<SPAN class="punctuation token">(</SPAN>output_file<SPAN class="punctuation token">)</SPAN><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>
Hi,
I am having the same problem when writing GeoTiff files. The files can be saved when I am running in debug mode, but not when running the code outside of debug. I can also save the intermediate file by displaying first in ArcDesktop 10.5 and then exporting to a file. I am calculating the difference between two input (geotiff) Rasters, the results are in type "Double." I have checked to make sure there is not a file of the same name already in existence. I have also tested whether or not using a different geodatabase path makes a difference, it does not. I have check to see if I could just save it to a folder, I cannot. The code is as follows (current_datestr example: 201909101900):
output_file <SPAN class="operator token">=</SPAN> <SPAN class="string token">"T2min_{}"</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>current_datestr<SPAN class="punctuation token">)</SPAN> output_file <SPAN class="operator token">=</SPAN> os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>join<SPAN class="punctuation token">(</SPAN>output_workspace<SPAN class="punctuation token">,</SPAN> output_file<SPAN class="punctuation token">)</SPAN> output_file <SPAN class="operator token">=</SPAN> <SPAN class="string token">"{}.tif"</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>splitext<SPAN class="punctuation token">(</SPAN>output_file<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">if</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>Exists<SPAN class="punctuation token">(</SPAN>output_file<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>Delete_management<SPAN class="punctuation token">(</SPAN>output_file<SPAN class="punctuation token">)</SPAN> current_raster <SPAN class="operator token">=</SPAN> Raster<SPAN class="punctuation token">(</SPAN>current_raster<SPAN class="punctuation token">)</SPAN> previous_raster <SPAN class="operator token">=</SPAN> Raster<SPAN class="punctuation token">(</SPAN>previous_raster<SPAN class="punctuation token">)</SPAN> <SPAN class="comment token"># set noData appropriately before subtraction:</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>SetRasterProperties_management<SPAN class="punctuation token">(</SPAN>current_raster<SPAN class="punctuation token">,</SPAN> nodata<SPAN class="operator token">=</SPAN><SPAN class="string token">"1 -3"</SPAN><SPAN class="punctuation token">)</SPAN> accum <SPAN class="operator token">=</SPAN> current_raster <SPAN class="operator token">-</SPAN> previous_raster output_con <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>sa<SPAN class="punctuation token">.</SPAN>Con<SPAN class="punctuation token">(</SPAN>accum <SPAN class="operator token">></SPAN> <SPAN class="number token">0</SPAN><SPAN class="punctuation token">,</SPAN> accum<SPAN class="punctuation token">)</SPAN> output_con<SPAN class="punctuation token">.</SPAN>save<SPAN class="punctuation token">(</SPAN>output_file<SPAN class="punctuation token">)</SPAN><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>
Thanks for your help.
Joleen
DescriptionThe output raster dataset could not be created in the specified format. There may already exist an output raster with the same name and format. Certain raster formats have limitations on the range of values that are supported. For example, the GIF format only supports a value range of 0 to 255, which would be a problem if the output raster would have a range of -10 to 365.SolutionCheck that a raster with the same name and format does not already exist in the output location. Also, check the Help for the technical specifications of raster dataset formats to make sure that the expected range of values in the output is compatible with the specified format.
Membros conectados podem postar, seguir atualizações e mais. Novo aqui? Registre uma conta gratuita.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.