pkreclass(1)

πŸ’– pkreclass β€” replace pixel values in raster image πŸ’–

okay bestie, pull up a chair because pkreclass is about to change your whole raster game. this is the pkreclass(1) manual page, and yes it's giving "I recode pixels for fun and I'm not sorry" energy. let's go πŸ¦‹


✨ SYNOPSIS ✨

pkreclass -i input [ -c from -r to ] -o output [options]

that's it. that's the whole vibe. you give it an input, you tell it what to swap for what, you get an output. slay. πŸ’…


🌸 DESCRIPTION 🌸

pkreclass is a program to replace pixel values in raster images. literally that's the job. in goes a raster, out comes a raster with the pixel values you said to change... changed. no cap. πŸ”₯


πŸ‘‘ OPTIONS πŸ‘‘

okay here's the whole menu, every single one, no skipping, because we don't do that here 🫢

  • -i filename, --input filename β€” the input image. your source material, your main character. πŸ’–
  • -m mask, --mask mask β€” mask image(s). plural, bestie, it said what it said.
  • -msknodata value, --msknodata value β€” mask value(s) where image has nodata. use one value for each mask, or multiple values for a single mask. πŸŽ€
  • -nodata value, --nodata value β€” nodata value to put in image if not valid (default is 0).
  • -code filename, --code filename β€” recode text file, 2 columns: from to. so like, a lil lookup table of glow-ups. ✨
  • -c classes, --class classes β€” list of classes to reclass. works in combination with the reclass option. (they're a duo, they don't go anywhere without each other πŸ₯Ί)
  • -r classes, --reclass classes β€” list of recoded classes. works in combination with the class option. same duo, other half. πŸ’ž
  • -ct filename, --ct filename β€” color table. it's a file with 5 columns: id R G B ALFA (where 0 is transparent and 255 is solid). yes it's spelled ALFA in there, keep it, don't touch it. 🌈
  • -o filename, --output filename β€” output mask file. this is where the magic lands. πŸ‘‘
  • -ot type, --otype type β€” data type for the output image. your choices are {Byte / Int16 / UInt16 / UInt32 / Int32 / Float32 / Float64 / CInt16 / CInt32 / CFloat32 / CFloat64}. empty string means: inherit the type from the input image. 🧚
  • -of format, --oformat format β€” output image format (see also gdal_translate(1)). πŸ‘€
  • -b band, --band band β€” band index(es) to replace. all the other bands just get copied straight to the output, they're innocent bystanders. 😭
  • -n name, --fname name β€” field name of the shape file to be replaced. default: label.
  • -co option, --co option β€” creation option for the output file. you can specify multiple options. stack 'em. πŸ”₯
  • -d description, --description description β€” set image description. give your output a lil name tag. 🏷️
  • -v level, --band band β€” band index(es) to extract. leave it empty to use all bands.
  • -v level, --verbose level β€” verbose mode if > 0. yes, -v shows up twice in this list. no, I did not do that. it's in the original. we simply respect the chaos. πŸ’€

πŸ“ EXAMPLE πŸ“

okay now the fun part, the actual hands-on stuff:

pkreclass -i input1.tif -o output.tif -c 1 -r 0 -c 2 -r 0

replace pixel values 1 and 2 with value 0. two-for-one special. ✨

pkreclass -i vector.shp -o output.shp -c FROM -r TO -n INFIELD

replace FROM with TO in field INFIELD (of type string) in vector file vector.shp and write to new vector output.shp. yes it does vectors too, she contains multitudes. πŸ’…

for((i=0;i<256;++i));do if(($i<100));then echo "$i 1";else echo "$i 0";fi;done > code.txt; pkreclass -i input1.tif -o output.tif --code code.txt

replace all values smaller than 100 with 1, all other values with 0. πŸŽ€

pkreclass -i input1.tif -o output.tif $(for((i=0;i<256;++i));do if(($i<100));then echo -n " -c $i " " -r 1";else echo " -c $i " " -r 0";fi;done)

same as previous but without temporary file. inline. unhinged. iconic. 😌

heads up bestie: run it, don't read it, that's where the joy lives 🫢

and that's the whole page!! this was pkreclass(1), brought to you from the pkreclass(1) manual, dated 01 January 2025. mwah, go recode something pretty πŸ’–βœ¨πŸŽ€

πŸ“¦ where this page comes from