Reputation: 2318
I have a simple postgres database with 4-5 columns including one latitude and one longitude column. I want to have an additional postGIS point column, but are at loss how I construct this new column using the two excisting latitude and longitude columns.
Table1
a | b | c | latitude | longitude | location(point column)
Upvotes: 0
Views: 2637
Reputation: 2318
And I found the answer myself. First of all, my latitude and longitude columns was varchar, so I had to convert them to use the ST_Makepoint function. Note that I use WSG4326 coordinates in this code, change accordingly.
ALTER TABLE table1 ADD COLUMN location GEOMETRY(point, 4326);
UPDATE table1 SET location = ST_SETSRID(ST_MakePoint(cast(longitude as float), cast(latitude as float)),4326);
Upvotes: 3