pkextractogr(1)

πŸ’– NAME πŸ’–

okay bestie, so this is pkextractogr(1), and she does exactly one thing but she does it so well: extract pixel values from a raster image, using a sample that can be vector or raster πŸ’…


✨ SYNOPSIS ✨

pkextractogr -i input [-s sample | -rand number | -grid size] -o output
             [options]

like, that's the whole vibe in one line. -i in, -o out, and you pick how you sample in the middle πŸŽ€


🌸 DESCRIPTION 🌸

okay so here's the tea πŸ“ pkextractogr pulls pixel values out of an input raster dataset, and it does it based on the locations you hand it in a sample file. but wait, there's more: if you don't have a sample lying around, you can also get a random sample or a systematic grid of points extracted instead. no sample? no problem. πŸ‘‘

the sample itself can be a vector file with points or polygons. and if you're working with polygons, you've got options, bestie:

  • extract the values for all raster pixels that the polygons cover, or
  • extract a single value for each polygon β€” like the centroid, mean, median, etc.

as output, you get a brand-new copy of the vector file, with an extra attribute holding the extracted pixel value. and not just one attribute β€” for each raster band in the input image, a separate attribute gets created. so if your raster dataset has three bands, you get three attributes, and their names are b0, b1 and b2. cute, consistent, iconic πŸ’–

a typical usage of pkextractogr is to prepare a training sample for one of the classifiers implemented in pktools. iykyk.

🌈 Overview of the possible extraction rules 🌈

here's the full menu, no substitutions, no skipping:

  • point β€” Extract all pixel values covered by the polygon (option -polygon not set) or extract a pixel on the surface option (-polygon set).
  • allpoints β€” Extract all pixel values covered by the polygon.
  • centroid β€” Extract pixel value at the centroid of the polygon.
  • mean β€” Extract average of all pixel values within the polygon.
  • stdev β€” Extract standard deviation of all pixel values within the polygon.
  • median β€” Extract median of all pixel values within the polygon.
  • min β€” Extract minimum value of all pixels within the polygon.
  • max β€” Extract maximum value of all pixels within the polygon.
  • sum β€” Extract sum of the values of all pixels within the polygon.
  • mode β€” Extract the mode of classes within the polygon (classes must be set with the option class).
  • proportion β€” Extract proportion of class(es) within the polygon (classes must be set with the option class).
  • count β€” Extract count of class(es) within the polygon (classes must be set with the option class).
  • percentile β€” Extract percentile as defined by option perc (e.g, 95th percentile of values covered by polygon).

πŸŽ€ OPTIONS πŸŽ€

every single one of them, bestie. nothing left out, nothing merged, we're thorough in this house πŸ’…

  • -i filename, --input filename β€” Raster input dataset containing band information
  • -s sample, --sample sample β€” OGR vector dataset with features to be extracted from input data. Output will contain features with input band information included. Sample image can also be GDAL raster dataset.
  • -ln layer, --ln layer β€” Layer name(s) in sample (leave empty to select all)
  • -rand number, --random number β€” Create simple random sample of points. Provide number of points to generate
  • -grid size, --grid size β€” Create systematic grid of points. Provide cell grid size (in projected units, e.g,. m)
  • -o filename, --output filename β€” Output sample dataset Output sample dataset (yes she said it twice, and honestly? she's right 🫢)
  • -c class, --class class β€” Class(es) to extract from input sample image. Leave empty to extract all valid data pixels from sample dataset. Make sure to set classes if rule is set to mode, proportion or count.
  • -t threshold, --threshold threshold β€” Probability threshold for selecting samples (randomly). Provide probability in percentage (>0) or absolute (<0). Use a single threshold per vector sample layer. If using raster land cover maps as a sample dataset, you can provide a threshold value for each class (e.g. -t 80 -t 60). Use value 100 to select all pixels for selected class(es)
  • -perc percentile, --perc percentile β€” Percentile value used for rule percentile
  • -f format, --f format β€” Output sample dataset format
  • -ft fieldType, --ftype fieldType β€” Field type (only Real or Integer)
  • -lt labelType, --ltype labelType β€” Label type: In16 or String
  • -b band, --band band β€” Band index(es) to extract. Leave empty to use all bands
  • -sband band, --startband band β€” Start band sequence number
  • -eband band, --endband band β€” End band sequence number
  • -r rule, --rule rule β€” Rule how to report image information per feature (only for vector sample). point (value at each point or at centroid if polygon), centroid, mean, stdev, median, proportion, count, min, max, mode, sum, percentile.
  • -bndnodata band, --bndnodata band β€” Band(s) in input image to check if pixel is valid (used for srcnodata)
  • -srcnodata value, --srcnodata value β€” Invalid value(s) for input image
  • -tp threshold, --thresholdPolygon threshold β€” (absolute) threshold for selecting samples in each polygon
  • -buf value, --buffer value β€” Buffer for calculating statistics for point features
  • -circ, --circular β€” Use a circular disc kernel buffer (for vector point sample datasets only, use in combination with buffer option)
  • -v level, --verbose level β€” Verbose mode if > 0
🫢 friendly reminder from your girl: -r only does its thing for a vector sample, and -circ is for vector point sample datasets only β€” use it with the buffer option, not on its own. and -c classes are mandatory the second you pick mode, proportion or count. you got this πŸ’œ

xoxo, that's the whole pkextractogr(1) page, dated 01 January 2025 πŸ’œ go extract something gorgeous, bestie βœ¨πŸ¦‹πŸŒΈ

πŸ“¦ where this page comes from