PostGIS Points – Disperse Points with Same Coordinates Within a Radius Using PostGIS

pointpostgispostgresql

I had located on my table I have sets of points sharing the same coordinates and they are clustering, is there a way to regenerate their geoms so they get dispersed or redistributed within a certain radius using PostGIS and PostgreSQL?


The data I count with is the lat/long and geom of the points and I just need them to be a couple meters away from each other, I need to work it out in the database, not using external tools such as Arcgis Pro or Qgis.

Best Answer

This creates a new POINT at random from <points> within the given <radius> around the given input <points>.geom (POINT):

SELECT ST_MakePoint(
         ST_X(geom) + rad*SIND(ang),
         ST_Y(geom) + rad*COSD(ang)
       ) AS geom
FROM   (
    SELECT random() * 360.0 AS ang,
           random() * <radius> AS rad,
           geom
    FROM   <points>
) q