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 is0).-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(where0is transparent and255is 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 alsogdal_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,-vshows 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
- 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