Arcpy clip file tiff

1262
12
09-21-2016 02:03 PM
DEVAPP
by
New Contributor III

Hi guys,

i have a tiff image that into Arcmap i clip with Data Frame Clip using a shp file into data frame as mask to clip and i have the result that you can see into this image

instead when i create a python script i can't use clip data frame so i use clip_managment or extract by mask with the same shp file but the result is different, you can see in this second image

You can see that the bouds of clip are not smooth as first clip resulted by clip data frame.

How i can resolve this problem and have the same result with bounds smooth?

Thanks

0 Kudos
12 Replies
DanPatterson_Retired
MVP Esteemed Contributor

in order to get the smoother edge, you have to explicitly set the cell size in the Environments tab of the tool.  If you don't, it defaults to 1/250th of the maximum of the extent with or height.  So when opening any tool in Arctoolbox, the first place you should go to is the Environments Tab and set your raster properties (there are a couple of places inside)

0 Kudos
DEVAPP
by
New Contributor III

Ok but i have deelop a script to add into custom toolbox

0 Kudos
DanPatterson_Retired
MVP Esteemed Contributor

would be nice to mention that as well, but as usual, there is an arcpy interface... see the examples in Environments section of arcpy and those that apply to raster processing.

Cell Size (Environment setting)—Help | ArcGIS for Desktop 

DEVAPP
by
New Contributor III

Dan i have set arcpy.env.cellSIze = 0.5 and after i have run my arcoy clip but the result is the same. More bounds are not smooth

0 Kudos
DanPatterson_Retired
MVP Esteemed Contributor

If you have a script, you should post it... it is not possible to discern an error from comments solely

0 Kudos
DEVAPP
by
New Contributor III

Hi Dan this is my script

def main():
    print "Start script"
    arcpy.env.overwriteOutput=True
    arcpy.env.cellSize = 0.1
    env.workspace = arcpy.GetParameterAsText(0)
    date = arcpy.GetParameterAsText(1)
    excludedValues = arcpy.GetParameterAsText(2)
    mxd = arcpy.mapping.MapDocument("Map.mxd")
    df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
    strNdvi = "ndvi.tif"
    strNdviLayer = "ndviLayer.lyr"
    Temp_Symbology = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'ndviLayer.lyr')

    # Generate NDVI
    strRedImage = "Image1.jp2"
    strIVImage = "Image2.jp2"
    strPolygons = "polygon.shp"
    strPolygon = "polygon"
    sr = arcpy.Describe(strRedImage).spatialReference
    df.spatialReference = sr

    if not arcpy.Exists(strNdvi) and arcpy.Exists(strRedImage) and arcpy.Exists(strIVImage):
        rasNdvi = Divide(Minus(Float(strRedImage),Float(strIVImage)),Plus(Float(strRedImage),Float(strIVImage)))
        rasNdvi.save("ndvi.tif")
        print "NDVI created."

the ndvi created have a cell size 10 x 10 , i have used Describe to see

and this is the rest of code

 arcpy.MakeRasterLayer_management(strNdvi, "ndvilyr")
    lyrNdvi = arcpy.mapping.Layer(strNdvi)
    arcpy.mapping.AddLayer(df, lyrNdvi)
    lyr = arcpy.mapping.ListLayers(mxd)[0]

    

    ##Clip Raster Dataset with feature geometry
    arcpy.env.cellSize = 0.05
    arcpy.Clip_management("ndvi.tif", "#", "ndvi_clip.tif",strPolygons, "0", "ClippingGeometry")
    print "clip ok"

and the result is the second image, with bounds not smooth

thanks

0 Kudos
DanPatterson_Retired
MVP Esteemed Contributor

Make Raster Layer—Help | ArcGIS for Desktop doesn't honour global settings other than workspaces... try

Feature to Raster—Help | ArcGIS for Desktop  which uses a cell size explicitly

You have to check what environment variables are honoured by tools as well

0 Kudos
DEVAPP
by
New Contributor III

Hi have try Dan but the result is always the same.

I have a result clip with bounds not smooth

0 Kudos
DanPatterson_Retired
MVP Esteemed Contributor

you set the cell size in FeatureToRaster?

0 Kudos