Increase Points in a LineString in PostGIS
I have a local setup playing with OpenStreetMap (OSM) data. Specifically, I load in a bunch of highways with osm2pgsql and then in a later step dump the points making up each highway into a table of nodes. These nodes are a 1:1 mapping with the nodes as you can see making up a way in the original OSM data. However, I wanted more nodes without changing the shape of the highway. Meaning, the nodes should just appear along straight stretches.
In the original SQL call, I do something like
SELECT
way_id,
ST_DumpPoints (geom) AS pt
FROM
highways;
Here geom
is a column in the highways
table holding the PostGIS LineString
geometry. ST_DumpPoints
gives you the points making up the
LineString. The result of this is used to fill up my table of nodes.
To increase the number of nodes, I ended up using
ST_Segmentize
. This takes your geometry and returns one where
no segment is longer than the segment length you pass to the call. A segment in
the case of a LineString is a section between two nodes (Points).
SELECT
way_id,
ST_DumpPoints (ST_Segmentize (geom, 50)) AS pt
FROM
highways;
The 50 here is in the unit/projection you are using. For me this should be metre.
Also worth noting is how this changed the number of nodes in my database. Beforehand a dump of Belgium and Pennsylvania had 10,389,975 nodes. After the change, there were 15,600,530 nodes.
Via GIS StackExchange and the PostGIS mailing list.