Process finished with exit code -1073741819 (0xC0000005) - Simple clipping tool

3076
3
09-19-2019 03:16 AM
JamesHone1
New Contributor III

Hi,

Im trying to learn to make geoprocessing tools.

Making a simple one to clip a raster but getting an error I cant decipher, from googling it looks like some kind of access violation.

heres my code

import arcpy

# Set geoprocessing environments
arcpy.env.workspace = r"C:\Jim\BathySelect\BSelect.gdb"
arcpy.env.overwriteOutput = True

#set params
inTif = r"C:\Jim\BathySelect\Data\Bathy\Whole UK Mosaic.tif"
desc = arcpy.Describe("SelectPoly")
outTif = r"C:\Jim\output.tif"

extent = desc.extent
rectangle = arcpy.Polygon(arcpy.Array([extent.lowerLeft, extent.upperLeft, extent.upperRight, extent.lowerRight, extent.lowerLeft]), desc.spatialReference)


arcpy.Clip_management(inTif, rectangle, outTif)

heres my error

C:\Python27\ArcGIS10.6\python.exe C:/Jim/BathySelect/BathySelect.py

Process finished with exit code -1073741819 (0xC0000005)

I eventually want this to fire from a widget in a WAB app and return a zip file of multiple clipped images.

0 Kudos
3 Replies
JamesHone1
New Contributor III

So I have made some progress, I realised I could export a modelbuilder version as a script and compare.

The problem was my extent I was passing in wasnt in correct format.

I now have the extent converted to a string and it runs, but it doesnt clip the right area

import arcpy

# Set geoprocessing environments
arcpy.env.workspace = r"C:\Jim\BathySelect\BSelect.gdb"
arcpy.env.overwriteOutput = True

#set params
inTif = r"C:\Jim\BathySelect\Data\Bathy\Whole UK Mosaic.tif"
poly = r"C:\Jim\BathySelect\SelectPoly.shp"
desc = arcpy.Describe(poly)
outTif = r"C:\Jim\output.tif"

extent = desc.extent

arcpy.Clip_management(inTif, str(extent), outTif, poly, "0", "NONE", "NO_MAINTAIN_EXTENT")

when I look at the generated script the values it passes in for the same polygon are :-   

   "-610219.285476707 6629015.89017292 -581115.060601592 6655474.27642303"

but the figures in my extent are :-

   “-5.48169310808 51.2315325764 -5.2202454077 51.3805117862”

this looks like a lat/lng vs metres problem now but not sure, still after a bit of help.

0 Kudos
Jeremy_Moore
MVP

I think whats happening is that when you are grabbing the information for the shapefile VIA

arcpy.Describe(poly)

it is giving you the extent for the shapefile and not the polygon information. I could be wrong though.

Within the documentation for Clip_management, it says the rectangle can use a Envelope, Feature Class or  Feature Layer. So lets try feeding in the clipping polygon information another way.  

Clip Raster—Data Management toolbox | ArcGIS Desktop 

Change str(extent) to poly and see if it works. If it doesn't work, import the shapefile into your BSelect.gdb as a featureclass and replace str(extent) with a variable for the path to the new featureclass.

EDIT:

I noticed you are using all of the optional parameters. Try replacing your Clip_management with this:

arcpy.Clip_management(inTif, poly, outTif)
0 Kudos
JamesHone1
New Contributor III

so it seems my 2 datasets were in different projections that's why I was getting different values for the extents.

Once I changed my shapefile projectiont match my tiff projection all my numbers looked good and tif was cropped.

0 Kudos