spatial icon indicating copy to clipboard operation
spatial copied to clipboard

Support new API for pelias import / reverse Geocoding

Open Joxit opened this issue 2 months ago • 0 comments

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

Joxit avatar Oct 03 '25 18:10 Joxit