I have a normal postgres database with lots of geo coded data. This is just present two columns as latitude and longitude.
I want to convert this database to PostGIs database. Can anyone suggest me a way to convert the database i have? I don't want to create a new postgis tempalte based database and then move the whole data one by one.
First, make sure PostGIS is installed on the system, then create a PostGIS extension for the database using:
CREATE EXTENSION postgis;
Next, spatially enable each table with a geometry column and populate the column with the long/lat data points:
ALTER TABLE mytable ADD COLUMN geom geometry(Point,4326);
UPDATE mytable SET geom = ST_SetSRID(ST_MakePoint(long, lat), 4326);
Also consider using the geography type:
ALTER TABLE mytable ADD COLUMN geog geography(Point,4326);
UPDATE mytable SET geog = ST_MakePoint(long, lat)::geography;
I know this is older... but I'd add something to address a previous issue:
@Cerin, make sure you apt-get install postgresql-x.x-postgis-2.1, not just apt-get install postgis. I had that issue before as well
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With