logo
Free, unlimited AI code reviews that run on commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

pkcrop - perform raster data operations on image such as crop, extract and stack bands

Description

pkcrop can subset and stack raster images.  In the spatial domain it can crop a bounding box from a larg‐
       er  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  do‐
       main,  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 provid‐
       ed,  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.

Example

       Crop the input image to the given bounding box

       pkcrop-iinput.tif-ulx100-uly1000-lrx600-lrx100-ooutput.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-iinput.tif-eextent.shp-ooutput.tif
       gdal_rasterize -i -burn 0 -l extent extent.shp output.tif
       gdal_rasterize-i-burn0-lextentextent.shpoutput.tif

       Extract bands 3,2,1 (starting from 0) in that order from multi-band raster image input.tifpkcrop-iinput.tif-b3-b2-b1-ooutput.tif

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

       pkcrop-ifimage.tif-s100-otByte-obimage.tif-ctcolortable.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-ifimage.tif-as0-as100-otByte-obimage.tif-ctcolortable.txt

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

       pkcrop-ilarge.tif $(pkinfo-ismall.tif-bb-dx-dy) -ooutput.tif

Name

       pkcrop - perform raster data operations on image such as crop, extract and stack bands

Options

-ifilename, --inputfilename
              Input image file(s).  If input contains multiple images, a multi-band output is created

       -ofilename, --outputfilename
              Output image file

       -ofout_format, --oformatout_format
              Output image format (see also gdal_translate(1)).  Empty string: inherit from input image

       -ottype, --otypetype
              Data type for output image ({Byte / Int16 / UInt16 / UInt32 / Int32 / Float32 / Float64 / CInt16 /
              CInt32 / CFloat32 / CFloat64}).  Empty string: inherit type from input image

       -bband, --bandband
              Band index to crop (leave empty to retain all bands)

       -sbandband, --startbandband
              Start band sequence number

       -ebandband, --endbandband
              End band sequence number

       -ulxULX, --ulxULX
              Upper left x value bounding box

       -ulyULY, --ulyULY
              Upper left y value bounding box

       -lrxLRX, --lrxLRX
              Lower right x value bounding box

       -lryLRY, --lryLRY
              Lower right y value bounding box

       -dxxres, --dxxres
              Output resolution in x (in meter) (empty: keep original resolution)

       -dyyres, --dyyres
              Output resolution in y (in meter) (empty: keep original resolution)

       -rresampling_method, --resampling-methodresampling_method
              Resampling method (near: nearest neighbor, bilinear: bi-linear interpolation).

       -a_srsEPSG:number, --a_srsEPSG: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)

       -nodatavalue, --nodatavalue
              Nodata value to put in image if out of bounds.

       Advanced options

       -evector, --extentvector
              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

       -eooptions, --eooptions
              Special  extent  options  controlling  rasterization:   ATTRIBUTE|CHUNKYSIZE|ALL_TOUCHED|BURN_VAL‐
              UE_FROM|MERGE_ALG, e.g., -eo ATTRIBUTE=fieldname-mfile, --maskfile
              Use the specified file as a validity mask (0 is nodata)

       -msknodatavalue, --msknodatavalue
              Mask value not to consider for crop

       -mskbandvalue, --mskbandvalue
              Mask band to read (0 indexed).

       -coNAME=VALUE, --coNAME=VALUE
              Creation option for output file.  Multiple options can be specified.

       -xcenter_x, --xcenter_x
              x-coordinate of image center to crop (in meter)

       -ycenter_y, --ycenter_y
              y-coordinate of image center to crop (in meter)

       -nxsize_x, --nxsize_x
              image size in x to crop (in meter)

       -nysize_y, --nysize_y
              image size in y to crop (in meter)

       -nsnsample, --nsnsample
              number of samples to crop (in pixels)

       -nlnlines, --nlnlines
              number of lines to crop (in pixels)

       -asmin-asmax, --autoscalemin--autoscaleautoscalemax
              scale output to min and max, e.g., --autoscale0--autoscale255-scalescale, --scalescale
              output=scale*input+offset

       -offoffset, --offsetoffset
              output=scale*input+offset

       -ctfilename, --ctfilename
              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

       -ddescription, --descriptiondescription
              Set image description

       -v, --verbose
              verbose

See Also

pkcomposite(1)

                                                 01 January 2025                                       pkcrop(1)

Synopsis

pkcrop-iinput-ooutput [options] [advancedoptions]

See Also