@classmethod<EOL><INDENT>def from_records(cls, records, dataset=None, on=None, value=None,<EOL>index=[], drop_missing=False, element=None, **kwargs):<DEDENT>
if dataset is not None and not on:<EOL><INDENT>raise ValueError('<STR_LIT>'<EOL>'<STR_LIT>')<EOL><DEDENT>if util.pd and isinstance(dataset, util.pd.DataFrame):<EOL><INDENT>dataset = Dataset(dataset)<EOL><DEDENT>if not isinstance(on, (dict, list)):<EOL><INDENT>on = [on]<EOL><DEDENT>if on and not isinstance(on, dict):<EOL><INDENT>on = {o: o for o in on}<EOL><DEDENT>if not isinstance(index, list):<EOL><INDENT>index = [index]<EOL><DEDENT>kdims = []<EOL>for ind in index:<EOL><INDENT>if dataset and dataset.get_dimension(ind):<EOL><INDENT>dim = dataset.get_dimension(ind)<EOL><DEDENT>else:<EOL><INDENT>dim = Dimension(ind)<EOL><DEDENT>kdims.append(dim)<EOL><DEDENT>ddims = []<EOL>if dataset:<EOL><INDENT>if value:<EOL><INDENT>vdims = [dataset.get_dimension(value)]<EOL><DEDENT>else:<EOL><INDENT>vdims = dataset.vdims<EOL><DEDENT>ddims = dataset.dimensions()<EOL>if None in vdims:<EOL><INDENT>raise ValueError('<STR_LIT>'<EOL>'<STR_LIT>' % (value, ddims) )<EOL><DEDENT><DEDENT>else:<EOL><INDENT>vdims = []<EOL><DEDENT>data = []<EOL>for i, rec in enumerate(records):<EOL><INDENT>geom = {}<EOL>if dataset:<EOL><INDENT>selection = {dim: rec.attributes.get(attr, None)<EOL>for attr, dim in on.items()}<EOL>row = dataset.select(**selection)<EOL>if len(row):<EOL><INDENT>values = {k: v[<NUM_LIT:0>] for k, v in row.iloc[<NUM_LIT:0>].columns().items()}<EOL><DEDENT>elif drop_missing:<EOL><INDENT>continue<EOL><DEDENT>else:<EOL><INDENT>values = {vd.name: np.nan for vd in vdims}<EOL><DEDENT>geom.update(values)<EOL><DEDENT>if index:<EOL><INDENT>for kdim in kdims:<EOL><INDENT>if kdim in ddims and len(row):<EOL><INDENT>k = row[kdim.name][<NUM_LIT:0>]<EOL><DEDENT>elif kdim.name in rec.attributes:<EOL><INDENT>k = rec.attributes[kdim.name]<EOL><DEDENT>else:<EOL><INDENT>k = None<EOL><DEDENT>geom[kdim.name] = k<EOL><DEDENT><DEDENT>geom['<STR_LIT>'] = rec.geometry<EOL>data.append(geom)<EOL><DEDENT>if element is not None:<EOL><INDENT>pass<EOL><DEDENT>elif data and data[<NUM_LIT:0>]:<EOL><INDENT>if isinstance(data[<NUM_LIT:0>]['<STR_LIT>'], poly_types):<EOL><INDENT>element = Polygons<EOL><DEDENT>else:<EOL><INDENT>element = Path<EOL><DEDENT><DEDENT>else:<EOL><INDENT>element = Polygons<EOL><DEDENT>return element(data, vdims=kdims+vdims, **kwargs).opts(color=value)<EOL>
Load data from a collection of `cartopy.io.shapereader.Record`
objects and optionally merge it with a dataset to assign
values to each polygon and form a chloropleth. Supplying just
records will return an NdOverlayof Shape Elements with a
numeric index. If a dataset is supplied, a mapping between the
attribute names in the records and the dimension names in the
dataset must be supplied. The values assigned to each shape
file can then be drawn from the dataset by supplying a
``value`` and keys the Shapes are indexed by specifying one or
index dimensions.

Parameters
----------
records: list of cartopy.io.shapereader.Record
   Iterator containing Records.
dataset: holoviews.Dataset
   Any HoloViews Dataset type.
on: str or list or dict
  A mapping between the attribute names in the records and the
  dimensions in the dataset.
value: str
  The value dimension in the dataset the values will be drawn
  from.
index: str or list
  One or more dimensions in the dataset the Shapes will be
  indexed by.
drop_missing: boolean
  Whether to drop shapes which are missing from the provides
  dataset.

Returns
-------
shapes: Polygons or Path object
  A Polygons or Path object containing the geometries