arcpy.Clip_management having different output from using Python and not

04-06-2016 11:46 AM
New Contributor

Dear All,

I use the Clip in the Raster Processing to clip some grid from a raster file. But the outputs are different from using Python or not.

Here is my code:

import arcpy
import os
from arcpy import env

# Set environment settings
env.workspace = "C:/data"

# Clip the layer, remove the points located outside of Texas boundary

# Read datafiles for clip
in_path = "C:/NDVI_data/2012/MOD13A3_out/"
shp_list = []
date_id = []
tile_id = []
for dirpath, dirnames, files in os.walk(in_path):
for f in files:
  if f.lower().endswith("_reproj.dat"):
   fullpath = os.path.join(dirpath, f)

# Count the elements in shp_list

# Clip raster
for i in range(0,1):
in_raster = shp_list
out_feature = "NDVI_clip"+date_id+tile_id
Rectangle = "-106.928314 25.611530 -93.605938 35.355261"
Clip_feature = "C://PM_Site/IMPROVE_2011_1km_albers.shp"
arcpy.Clip_management(in_raster,Rectangle,out_feature, Clip_feature,"-999","ClippingGeometry","MAINTAIN_EXTENT")

And the output looks like this:

But if I don't use the Python.

The output is looks like this:

Why there are two grids missing by using the Python?

I will really appreciate your help!


0 Kudos
4 Replies
MVP Esteemed Contributor

note clear in the first image you set the extent to decimal degree coordinates, but you are using an albers (projected) file.  Can you confirm the extents in both files as to whether were selected from the layer or typed in and whether in file being clipped has the same coordinates as the clipping file

PS I would check the effect of the checkbox ... maintain clipping extent

0 Kudos
New Contributor

Yes, I'm sure I used the exact same input files. Just the name shows differently because I take the screenshot in different times. Sorry for the confusing.

And I did checked the two boxess, "ClippingGeometry" and "maintain clipping extent".

Using the same input files but the output is different, that confused me.

0 Kudos
MVP Esteemed Contributor

If the tools and inputs are the same but outputs are different, I suggest investigating if the environment settings in ArcMap and in the script environment are script are different. Especially check processing extent, output coordinate system, mask.

0 Kudos
Occasional Contributor

Set your Rectangle variable to "#".  You don't need to specify an envelope if you are providing a shp as the clipping extent.

Rectangle = "#"

0 Kudos