I have roughly 50 mosaic datasets with 50 corresponding point feature classes. My goal is to append the raster cell value (elevation) to the overlying point. The mosaic datasets are all from a single band rasters (elevation). I've been trying to iterate the process in arcpy, but I've been having mixed results. I'm running ArcGIS Desktop 10.6.1, and all the feature classes and mosaic datasets are in the same projection. When I run my script I'll get the results I want for the first few iterations, but then the remaining point feature classes contain extracted values that don't exist within any of the rasters.
I'm not sure on the best method to extract values from a mosaic dataset. The one way that seems to work is to make a a mosaic layer from the mosaic dataset. I've been creating the mosaic layer in the same geodatabase where the point feature classes are stored and then running extraction.
<SPAN class="keyword token">import</SPAN> arcpy
<SPAN class="keyword token">from</SPAN> arcpy <SPAN class="keyword token">import</SPAN> env
<SPAN class="keyword token">import</SPAN> os
<SPAN class="comment token">#create a list of all folders in the directory</SPAN>
directory <SPAN class="operator token">=</SPAN> <SPAN class="string token">"path to folders with rasters and mosaic datasets"</SPAN>
folders <SPAN class="operator token">=</SPAN> os<SPAN class="punctuation token">.</SPAN>listdir<SPAN class="punctuation token">(</SPAN>directory<SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token">#create list of the point feature classes</SPAN>
env<SPAN class="punctuation token">.</SPAN>workspace <SPAN class="operator token">=</SPAN> r<SPAN class="string token">'path to point feature classes'</SPAN>
files <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>ListFeatureClasses<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
point_path <SPAN class="operator token">=</SPAN> <SPAN class="string token">"path to point feature classes"</SPAN> <SPAN class="comment token">#for use in creating the mosaic layer</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>CheckOutExtension<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Spatial"</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">for</SPAN> i<SPAN class="punctuation token">,</SPAN> j <SPAN class="keyword token">in</SPAN> zip<SPAN class="punctuation token">(</SPAN>folders<SPAN class="punctuation token">,</SPAN> files<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
in_workspace <SPAN class="operator token">=</SPAN> i<SPAN class="operator token">+</SPAN><SPAN class="string token">"path to each geodatabase"</SPAN>
in_mosaic_dataset_name <SPAN class="operator token">=</SPAN> <SPAN class="string token">"mosaic dataset name"</SPAN>
path_to_raster <SPAN class="operator token">=</SPAN> in_workspace<SPAN class="operator token">+</SPAN>in_mosaic_dataset_name
outlayername <SPAN class="operator token">=</SPAN> point_path<SPAN class="operator token">+</SPAN>in_mosaic_dataset_name
arcpy<SPAN class="punctuation token">.</SPAN>MakeMosaicLayer_management<SPAN class="punctuation token">(</SPAN>path_to_raster<SPAN class="punctuation token">,</SPAN>outlayername<SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>sa<SPAN class="punctuation token">.</SPAN>ExtractMultiValuesToPoints<SPAN class="punctuation token">(</SPAN>j<SPAN class="punctuation token">,</SPAN> outlayername<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></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>I've run this both in the python window of ArcMap and in spyder, and in both instances I run into problems. The first few iterations work fine and then the raster cell values that are extracted do not exist in any of the rasters. Is there a better way to extract raster cell values from a mosaic dataset?
Cheers!