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: the pkcrop utility is not suitable to mosaic or composite images. if that's what you're after, go talk to pkcomposite(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 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).
  • -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 πŸ‘‘

pkcomposite(1)


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