girs.feat.proc.dissolve

dissolve(source, **kwargs)

Dissolve features in a layers set.

Features are dissolved according to the parameter fields. Remaining fields are defined by the parameter stats. Both parameters fields and stats are appended by the layer number. Examples:

lrs1 = LayersReader(shp1())
# Dissolved by field 'NAME_3', no remaining field
lrs2 = lrs1.dissolve(fields0='NAME_3')
# Dissolved by field 'NAME_3', no remaining field, saved to file
lrs2 = lrs1.dissolve(target='D/tmp/diss.shp', fields0='NAME_3')
# Dissolved by field 'NAME_3', remaining field 'NAME_2' with statistics 'last'
lrs2 = lrs1.dissolve(fields0='NAME_3', stats0=[('NAME_2', 'last')])

The following statistics are possible: first, last, count, min, max, sum, mean, range, and std

Parameters:
  • source – LayersSet or filename of a LayersSet
  • kwargs
    key cpus:number of cpus to be used (default 1). Hint. cpus <= total number of cpus - 1
    key target:dataset source. Default is ‘’ (memory). Examples: target=’‘, target=’D:tmp/output.shp’
    key drivername:driver short name. Example: drivername=’GML’
    key as_collection:
     if True return geometries as collections (MULTIPOINT, MULTIPOLYGON, etc.)
    key fields:dictionary with layer number as key and a list of field names
    key stats:dictionary with layer number as key and a list of statistics [(field name, stats, output field name)].

    If the list is defined, field name and stats are obligatory. The resulting output field name will be field name

    Examples:

    • {0: [(‘NAME3’, ‘count’)]}: results in a count of field ‘NAME3’ saved under ‘NAME3’
    • {0: [(‘NAME3’, ‘count’, ‘NAME3COUNT’)]}: count of field ‘NAME3’ saved under ‘NAME3COUNT’
    • {0: [(‘NAME3’, ‘count’, True)]}: count of field ‘NAME3’ saved under ‘NAME3_COUNT’. The stats name is appended to the field name preceded by underline.
    • {0: [(‘NAME3’, ‘first’)], [(‘AREA’, ‘sum’, ‘AREAkm2)]}: results in a count of field ‘NAME3’ saved under ‘NAME3’ and summed area of the field ‘AREA’ saved under ‘AREAAREAkm2’
Returns:

LayersWriter

Return type:

LayersWriter