Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update documentation to include instructions for spatial indexing of points in srid 3857 #82

Open
chriszrc opened this issue Apr 13, 2022 · 1 comment

Comments

@chriszrc
Copy link
Contributor

chriszrc commented Apr 13, 2022

Given that all the point intersection queries are executed with srid of 3857:

SELECT
${geometry} AS center,
1 AS size,
0 AS clusterNo,
${maxZoomLevel + 1} AS expansionZoom${attributes}
FROM ${table}
WHERE
ST_Intersects(TileBBox(${z}, ${x}, ${y}, 3857), ST_Transform(${geometry}, 3857))
${query.length > 0 ? `AND ${query.join(' AND ')}` : ''}

A standard spatial index on the point geometry column won't be used (unless maybe the points are stored in 3857, but most I suspect are probably 4326). However regardless of srid on the geometry column, we can always add an expression (functional) index:

CREATE INDEX mytable_geom_3857_idx on mytable USING gist (ST_Transform(geom, 3857));

Which will of course speed up ST_INTERSECTS queries for all the tile requests.

PS - Was https://github.com/datalanche/node-pg-format or similar considered to more safely create parameterized queries?

@cosmin-petrescu
Copy link

Hello @chriszrc . Do you want to create a PR for this issue. We are more than happy to review it and merge it.

@cosmin-petrescu cosmin-petrescu added help wanted Extra attention is needed and removed help wanted Extra attention is needed labels Apr 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants