arcpy.Clip_management having different output from using Python and not

3477
4
04-06-2016 11:46 AM
XueyingZhang1
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
output_path="C:/NDVI/2012/"


# 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)
   shp_list.append(fullpath)
   date_id.append(f[9:16])
   tile_id.append(f[17:23])


# Count the elements in shp_list
N=len(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!

Sue-ying

0 Kudos
4 Replies
DanPatterson_Retired
MVP Emeritus

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
XueyingZhang1
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
curtvprice
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
AndrewKeith3
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