Skip to contents

decoupage 0.2.0

First version. decoupage cuts a territory into contiguous areas whose sizes stay within bounds, at the census scale (blocks into pre-census enumeration areas) and at the survey scale (enumeration areas into PSUs, segments and SSUs). It returns geometry, ids, sizes, an order and flags, and never selection probabilities or weights. The same functions work at every level, so PSUs, segments, SSUs and supervision areas are built with the calls that build enumeration areas. They take any polygons and any additive size, so they also build agricultural area frames and forest inventories. A simulator builds populations and frames with a known truth, for comparing survey designs.

Inputs

  • build_blocks() cuts boundary units, such as admin units, into blocks along roads, tracks, paths and the zones between settlements. Every block nests in one unit and carries its columns, and faces below min_area, or narrower on average than min_width, join a neighboring block, such as the strips between a road and a unit line drawn along it. A line running within precision of a unit’s boundary does not cost the unit any land. A line crossing the boundary between two units cuts both, and the blocks on either side share their vertices, so the blocks form a coverage. A boundary column named unit, block, zone or settlement, such as the id of a management unit, is an error rather than being replaced by the computed column of that name. zone and settlement keep the ids of the settlements with their type, so codes such as "001" stay as written and a factor stays a factor.
  • delineate_settlements() finds settlement patches from building points on a grid, for the zones of build_blocks() and the patch of unit_graph().
  • measure_units() returns the size of each unit from a raster of counts or from weighted points. With inside, such as building footprints, each cell’s count goes to the units holding those features, so blocks with no building get nothing, and only the window of the raster the units span is read.
  • assign_points() gives each point or footprint one unit, with a fixed rule for points on a shared line and the unit holding most of a footprint, so the result does not depend on row order. A unit that only touches a footprint holds none of it. Every function that reads points or footprints uses the same rule.
  • assign_units() gives each unit to one point, such as a settlement of a census directory, so every settlement gets a connected territory of whole units within its admin unit. A unit holding several settlements is cut between them.
  • A weight or a size can be a column name or a vector, on a layer of any number of rows, one included.

Grouping and cutting

  • unit_graph() builds the contiguity graph of a polygon layer once, with shared boundary lengths. Units touching at a corner are not adjacent, and no edge joins two parts of within (such as two admin units or strata) or crosses a barrier line. It records the part of each boundary on visible lines, links units whose interiors overlap, and keeps the pairs dropped at a barrier with the barrier’s rank. With gap, land that no edge joins to the rest of its part, as across a creek, is linked to the nearest unit, and with gap = Inf also to the largest piece of its part. Overlaps that check_units() would leave out as rounding are counted apart as slivers, so the print reports the same overlaps as the check.
  • group_units() groups units into contiguous groups within a size cap and an area cap, near a target size when one is given, and lifts groups below a minimum where a neighbor has room. The bounds can differ from one part of within to the next, as EA sizes do by stratum.
    • The "tree" method cuts a maximum spanning tree with the exact algorithm of Kundu and Misra (1977), and the "greedy" method follows the merge of the WorldPop preEA tool. A local search then evens sizes, improves shapes and draws boundaries along visible lines.
    • With n, each part, or each level of n_by (a stratum shared among its wards), gets an exact number of groups as far as the caps allow. A part whose land lies in more pieces than its count opens the barrier crossings and gap links it needs, joining the smallest pieces first.
    • With groups, a table of groups of known sizes such as the EAs of a census table, each part is cut into those groups, each toward the size of its row and with its id, so a frame built from published counts needs no match of codes afterwards. A group left above a cap gets a warning that names its row.
    • Settlements under the caps are never split, locked groups (fixed) stay as they are, and barriers give way only where they enclose too little (cross_below, one value per part or a column). A locked group does not count as land enclosed with the free units next to it, so those units still cross a barrier when they hold too little.
    • The "merge" method only merges units below the minimum with their neighbors, as when small EAs become PSUs, and id gives each group the id of its first unit, as svyplan::merge_psus() does.
    • With seed, each part draws its tree from the seed alone, under R’s default generator, so a part gets the same groups run on its own or in parallel workers.
  • split_units() cuts units above a size or area cap into contiguous pieces, by weighted recursive bisection or by quadtree, with cuts that pass between buildings where they can. Pieces keep the columns of their unit and their share of its size. With lines, such as tracks and field edges left out of the blocks, a unit is cut along them into faces, the faces are grouped into pieces, and a cut runs straight only inside a face too large for a piece. visible gives the share of each piece’s cut boundary on the lines. A unit with no point inside, or of size 0, is cut by area on a fixed grid, so its pieces do not depend on the random seed. With max_area, each bisection cut balances size and area, whichever is the tighter cap, so every piece meets max_area.
  • dissolve_units() merges the units of each group into one polygon, sums one or more sizes, such as households and cropland, and keeps the columns that are constant within each group. A label or a size named units, area or geometry, or a size named like the label, is an error, as are a split_units() size and an assign_units() within named like a column they compute.
  • order_units() ranks units along a Hilbert curve or a serpentine within each part of within, such as a stratum, for systematic selection and the zones of svyplan::n_alloc().
  • group_graph() turns a grouping into the graph of its groups, so group_units() builds the level above with the same engine, nested by construction.

Checks

  • check_units() lists the defects of a layer of units, one row per finding. It checks the geometry (overlaps, gaps, invalid polygons), and, when given them, nesting in and coverage of a boundary layer, such as admin units, and sizes out of bounds. Gaps and overlaps thinner than tolerance are rounding and are left out, as are the holes of the boundary layer. With id and groups, it checks an admin layer against a table of records before the units are cut, and reports parts of the table with no unit and units with no records, among them those inside another unit, such as a town coded in the district around it.
  • check_groups() tests a grouping against the rules every grouping must meet and flags the violations that the caps make unavoidable. It takes n, n_by and groups, and reports a level off its count, a group that is no row of the table, a row with no group and a group outside the part of its row, with the level, part or row in detail. Like group_units(), it takes a layer and its graph together through graph, so the columns of the layer are named as in group_metrics().
  • group_metrics() returns the size, area and four shape measures of each group. With the graph, it splits each group’s perimeter into within lines, barriers, and boundaries with other groups that are visible or not, and flags groups another group encloses.
  • graph_lines() draws the edges and barrier crossings of a graph as lines, for checking in a GIS.
  • audit_field() compares field points, such as a listing, with the areas of a frame.

Frame updates

  • code_units() builds hierarchical codes numbered in a geographic order. Against a previous version, unchanged units keep their codes and the pieces of a split unit get child codes.
  • crosswalk_units() returns the correspondence between two versions of a layer, with the shares of area and of size each pair holds in common. A unit with no size, such as one whose points all weigh 0, has NA size shares.
  • renest_units() carries a partition to new boundaries, such as redrawn admin units, and partitions again only the groups the new lines cross, keeping to the barriers, visible lines and patches of the first partition. New groups are labeled after every label in use, so its output can be re-nested again, and a factor group stays a factor. Bounds given per unit, such as min and max, go to every piece of a cut unit.

Simulation

  • A population and its frames are separate objects. A population (decoupage_population) holds a territory, households and persons with their outcomes. A frame (decoupage_frame) holds the population it was built on, its EAs, the EA of each household and the frame a planner receives, so frames of different EA sizes are compared on the same persons. A household can be any listing unit with members, such as an establishment or a plot.
  • sim_territory() starts from a real boundary or a synthetic one, and sim_households() places households in towns and villages or in proportion to a population raster. A raster cell partly inside the territory gets its share of households once. Each household records its town or village as settlement, and settlement_cv sets how much their sizes vary, from equal to a few large and many small.
  • sim_outcome() adds an outcome whose latent variance is shared among region, district, spatial, ea, household and person components. An ea component is drawn on a given frame and recorded with the outcome. effects shifts the latent outcome by household columns, in latent standard deviations, so mean, sd and prevalence hold in the reference group. A binary outcome is a probit model. The spatial field stops before it allocates more than getOption("decoupage.max_field_cells", 2.5e7) grid cells, and says what it needs.
  • sim_frame() delineates EAs on a population with the package’s own engine. populate_frame() creates a population inside an existing EA layer, with exact or expected counts and households placed uniformly, by a raster or in villages. as_population() wraps households and persons made elsewhere, and as_frame() lays an existing EA layer over an existing population. They keep the codes, geometry, counts and other columns they are given, and stop on an input that fails a check, naming its rows. A frame records its measure of size as mos, apart from the realized counts, and its strata as stratum, region by urban unless stratum names one or more columns to cross or gives a vector.
  • sim_frame_defects() makes a frame stale and incomplete, with one growth rate and share of omitted EAs for the whole frame, or a mean rate and a probability of omission for each EA. It ages the recorded mos, so a measure of size given to as_frame() stays the one that ages. sim_population() runs every step with its defaults.
  • population_truth() gives the totals, means, variances and household intraclass correlation of an outcome, by household domain. frame_truth() gives, by EA domain, the share of households and persons the frame misses, the truth over the full and the covered population, and the components a planner needs for EAs drawn in proportion to a measure of size (mos). They match svyplan::varcomp() for two- and three-stage designs. A quantity whose denominator is 0 is NA, with one warning that names the domains, and the others are kept.
  • Each step records its effective arguments and the package version, and describes a supplied boundary or raster by its CRS, extent, features and columns.

Data and vignettes

  • Example data for a window north of Yako, Burkina Faso (?yako), with a frame of 21 EAs, from open sources. The window is a block of whole cells of its population raster.
  • vignette("decoupage") builds pre-census enumeration areas from roads, buildings and a population raster, then takes a frame of EAs to PSUs, their order and segments. vignette("recipes") covers tasks a few calls solve, such as fetching inputs from Overture Maps, an agricultural area frame, a forest inventory, building a frame from a table of records, reconciling an edited frame, building a large area one admin unit at a time in mirai daemons and recording a run. It ends with what the package leaves to other tools.
  • The article “The same population, different frames”, on the package website, builds one population on the Yako window, cuts it into three frames of different EA sizes, plans a survey on each with svyplan, draws it with samplyr and estimates with survey, and compares estimates against the full and the covered population after selective omission.
  • The pkgdown site publishes llms.txt and a Markdown copy of each page, for reading by language models.