pkcrop(1)
π pkcrop(1) π
okay so bestie, pkcrop(1) is that girl. she does raster data operations β crop, extract, stack bands, the whole vibe. let's get into it π«Ά
β¨ NAME β¨
pkcrop β perform raster data operations on image such as crop, extract and stack bands. no cap. π
πΈ SYNOPSIS πΈ
pkcrop -i input -o output [options] [advanced options]
π¦ DESCRIPTION π¦
so what does she actually do. pkcrop can subset and stack raster images, periodt. π
in the spatial domain she can crop a bounding box out of a bigger image. you pick that output bounding box by setting the new corner coordinates with the options -ulx -uly -lrx -lry. or, if you're feeling a different way, you can set the new image center (-x -y) plus size. and the size can be given either in projected coordinates (options -nx -ny) or in image coordinates (options -ns -nl). you can also just hand her a vector file to set the new bounding box (option -e). so many paths to the same slay. β¨
in the spectral domain, pkcrop lets you pick individual bands from one or more input image(s). bands get stored in the exact same order you provided them on the command line, using the option -b. and listen: band numbers start with index 0 (so 0 = the first band, not the second, don't do it to yourself π). the default is to select all input bands. if you give more input images, the bands get stacked into a multi-band image.
if the bounding boxes or the spatial resolution aren't identical for all your input images, you should explicitly set them via the options. like, actually set them, don't just hope. π
π¨ real talk: thepkcroputility is not suitable to mosaic or composite images. if that's what you're after, go talk topkcomposite(1)instead. she's the one for that job. π
π OPTIONS π
-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 alsogdal_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, useepsg:3035to 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 (0is nodata)-msknodata value,--msknodata valueβ Mask value not to consider for crop-mskband value,--mskband valueβ Mask band to read (0indexed).-co NAME=VALUE,--co NAME=VALUEβ 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βoutput=scale*input+offset-off offset,--offset offsetβoutput=scale*input+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β verbose
π₯ EXAMPLE π₯
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
π SEE ALSO π
okay that's the whole page, you ate that π one last thing for the girlies who read to the bottom: this is pkcrop(1), dated 01 January 2025. go crop something iconic. β¨πΈπ¦
π¦ where this page comes from
- ubuntu questing: pktools 2.6.7.6+ds-6build4
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms