My question is similar to Creating geometry from lat/lon in table using PostGIS? , but I need to convert set or array of LON & LAT in PostgreSQL into geometry value.
For example, I can convert single LON & LAT to geometry point using below code (using PostgreSQL command) :
SET geometry = ST_GeomFromText('POINT(' || lon || ' ' || lat || ')',4326);
What if I have array of LON & LAT like this lon1,lon2,lon3,lat1,lat2,lat3
and I want to combine those coordinates to geometry values which will produce a long polygon shape instead of a single point shape?
Best Answer
It's a little nasty to store coordinates that way...
However, more importantly, creating actual Polygons from points require some pre-conditions to be met:
Assuming that your arrays fulfill these conditions, running
will create Polygons with a given
<SRID>
in column<geom>
from your<array>
column. If you'd rather want LineStrings, remove the wrappingST_MakePolygon()
from the query.If your arrays do not meet these requirements, please edit and update your question with details.