Skip to content

Instantly share code, notes, and snippets.

@jczaplew
Created February 4, 2014 19:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jczaplew/8810346 to your computer and use it in GitHub Desktop.
Save jczaplew/8810346 to your computer and use it in GitHub Desktop.
PostGIS to MySQL

Postgres:

psql

   CREATE DATABASE federal lands; 
   \c federal lands;
   CREATE EXTENSION postgis;
   CREATE EXTENSION postgis_topology;

shell

shp2pgsql -s 4326 fedlanp020.shp | psql -h localhost -U john -d federal_lands

psql or pgAdmin SQL window

    ALTER TABLE fedlanp020 ADD COLUMN wkt TEXT;
    UPDATE fedlanp020 SET wkt = ST_AsText(geom);

    ALTER TABLE fedlanp020 DROP COLUMN feature2;
    ALTER TABLE fedlanp020 DROP COLUMN feature3;
    ALTER TABLE fedlanp020 DROP COLUMN state;
    ALTER TABLE fedlanp020 DROP COLUMN fedlanp020;
    ALTER TABLE fedlanp020 DROP COLUMN geom;

    COPY fedlanp020 TO '/path/to/where/you/want/the/file/federal_lands.csv' DELIMITER ',' CSV HEADER;

##MySQL:

  CREATE TABLE federal_lands (gid INT, feature1 VARCHAR(80), agbur VARCHAR(7), name1 VARCHAR(80), wkt TEXT);

  load data local infile '/path/to/where/you/want/the/file/federal_lands.csv' into table federal_lands fields terminated by ',' enclosed by '"' lines terminated by '\n' (gid, feature1, agbur, name1, wkt);

  ALTER TABLE federal_lands ADD geom GEOMETRY;
  UPDATE federal_lands SET geom = GeomFromText(wkt);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment