#!/usr/bin/env ruby # frozen_string_literal: true # The reference example of the plugin contract (see lib/maptool/plugins.rb): # read --south/--west/--north/--east, print a GeoJSON FeatureCollection to # stdout. Thin wrapper around lib/maptool/overpass_pois.rb, which already # did all the real work for the "rake overpass:pois" dev-time task this # plugin now sits alongside as a second way to run the same query. # Along the trip's route (--route= --corridor-km): # Overpass' around: with the route thinned to a vertex every half corridor. require_relative "../../lib/maptool/overpass_pois" require_relative "../../lib/maptool/corridor" args = ARGV.to_h { |arg| arg.sub(/\A--/, "").split("=", 2) } bbox = %w[south west north east].map { |key| Float(args.fetch(key)) } around = if args["route"] corridor = Float(args.fetch("corridor-km")) line = Maptool::Corridor.thin(JSON.parse(File.read(args["route"]))["coordinates"], [corridor / 2, 0.5].max) [corridor * 1000, line] end response = Maptool::OverpassPois.fetch(bbox, timeout: around ? 180 : 60, around: around) puts JSON.generate(Maptool::OverpassPois.to_geojson(response))