Clipping rasters by shapefile

1790
9
09-21-2010 11:12 PM
Highlighted
New Contributor III
Hi,
I need to clip a lot of rasters by a shapefile (clip by irregular shape) and I need a georeferenced jpg as an output. I am trying using "Extract by mask" which basically does what I wanted except:
1. the output is GRID instead jpg
2. it makes grid for each color band
3. it's extremely slow and
4. it crashes with a large mask file

Any thoughts would be appreciated.
Thx,
Reply
0 Kudos
9 Replies
Highlighted
New Contributor III
OK. I've made it half way around.
I solved the problem with the JPEG output (convert GRID to jpg and delete GRID), however, the problems with speed and large shape file are still there.

For clipping an image size 1000x1000 pixels it takes for about 10 minutes! How to speed up the process?
BTW, I have polygon shape file representing surface area of roads, however, since my images cover a larger area, I need to clip them before analyzing them in terms of crack detection..
See the attached code.
Thanks for your suggestions,
Reply
0 Kudos
Highlighted
New Contributor III
Hi Matej,

You can use the clip geoprocessing tool in the raster toolset. This tool allows you to clip based on the geometry of your feature (a parameter on the tool) and you can simply change the output from output.img or output.tif to output.jpg. This way, assuming that your input has a georeference, your output jpg image should also be georeferenced.
See the help for more details: http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//00170000009n000000.htm

Robert
Reply
0 Kudos
Highlighted
New Contributor III
Thank you, Robert!

Using gp.clip_management works much faster indeed and also produces jpgs. The only thing that bothered me was that the clipped image was not of the same brightness as the original. Now I added the line: gp.compression= "LZ77" and everything looks awesome!! Thank you again, Robert!
Attached is the working script.
...
As I cheched again the pixel values of the result are not the same as the original's, despite the LZ77 setting.. Any thoughts on how to achieve that the pixel values of the clipped image remain the same?
Reply
0 Kudos
Highlighted
New Contributor III
Hi Matej,

When you use jpg compression the compression algorithm is allowed to change pixel values slightly to achieve a higher compression ratio (smaller files). This is called lossy compression. http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//009t00000021000000.htm
Other compression algorithms such as RLE or LZW are lossless, meaning the pixels remain the same, but they don't work with jpg. You could use .img or .tif for those (and several other formats).
Another reason why the image might look slightly different (usually you wouldn't notice the difference visually with jpg) is that the statistics are now different and so the image will be stretched differently.
Another reason why identify might show different pixel could be a pixel shift. If you clip to a boundary then your pixels might shift slightly to accommodate the new extent. You can see if snap raster will resolve this. Otherwise clip with lossless compression should not change the pixel value.
I'm glad this is working well for you.

Robert
Reply
0 Kudos
Highlighted
New Contributor III
The JPEG format only supports JPEG compression (not LZ77 compression). However, you can generally achieve a lossless jpeg compression if you modify the compression quality used by the JPEG to 100. However, like posted earlier, if you can use something other than JPEG (such as TIFF) you can guarantee a lossless compression.
Reply
0 Kudos
Highlighted
Occasional Contributor II
Thank you, Robert!

Using gp.clip_management works much faster indeed and also produces jpgs. The only thing that bothered me was that the clipped image was not of the same brightness as the original. Now I added the line: gp.compression= "LZ77" and everything looks awesome!! Thank you again, Robert!
Attached is the working script.
...
As I cheched again the pixel values of the result are not the same as the original's, despite the LZ77 setting.. Any thoughts on how to achieve that the pixel values of the clipped image remain the same?


Hi Matejt,

Does that script actually work?  I'm trying to do something similar and I can't get the extent to work out.  The clip tool seems a little redundant, if I already have a feature class I want to clip the raster by why do I need to supply the clip extent.  Anyway, I've gotten the extent from my feature class and supplied that to the tool but it doesn't actually clip the raster.  If I choose the clippinggeometry option it will be masked by the feature class but the extent is the same as the original.  My feature class and raster are in different coordinate systems, that might be an issue.  Is your feature class and raster in the same coordinate system? 

I'd appreciate any info.  Thanks very much,

Nils
Reply
0 Kudos
Highlighted
New Contributor II
Hello.  I am having a similar issue with the Raster clip tool changing the pixel color of the output.  I have tried .jpg, .tif, and .img output and none match the original raster.  Its important for me that the colors stay consistent.  Any suggestions?  Thanks
Reply
0 Kudos
Highlighted
Occasional Contributor III
Download what used to be Hawth Tools.
http://www.spatialecology.com/gme/gmedownload.htm

As for the colours the raster displays, that can be made the same with statistics options as long as the values are not being modified.
Reply
0 Kudos
Highlighted
Occasional Contributor II
Georeferencing is indeed broken during a clip at ArcGIS 10. I dont know how ESRI allowed this to happen because it was fixed at ArcGIS 9.3.1.

I vaguely remember scripting the same function at ArcGIS 9.3 and was relieved to see it was fixed in the last version.

For now I have justed 5 days struggling with this bug in ArcGIS 10 when the raster clipping and georeferencing function is handled in FME 2010.

I am seriously considering going back to ArcGIS 9.3.1.
Reply
0 Kudos