Replies: 4 comments 1 reply
-
Hi, the order of the elements, for the For example: WITH ways AS (
SELECT
osm_id AS way_id,
generate_subscripts(refs, 1) AS idx,
refs
FROM raw_way_tmp),
unnested_ways AS (
SELECT
way_id,
idx,
refs[idx] AS node_id
FROM ways),
distinct_nodes AS (
SELECT DISTINCT
osm_id AS node_id,
geometry
FROM raw_node_tmp),
ways_nodes AS (
SELECT
w.way_id AS way_id,
w.idx AS idx,
n.geometry AS geometry
FROM unnested_ways AS w
LEFT JOIN distinct_nodes AS n
USING (node_id)),
linestrings AS (
SELECT
way_id,
ST_MakeLine(geometry ORDER BY idx) AS geometry
FROM ways_nodes
GROUP BY way_id)
SELECT
way_id,
ST_AsText(geometry) AS wkt,
ST_IsClosed(geometry) AS is_closed,
ST_IsSimple(geometry) AS is_simple
FROM linestrings
LIMIT 10; It is more like a proof of concept: It returns:
|
Beta Was this translation helpful? Give feedback.
-
@emi420 it seems you wanna do this on the database level, I would suggest ST_MakePolygon to create a Polygon from an open LineString, using ST_StartPoint and ST_AddPoint to close it. |
Beta Was this translation helpful? Give feedback.
-
This is how osm2pgsql does it , It should solve the issue !
|
Beta Was this translation helpful? Give feedback.
-
Finally, I opted for storing and keeping updated geometries for ways also, not only for nodes, so the query is so much easy now. Thank you all for your contributions! |
Beta Was this translation helpful? Give feedback.
-
Do you have good Postgres skills? we need your help :)
Underpass can keep a local copy of the OSM database. For rendering OSM data on a UI, we need to query a boundary box and return a GeoJSON with the ways polygons as features.
Data
It looks something like the following.
Ways
Nodes
Query
I'm experimenting with this query:
It works as the following:
Problem
Refs order is not being kept, resulting in broken polygons:
We need to find a way to keep the order of the refs, but I'm not an Postgres expert at all :) could you help? it will be much appreciated!
For making things easier, I've created a test that includes sample data and the query, returning a GeoJSON that you can render in https://geojson.io or whatever you want use.
wayrefs-nodes-geojson.zip
You can make it work just editing the
CONN_STRING
variable for connecting it to a Postgres database, with the PostGIS installed on.Thank you!
Beta Was this translation helpful? Give feedback.
All reactions