Skip to main content
Title changed, Content structured
Source Link
Taras
  • 34k
  • 4
  • 73
  • 148

Update points geometry in PostGIS databasewhile snapping them to nearest line

I have two tables in the PostGIS database - points and lines. And I want to update points geometry to snap them to line if they lay within a certain distance.

By now I managed to create a new table with snapped points which has only geometries. This works:

CREATE TABLE new_table AS
SELECT ST_ClosestPoint(lines.geom, points.geom) as snapped_point
FROM lines
INNER JOIN points on ST_Dwithin(lines.geom, points.geom, 5)
ORDER BY points.id;
CREATE TABLE new_table AS
SELECT ST_ClosestPoint(lines.geom, points.geom) as snapped_point
FROM lines
INNER JOIN points on ST_Dwithin(lines.geom, points.geom, 5)
ORDER BY points.id;

But what I really need is to update the existing table. So I try:

UPDATE points
SET geom =  
(SELECT ST_ClosestPoint(lines.geom, points.geom) as snapped_point
FROM lines
INNER JOIN points on ST_Dwithin(lines.geom, points.geom, 5)
ORDER BY points.id);
UPDATE points
SET geom =  
(SELECT ST_ClosestPoint(lines.geom, points.geom) as snapped_point
FROM lines
INNER JOIN points on ST_Dwithin(lines.geom, points.geom, 5)
ORDER BY points.id);

And it never worksdid not work. How do I put these two pieces together?

Update points geometry in PostGIS database snapping them to nearest line

I have two tables in the PostGIS database - points and lines. And I want to update points geometry to snap them to line if they lay within a certain distance.

By now I managed to create a new table with snapped points which has only geometries. This works:

CREATE TABLE new_table AS
SELECT ST_ClosestPoint(lines.geom, points.geom) as snapped_point
FROM lines
INNER JOIN points on ST_Dwithin(lines.geom, points.geom, 5)
ORDER BY points.id;

But what I really need is to update the existing table. So I try:

UPDATE points
SET geom =  
(SELECT ST_ClosestPoint(lines.geom, points.geom) as snapped_point
FROM lines
INNER JOIN points on ST_Dwithin(lines.geom, points.geom, 5)
ORDER BY points.id);

And it never works. How do I put these two pieces together?

Update points geometry while snapping them to nearest line

I have two tables in the PostGIS database - points and lines. And I want to update points geometry to snap them to line if they lay within a certain distance.

By now I managed to create a new table with snapped points which has only geometries. This works:

CREATE TABLE new_table AS
SELECT ST_ClosestPoint(lines.geom, points.geom) as snapped_point
FROM lines
INNER JOIN points on ST_Dwithin(lines.geom, points.geom, 5)
ORDER BY points.id;

But what I really need is to update the existing table. So I try:

UPDATE points
SET geom =  
(SELECT ST_ClosestPoint(lines.geom, points.geom) as snapped_point
FROM lines
INNER JOIN points on ST_Dwithin(lines.geom, points.geom, 5)
ORDER BY points.id);

And it did not work. How do I put these two pieces together?

Tweeted twitter.com/StackGIS/status/1273088218200711168
Became Hot Network Question
naming; removed helpme
Source Link
Vince
  • 20.3k
  • 16
  • 48
  • 65

Update points geometry in postgisPostGIS database snapping them to nearest line

I have two tables in the postgisPostGIS database - points and lines. And I want to update points geometry to snap them to line if they lay within a certain distance.

By now I managed to create a new table with snapped points which has only geometries. This works:

CREATE TABLE new_table AS
SELECT ST_ClosestPoint(lines.geom, points.geom) as snapped_point
FROM lines
INNER JOIN points on ST_Dwithin(lines.geom, points.geom, 5)
ORDER BY points.id;

But what I really need is to update the existing table. So I try:

UPDATE points
SET geom =  
(SELECT ST_ClosestPoint(lines.geom, points.geom) as snapped_point
FROM lines
INNER JOIN points on ST_Dwithin(lines.geom, points.geom, 5)
ORDER BY points.id);

And it never works. Please, help me toHow do I put these two pieces together.?

Update points geometry in postgis database snapping them to nearest line

I have two tables in the postgis database - points and lines. And I want to update points geometry to snap them to line if they lay within a certain distance.

By now I managed to create a new table with snapped points which has only geometries. This works:

CREATE TABLE new_table AS
SELECT ST_ClosestPoint(lines.geom, points.geom) as snapped_point
FROM lines
INNER JOIN points on ST_Dwithin(lines.geom, points.geom, 5)
ORDER BY points.id;

But what I really need is to update the existing table. So I try:

UPDATE points
SET geom =  
(SELECT ST_ClosestPoint(lines.geom, points.geom) as snapped_point
FROM lines
INNER JOIN points on ST_Dwithin(lines.geom, points.geom, 5)
ORDER BY points.id);

And it never works. Please, help me to put these two pieces together.

Update points geometry in PostGIS database snapping them to nearest line

I have two tables in the PostGIS database - points and lines. And I want to update points geometry to snap them to line if they lay within a certain distance.

By now I managed to create a new table with snapped points which has only geometries. This works:

CREATE TABLE new_table AS
SELECT ST_ClosestPoint(lines.geom, points.geom) as snapped_point
FROM lines
INNER JOIN points on ST_Dwithin(lines.geom, points.geom, 5)
ORDER BY points.id;

But what I really need is to update the existing table. So I try:

UPDATE points
SET geom =  
(SELECT ST_ClosestPoint(lines.geom, points.geom) as snapped_point
FROM lines
INNER JOIN points on ST_Dwithin(lines.geom, points.geom, 5)
ORDER BY points.id);

And it never works. How do I put these two pieces together?

edited tags
Link
geozelot
  • 30.9k
  • 4
  • 34
  • 57
edited title
Link
MrXsquared
  • 35.6k
  • 22
  • 71
  • 121
Loading
Source Link
Loading