Module: OvertureMaps::Changelog

Defined in:
lib/overture_maps/changelog.rb

Overview

Overture's per-release data changelog: parquet partitioned by theme, type, and change_type (added | removed | data_changed | unchanged), with each row carrying the feature id and its bbox. The changelog for release R describes changes relative to the release before R.

Constant Summary collapse

CHANGE_TYPES =
%w[added removed data_changed unchanged].freeze

Class Method Summary collapse

Class Method Details

.counts(theme:, type:, release:, bbox: nil) ⇒ Object

Per-change_type counts for a release/theme/type (for sync:status and dry runs). Returns e.g. => 123, "removed" => 4, ....



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/overture_maps/changelog.rb', line 22

def counts(theme:, type:, release:, bbox: nil)
  validate!(theme, type)
  source = source_glob(theme: theme, type: type, release: Releases.validate!(release),
                       change_type: "*")
  sql = +"SELECT change_type, count(*) AS n FROM read_parquet('#{source}', hive_partitioning=1)"
  params = []
  if bbox
    sql << " WHERE bbox.xmin <= ? AND bbox.xmax >= ? AND bbox.ymin <= ? AND bbox.ymax >= ?"
    params = bbox_params(bbox)
  end
  sql << " GROUP BY change_type"

  QueryEngine.instance.query(sql, params)
             .to_h { |row| [row["change_type"], Integer(row["n"])] }
end

.removed_ids(theme:, type:, release:, bbox: nil) ⇒ Object

IDs removed in release (relative to the prior release), optionally restricted to those whose bbox intersects the given area.



14
15
16
17
18
# File 'lib/overture_maps/changelog.rb', line 14

def removed_ids(theme:, type:, release:, bbox: nil)
  sql, params = build_query(theme: theme, type: type, release: release,
                            change_type: "removed", bbox: bbox, select: "id")
  QueryEngine.instance.query(sql, params).map { |row| row["id"] }
end