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 🙏

© 2025 – Pkg Stats / Ryan Hefner

pelias-spatial

v1.6.0

Published

Pelias Spatial Service

Downloads

3,389

Readme

Pelias Spatial Service

Lightweight spatial service used by Pelias — provides point-in-polygon (PIP) lookups, geometry, relationships and ontology data via a small HTTP API and demo pages.

HTTP endpoints

All endpoints are GET endpoints unless noted. See server/routes/* for parameter details and exact output shape.

  • GET /place/:source/:id Return place metadata by source and id.

  • GET /place/:source/:id/geometry Return all geometry roles for the place.

  • GET /place/:source/:id/geometry/:role Return geometry for a specific role (e.g. intersection, shape, etc.).

  • GET /place/:source/:id/relationship/intersects Return places that intersect the given place.

  • GET /place/:source/:id/relationship/contains Return places that contain the given place.

  • GET /place/:source/:id/relationship/within Return places within the given place.

  • GET /place/:source/:id/property Return properties for the place.

  • GET /place/:source/:id/name Return names for the place.

  • GET /place/:source/:id/hierarchy Return the administrative hierarchy for the place.

  • GET /query/pip Point-in-polygon lookup (compact view). Query parameters are handled by the pip route implementation in server/routes/pip.js.

  • GET /query/pip/verbose Point-in-polygon lookup (verbose view), returns detailed match records.

  • GET /query/pip/_view/pelias/:lon/:lat Pelias-compatible PIP view (legacy Pelias format).

    • Path params: lon, lat
    • Query params: layers (comma-separated list) is supported by the Pelias view implementation and filters the output layers. See server/routes/pip_pelias.js for details.
  • GET /query/search General spatial search endpoint (see server/routes/search.js for supported query parameters).

  • GET /ontology Return top-level ontology index.

  • GET /ontology/:class Return ontology entries for a class.

  • GET /ontology/:class/:type Return ontology entries for a class/type pair.

Demo pages and utilities:

  • GET /explore (static demo UI at server/demo)
  • GET /explore/place/:source/:id
  • GET /explore/pip
  • GET /explore/ontology
  • GET /explore/ontology/:class/:type

Root:

  • GET / redirects to /explore/pip

Examples

Pelias PIP view (Pelias-compatible response):

curl -s "http://localhost:3000/query/pip/_view/pelias/170.97/-45.09?layers=locality,region"

Simple place lookup:

curl -s "http://localhost:3000/place/whosonfirst/85633345"

Docker Development

# build image
docker build -t 'pelias/spatial' .
# run environment checks
docker run --rm -it \
  --entrypoint=npm \
  pelias/spatial \
  run env_check
# run tests
docker run --rm -it \
  --entrypoint=npm \
  pelias/spatial \
  test
# generate code coverage report
docker run --rm -it \
  --entrypoint=npm \
  pelias/spatial \
  run coverage
# create empty spatial database
docker run --rm -i \
  -v "${PWD}:/data" \
  pelias/spatial \
  import whosonfirst --db=/data/empty.db --file=/dev/null
# merge two databases
docker run --rm -i \
  -v "${PWD}:/data" \
  pelias/spatial \
  merge --db=/data/empty.db /data/external.db
# run whosonfirst import
# note: database sourced from https://dist.whosonfirst.org/sqlite/
ingress() {
  WOFDB='/data/wof/sqlite/whosonfirst-data-admin-nz-latest.db'
  EXTRACT_QUERY='SELECT json_extract(body, "$") FROM geojson'
  sqlite3 "${WOFDB}" "${EXTRACT_QUERY}"
}

ingress | docker run --rm -i \
  -v "${PWD}:/data" \
  pelias/spatial \
  import whosonfirst --db=/data/geo.docker.db
# run openstreetmap import
# note: data generated using https://docs.osmcode.org/osmium/latest/
ingress() {
  EXTRACT_FILE='osmium.extract.geojsonl.gz'
  gzcat "${EXTRACT_FILE}"
}

ingress | docker run --rm -i \
  -v "${PWD}:/data" \
  pelias/spatial \
  import osmium --db=/data/geo.docker.db
# start the HTTP server on port 3000
docker run --rm -it \
  -v "${PWD}:/data" \
  -p 3000:3000 \
  pelias/spatial \
  server --db=/data/geo.docker.db
# run point-in-polygon query
docker run --rm -i \
  -v "${PWD}:/data" \
  pelias/spatial \
  pip --db=/data/geo.docker.db 174.766843 -41.288788

Local Development

Install dependencies from homebrew (macos):

# install a modern version of nodejs
brew install node@23
brew link --overwrite node@23
brew postinstall node

# install sqlite3 and libspatialite
brew install sqlite3 libspatialite
# run environment checks
npm run env_check
# run tests
npm test
# generate code coverage report
npm run coverage
# create empty spatial database
node bin/spatial.js import whosonfirst --db=empty.db --file=/dev/null
# merge two databases
node bin/spatial.js merge --db=/data/empty.db /data/external.db
# run whosonfirst import
# note: database sourced from https://dist.whosonfirst.org/sqlite/
ingress() {
  WOFDB='/data/wof/sqlite/whosonfirst-data-admin-nz-latest.db'
  EXTRACT_QUERY='SELECT json_extract(body, "$") FROM geojson'
  sqlite3 "${WOFDB}" "${EXTRACT_QUERY}"
}

ingress | node bin/spatial.js --db=geo.local.db import whosonfirst
# run openstreetmap import
# note: data generated using https://docs.osmcode.org/osmium/latest/
ingress() {
  EXTRACT_FILE='osmium.extract.geojsonl.gz'
  gzcat "${EXTRACT_FILE}"
}

ingress | node bin/spatial.js --db=geo.local.db import osmium
# start the HTTP server on port 3000
node bin/spatial.js server --db=geo.local.db
# run point-in-polygon query
node bin/spatial.js --db=geo.local.db pip 174.766843 -41.288788

Performance Testing

For performance critial HTTP APIs we have two methods of load-testing:

K6

For some basic tests you can use k6 to write perf tests in javascript:

import http from 'k6/http'
const baseurl = 'http://localhost:3000/query/pip/_view/pelias'

function randomFloat(from, to, fixed) {
  return (Math.random() * (to - from) + from).toFixed(fixed) * 1
}

export default function() {
  let lon = randomFloat(-180, +180, 8)
  let lat = randomFloat(-90, +90, 8)
  http.get(`${baseurl}/${lon}/${lat}`)
}
k6 run --vus 20 --iterations 100000 test.js

Gatling

Jawg provide a suite of stress-testing tools for benchmarking various Pelias services.

These tools are powered by Gatling which can produce impressive visual charts and provide more information about where the bottlenecks are occurring (ie. disk congestion).

see https://github.com/pelias/spatial/issues/7 for examples