pkcrop(1) perform raster data operations on image such as crop, extract and stack bands


pkcrop -i input -o output [options] [advanced options]


pkcrop can subset and stack raster images. In the spatial domain it can crop a bounding box from a larger image. The output bounding box is selected by setting the new corner coordinates using the options -ulx -uly -lrx -lry. Alternatively you can set the new image center (-x -y) and size. This can be done either in projected coordinates (using the options -nx -ny) or in image coordinates (using the options -ns -nl). You can also use a vector file to set the new bounding box (option -e). In the spectral domain, pkcrop allows you to select individual bands from one or more input image(s). Bands are stored in the same order as provided on the command line, using the option -b. Band numbers start with index 0 (indicating the first band). The default is to select all input bands. If more input images are provided, the bands are stacked into a multi-band image. If the bounding boxes or spatial resolution are not identical for all input images, you should explicitly set them via the options. The pkcrop utility is not suitable to mosaic or composite images. Consider the utility pkcomposite(1) instead.


-i filename, --input filename
Input image file(s). If input contains multiple images, a multi-band output is created
-o filename, --output filename
Output image file
-of out_format, --oformat out_format
Output image format (see also gdal_translate(1)). Empty string: inherit from input image
-ot type, --otype type
Data type for output image ({Byte / Int16 / UInt16 / UInt32 / Int32 / Float32 / Float64 / CInt16 / CInt32 / CFloat32 / CFloat64}). Empty string: inherit type from input image
-b band, --band band
Band index to crop (leave empty to retain all bands)
-sband band, --startband band
Start band sequence number
-eband band, --endband band
End band sequence number
-ulx ULX, --ulx ULX
Upper left x value bounding box
-uly ULY, --uly ULY
Upper left y value bounding box
-lrx LRX, --lrx LRX
Lower right x value bounding box
-lry LRY, --lry LRY
Lower right y value bounding box
-dx xres, --dx xres
Output resolution in x (in meter) (empty: keep original resolution)
-dy yres, --dy yres
Output resolution in y (in meter) (empty: keep original resolution)
-r resampling_method, --resampling-method resampling_method
Resampling method (near: nearest neighbor, bilinear: bi-linear interpolation).
-a_srs EPSG:number, --a_srs EPSG:number
Override the spatial reference for the output file (leave blank to copy from input file, use epsg:3035 to use European projection and force to European grid)
-nodata value, --nodata value
Nodata value to put in image if out of bounds.

Advanced options

-e vector, --extent vector
get boundary from extent from polygons in vector file
-cut, --crop_to_cutline
Crop the extent of the target dataset to the extent of the cutline
-eo options, --eo options
Special extent options controlling rasterization: ATTRIBUTE|CHUNKYSIZE|ALL_TOUCHED|BURN_VALUE_FROM|MERGE_ALG, e.g., -eo ATTRIBUTE=fieldname
-m file, --mask file
Use the specified file as a validity mask (0 is nodata)
-msknodata value, --msknodata value
Mask value not to consider for crop
-mskband value, --mskband value
Mask band to read (0 indexed).
Creation option for output file. Multiple options can be specified.
-x center_x, --x center_x
x-coordinate of image center to crop (in meter)
-y center_y, --y center_y
y-coordinate of image center to crop (in meter)
-nx size_x, --nx size_x
image size in x to crop (in meter)
-ny size_y, --ny size_y
image size in y to crop (in meter)
-ns nsample, --ns nsample
number of samples to crop (in pixels)
-nl nlines, --nl nlines
number of lines to crop (in pixels)
-as min -as max, --autoscale min --autoscaleautoscale max
scale output to min and max, e.g., --autoscale 0 --autoscale 255
-scale scale, --scale scale
-off offset, --offset offset
-ct filename, --ct filename
colour table in ASCII format having 5 columns: id R G B ALFA (0: transparent, 255: solid)
-align, --align
Align output bounding box to input image
-d description, --description description
Set image description
-v, --verbose


Crop the input image to the given bounding box

pkcrop -i input.tif -ulx 100 -uly 1000 -lrx 600 -lrx 100 -o output.tif

Crop the input image to the envelop of the given polygon and mask all pixels outside polygon as 0 (using gdal_rasterize(1))

pkcrop -i input.tif -e extent.shp -o output.tif
gdal_rasterize -i -burn 0 -l extent extent.shp output.tif
gdal_rasterize -i -burn 0 -l extent extent.shp output.tif

Extract bands 3,2,1 (starting from 0) in that order from multi-band raster image input.tif

pkcrop -i input.tif -b 3 -b 2 -b 1 -o output.tif

Scale raster floating point image fimage.tif with factor 100 and write as single byte image with the given colourtable (for auto scaling, see next example)

pkcrop -i fimage.tif -s 100 -ot Byte -o bimage.tif -ct colortable.txt

Automatically scale raster floating point image fimage.tif to [0:100] and write the output as a single byte image with the given colourtable

pkcrop -i fimage.tif -as 0 -as 100 -ot Byte -o bimage.tif -ct colortable.txt

Crop raster image large.tif to the bounding box of raster image small.tif and use the same pixel size.

pkcrop -i large.tif $(pkinfo -i small.tif -bb -dx -dy) -o output.tif