2

If I have a point

SELECT point(long,lat);

How do I go from that to a PostGIS point?

asked Dec 1, 2016 at 21:06
0

1 Answer 1

2

Update

This is no longer required there is now a native cast from gemoetry to native Point and vise-versa:

SELECT ST_MakePoint(0,0)::Point;
SELECT ST_AsText( Point(0,0)::geometry );

There is no implicit conversion or casting from a PostgreSQL native point type to a PostGIS geometry, and a PostGIS POINT has a Spatial Reference System attached to it. ST_MakePoint will create the point geometry, but it'll be apart from any system that maps it to Earth,

SELECT ST_MakePoint(p[0],p[1])
FROM ( VALUES (point(-71.1043443253471,42.3150676015829)) ) AS t(p);

We're accessing the point type with the array syntax,

It is possible to access the two component numbers of a point as though the point were an array with indexes 0 and 1. For example, if t.p is a point column then SELECT p[0] FROM t retrieves the X coordinate and UPDATE t SET p[1] = ... changes the Y coordinate. In the same way, a value of type box or lseg can be treated as an array of two point values.

answered Dec 1, 2016 at 21:06
1
  • you can wrap an ST_SetSRID around the ST_MakePoint and you'll have a proper coordinate system assigned to your geometry... Commented Jun 12, 2017 at 21:26

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.