I need to make clips from a single raster (and save them as individual raster files). The coordinates of each point are in a shapefile. At the moment, I am buffering a radius around (1meter) each point, then clipping it from a raster using the following code in a loop for each point.
point <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>Point<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
point<SPAN class="punctuation token">.</SPAN>X <SPAN class="operator token">=</SPAN> x_coord
point<SPAN class="punctuation token">.</SPAN>Y <SPAN class="operator token">=</SPAN> y_coord
ptObject <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>PointGeometry<SPAN class="punctuation token">(</SPAN>point<SPAN class="punctuation token">,</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>SpatialReference<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"WGS 1984"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN>projectAs<SPAN class="punctuation token">(</SPAN>arcpy<SPAN class="punctuation token">.</SPAN>SpatialReference<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"WGS 1984 UTM Zone 55S"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>Buffer_analysis<SPAN class="punctuation token">(</SPAN>in_features <SPAN class="operator token">=</SPAN> ptObject<SPAN class="punctuation token">,</SPAN> out_feature_class <SPAN class="operator token">=</SPAN> buffer_filepath<SPAN class="punctuation token">,</SPAN> buffer_distance_or_field <SPAN class="operator token">=</SPAN> <SPAN class="string token">"1 Meters"</SPAN><SPAN class="punctuation token">,</SPAN> line_side <SPAN class="operator token">=</SPAN> <SPAN class="string token">"FULL"</SPAN><SPAN class="punctuation token">,</SPAN> line_end_type <SPAN class="operator token">=</SPAN> <SPAN class="string token">"ROUND"</SPAN><SPAN class="punctuation token">,</SPAN> dissolve_option <SPAN class="operator token">=</SPAN> <SPAN class="string token">"NONE"</SPAN><SPAN class="punctuation token">,</SPAN> dissolve_field <SPAN class="operator token">=</SPAN> <SPAN class="string token">""</SPAN><SPAN class="punctuation token">,</SPAN> method <SPAN class="operator token">=</SPAN> <SPAN class="string token">"PLANAR"</SPAN><SPAN class="punctuation token">)</SPAN>
desc <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>Describe<SPAN class="punctuation token">(</SPAN>buffer_filepath<SPAN class="punctuation token">)</SPAN>
ExtStr <SPAN class="operator token">=</SPAN> <SPAN class="string token">"{0} {1} {2} {3}"</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>desc<SPAN class="punctuation token">.</SPAN>extent<SPAN class="punctuation token">.</SPAN>XMin<SPAN class="punctuation token">,</SPAN> desc<SPAN class="punctuation token">.</SPAN>extent<SPAN class="punctuation token">.</SPAN>YMin<SPAN class="punctuation token">,</SPAN> desc<SPAN class="punctuation token">.</SPAN>extent<SPAN class="punctuation token">.</SPAN>XMax<SPAN class="punctuation token">,</SPAN> desc<SPAN class="punctuation token">.</SPAN>extent<SPAN class="punctuation token">.</SPAN>YMax<SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>Clip_management<SPAN class="punctuation token">(</SPAN>in_raster <SPAN class="operator token">=</SPAN> raster_filepath<SPAN class="punctuation token">,</SPAN> out_raster <SPAN class="operator token">=</SPAN> clip_filepath<SPAN class="punctuation token">,</SPAN> rectangle <SPAN class="operator token">=</SPAN> ExtStr<SPAN class="punctuation token">,</SPAN> nodata_value <SPAN class="operator token">=</SPAN> <SPAN class="string token">"-999"</SPAN><SPAN class="punctuation token">,</SPAN> in_template_dataset <SPAN class="operator token">=</SPAN> buffer_filepath<SPAN class="punctuation token">,</SPAN> clipping_geometry <SPAN class="operator token">=</SPAN> <SPAN class="string token">"ClippingGeometry"</SPAN><SPAN class="punctuation token">,</SPAN> maintain_clipping_extent <SPAN class="operator token">=</SPAN> <SPAN class="string token">"NO_MAINTAIN_EXTENT"</SPAN><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>This works, but is a little slow for a couple of hundred clips, and I need to do cleanup on the temporary buffer files afterwards.
I would like to do something like the following:
point <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>Point<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
point<SPAN class="punctuation token">.</SPAN>X <SPAN class="operator token">=</SPAN> x_coord
point<SPAN class="punctuation token">.</SPAN>Y <SPAN class="operator token">=</SPAN> y_coord
ptObject <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>PointGeometry<SPAN class="punctuation token">(</SPAN>point<SPAN class="punctuation token">,</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>SpatialReference<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"WGS 1984"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN>projectAs<SPAN class="punctuation token">(</SPAN>arcpy<SPAN class="punctuation token">.</SPAN>SpatialReference<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"WGS 1984 UTM Zone 55S"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># Create a buffer property directly on the point geometry object</SPAN>
ptObject_buffer <SPAN class="operator token">=</SPAN> ptObject<SPAN class="punctuation token">.</SPAN>buffer<SPAN class="punctuation token">(</SPAN><SPAN class="number token">1.0</SPAN><SPAN class="punctuation token">)</SPAN>
ptObject_extent <SPAN class="operator token">=</SPAN> ptObject_buffer<SPAN class="punctuation token">.</SPAN>extent
arcpy<SPAN class="punctuation token">.</SPAN>MakeFeatureLayer_management<SPAN class="punctuation token">(</SPAN>in_features <SPAN class="operator token">=</SPAN> ptObject_buffer<SPAN class="punctuation token">,</SPAN> out_layer <SPAN class="operator token">=</SPAN> <SPAN class="string token">"tmp"</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># Clip the raster using the point geometry object directly</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>Clip_management<SPAN class="punctuation token">(</SPAN>in_raster <SPAN class="operator token">=</SPAN> raster_filepath<SPAN class="punctuation token">,</SPAN> out_raster <SPAN class="operator token">=</SPAN> clip_filepath<SPAN class="punctuation token">,</SPAN> rectangle <SPAN class="operator token">=</SPAN> ptObject_extent <SPAN class="punctuation token">,</SPAN> nodata_value <SPAN class="operator token">=</SPAN> <SPAN class="string token">"-999"</SPAN><SPAN class="punctuation token">,</SPAN> in_template_dataset <SPAN class="operator token">=</SPAN> <SPAN class="string token">"tmp"</SPAN><SPAN class="punctuation token">,</SPAN> clipping_geometry <SPAN class="operator token">=</SPAN> <SPAN class="string token">"ClippingGeometry"</SPAN><SPAN class="punctuation token">,</SPAN> maintain_clipping_extent <SPAN class="operator token">=</SPAN> <SPAN class="string token">"NO_MAINTAIN_EXTENT"</SPAN><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>
When I run this code I get error 001143: "Background server threw an exception"
My aim is to avoid creating the temporary buffer files - although I realize this method also requires me to delete the temporary layer file in each loop iteration, which might turn out to be slower in the end...
Am I on the right track, or is there a simpler or faster way to achieve what I need to? Thank you in advance for your help!