npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@toriyama/osmql

v0.1.1

Published

Easy access to OSM's gold mine of information.

Downloads

5

Readme

osmQL

Easy access to OSM's gold mine of information.

Abstract

JavaScript で Overpass API にアクセスするためのライブラリです。 Overpass QL を記述したファイルを読み込んで実行する機能だけでなく、ユーティリティを用いてクエリを作成する機能もあります。 かんたんなクエリの実行に便利であるほか、クエリ言語にあまり親しみがないユーザーでもかんたんに Overpass API に触れることができます。

Installation

npm install @toriyama/osmql

Usage

大きく分けて 2 つの使い方があります。

  • 手書きの OverpassQL を実行する
  • QueryBuilderを用いてクエリを作成し実行する

手書きの OverpassQL を実行する

クラスOSMQueryをインポートしたらまずインスタンスを作成してください。

import { OSMQuery } from "@toriyama/osmql";
const osmQuery = new OSMQuery(options);

optionsには次のオプションを指定できます。

| オプション | デフォルト値 | 説明 | | ---------- | --------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------- | | endPoint | https://overpass-api.de/api/interpreter | Overpass API を提供しているサーバーの URL を指定します。 | | bbox | undefined | 東西南北の緯度経度を指定し検索結果を絞り込みます。 例) { south: 35.0, west: 135.73, north: 35.05, east: 135.79 } | | timeout | 180 | 処理時間が指定した秒数以上になる場合処理を中断します。 | | maxsize | 536870912 | 処理に用いられる一時メモリの上限サイズを指定できます。 | | date | undefined | 指定した日時以前のデータから検索します。日時はISO 8601形式で記述します。例) 2021-11-20T21:00:00Z |

クエリ文字列を実行する

fromQLStringメソッドを利用します。

const osmQuery = new OSMQuery();
const query = osmQuery.fromQLString(
	"node(35.0, 135.73, 35.05, 135.79)['name' ~ '郵便局$'];out;"
);
query.execute().then((result) => {
	const geojson = result.toGeoJSON();
	console.log(geojson);
});
{
  type: 'FeatureCollection',
  features: [
    {
      type: 'Feature',
      id: 'node/796933156',
      properties: [Object],
      geometry: [Object]
    },
    {
      type: 'Feature',
      id: 'node/1422960082',
      properties: [Object],
      geometry: [Object]
    },
    ...
  ]
}

ファイルからクエリを読み込んで実行

fromQLFileメソッドを用います。

// sample.ql
node
	(35.0, 135.73, 35.05, 135.79)
	['name' ~ '郵便局$'];
out;
const osmQuery = new OSMQuery();
const query = osmQuery.fromQLFile("./sample.ql");
query.execute().then((result) => {
	const geojson = result.toGeoJSON();
	console.log(geojson);
});

QueryBuilderを用いてクエリを作成し実行する(experimental)

OSMQuery.queryBuilder()を用いると OverpassQL が書けなくてもかんたんなクエリを作成し実行することができます。

image

京都の市街地にある郵便局の一覧を取得する次のクエリをQueryBuilderを使って実行してみましょう。

node
	(35.0, 135.73, 35.05, 135.79)
	['name' ~ '郵便局$'];
out;
const query = OSMQuery.queryBuilder({
	category: "node",
});
query.setBounding({
	south: 35.0,
	west: 135.73,
	north: 35.05,
	east: 135.79,
});
query.filterBy("name")(/郵便局$/);
OSMQuery.get(query).then((result) => {
	console.log(result.toGeoJSON());
});

Contribution

追加して欲しい機能などがあれば Issue からお気軽にお申し付けください!

Todo

  • [ ] ブラウザでも実行できるようにする
  • [ ] 詳細なドキュメントを作成
  • [ ] 複雑なクエリも QueryBuilder を使って生成できるようにする

Author

Torichan (@CoconMap)