pelias / pelias/spatial

Support new API for pelias import / reverse Geocoding

Open
#129 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
JavaScript
Stars
32
Forks
8
Avg merge
13m
Merged PRs (30d)
1

Description

Use-cases

The pelias pip-service API is supported by spatial via the endpoint /query/pip/_view/pelias/:lon/:lat.

This API is quite old and I think we can create a better one. The current one is an object of places grouped by their placetype.

{
  "ocean": [
    {
      "id": 404528709,
      "name": "North Atlantic Ocean",
      "centroid": {
        "lat": 34.226813,
        "lon": -28.8395953
      },
      "bounding_box": "-81.520626,0.022273,6.557047,68.437167"
    }
  ]
}
Proposal

I'm suggesting a new API, a bit simpler that will return a list of places.

[
  {
    "id": 404528709,
    "name": "North Atlantic Ocean",
    "type": "ocean",
    "centroid": {
      "lat": 34.226813,
      "lon": -28.8395953
    },
    "bounding_box": "-81.520626,0.022273,6.557047,68.437167"
  }
]

Why a list instead of a map ? The complexity this adds at Spatial and pelias levels.

  1. The SQLite query returns an array list of places
  2. spatial/server/routes/pip_pelias.js#parseRows will remap the list into an object complexity: θ(N)
  3. spatial/server/routes/pip_pelias.js#remapFromHierarchy will do some stuff about hierarchy costing θ(3 * N + 2 * supported-layers)
  4. wof-admin-lookup/src/lookupStream.js#createPipResolverStream will set parent on θ(supported-layers)

The final complexity is θ(4 * N + 3 * supported-layers) for this pipeline

I think my idea is not compatible with the hierarchy feature, we might remove parseRows and make some changes in remapFromHierarchy, the complexity of createPipResolverStream will be θ(N) and the whole complexity could be θ(3 * N )

BTW, this piece of code can be expensive for debug purpose only 😅
https://github.com/pelias/wof-admin-lookup/blob/dde07e2774111184cf04d7187960283ef84ea695/src/lookupStream.js#L45-L50

How to change the API ? For importer / pelias API services.spatial.version=2 and /query/pip/_view/pelias/:lon/:lat?version=2 query param for Spatial API ?

References

https://github.com/pelias/wof-admin-lookup/pull/331#pullrequestreview-3284378548
https://github.com/pelias/wof-admin-lookup/pull/331#issuecomment-3351926238

cc @missinglink

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with server/routes/pip_pelias.js, especially parseRows and remapFromHierarchy, then read wof-admin-lookup/src/lookupStream.js at createPipResolverStream and the referenced debug section. Clarify how a versioned Spatial API should coexist with hierarchy handling and importer consumers; done means the agreed response shape and version behavior work across this pipeline.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
api, backend-api-design
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.