0

I am wanting to use a GEOMETRY point and radius value that I pull from a postgis table. It looks like this:

CREATE TABLE waypoint (
  name          VARCHAR(30),
  location      GEOMETRY(Point, 3857),
  radius        INTEGER,
);

-- Update SRID to WGS84 (World Geodetic System 1984) - Standard for most calcluations worldwide
SELECT UpdateGEometrySRID('waypoint', 'location', 3857);

INSERT INTO
    waypoint (name, location, radius)
SELECT
    'Waypoiint 1', 'SRID=3857; POINT(-27.0 153.0)', 50;

So once I get the location and radius values in my javascript I wish to use it to display a circle on a map.

       WPcircle = L.circleMarker(location, radius).addTo(mymap)

but that gives an error because location is invalid format. It is type GEOMETRY not latlng.

I want to do the equivalent of ST_AsText(location) in javascript. Can I?

Is there an easy (or any?) way to convert it in javascript?

PPrime
  • 47
  • 8

2 Answers2

1

I think it is a bad idea to try and handle the WKB or WKT formats on a geometry in Javascript.

Use the ST_X and ST_Y functions to get the coordinates of a point in the SQL query.

Laurenz Albe
  • 209,280
  • 17
  • 206
  • 263
0

If you want to draw a buffer (circle) on your map you should use ST_Buffer. This should return a geometry with a circle from a given geometry and radius, so that you do not need to compute it in the client:

SELECT ST_Buffer(location,radius) FROM waypoint;

Further reading: Circles/Buffers in PostGIS

Jim Jones
  • 18,404
  • 3
  • 35
  • 44