GeoGenius.Providers.CSV (geo_genius v0.2.0)

Copy Markdown View Source

Provider for a single delimited-text artifact with a header row.

One data row becomes one staged row: payload is a map keyed by header name, every value a string, and geom is a %Geo.Point{} built from lon_column/lat_column when both are configured and the row's cells for them are non-empty, or nil otherwise. A CSV source carries no polygons -- a collection of postal codes with centroids and no boundaries is a first-class catalog, not a degraded one. normalize/2 reads the code and names out of payload using the manifest's options, so the same module serves any collection whose columns name their code and display name differently.

required_options/0 requires "area_type" and "code_column". The remaining options keys are optional:

  • "name_column" -- defaults to "name".
  • "authority" -- defaults to the manifest's own authority, when it declares exactly one.
  • "lon_column" and "lat_column" -- both required together to build a centroid; neither alone.
  • "attribute_columns" -- a list; defaults to [].
  • "alias_columns" -- a list; defaults to [].
  • "code_columns" -- a list of %{"type" => ..., "column" => ...}; defaults to [].
  • "delimiter" -- one of ",", "\t", ";", "|"; defaults to ",".

See the option-vocabulary table in GeoGenius.Provider's moduledoc for how these correspond to GeoGenius.Providers.GeoJSON's own option keys.

Summary

Functions

Every artifact declared across the manifest's sources; a CSV collection's artifacts are all delimited text.

Asserts an edge from each area the row implies to the row's own area.

Reads the code and names out of the staged row's payload, using the manifest's options.

CSV areas carry no hierarchy of their own; relations are always rebuilt.

Requires area_type and code_column in the manifest's options.

Reads path as delimited text and emits its data rows in chunks of 1000 rows.

Validates the manifest's implied_areas entries, whose code key is code_column.

Functions

artifacts(manifest)

Every artifact declared across the manifest's sources; a CSV collection's artifacts are all delimited text.

asserted_relations(manifest, row)

@spec asserted_relations(GeoGenius.Manifest.t(), GeoGenius.Staging.Row.t()) :: [
  {String.t(), String.t(), String.t()}
]

Asserts an edge from each area the row implies to the row's own area.

normalize(manifest, row)

@spec normalize(GeoGenius.Manifest.t(), GeoGenius.Staging.Row.t()) ::
  {:ok, GeoGenius.Provider.Area.t()}
  | {:ok, [GeoGenius.Provider.Area.t()]}
  | :skip
  | {:error, String.t()}

Reads the code and names out of the staged row's payload, using the manifest's options.

relations(manifest)

@spec relations(GeoGenius.Manifest.t()) :: :rebuild

CSV areas carry no hierarchy of their own; relations are always rebuilt.

required_options()

@spec required_options() :: [String.t()]

Requires area_type and code_column in the manifest's options.

stage(manifest, artifact, path, emit, opts)

Reads path as delimited text and emits its data rows in chunks of 1000 rows.

validate_options(options)

@spec validate_options(map()) :: :ok | {:error, String.t()}

Validates the manifest's implied_areas entries, whose code key is code_column.