- Install Postgres.app
- Add
/Applications/Postgres.app/Contents/Versions/9.4/bin
to your $PATH createdb mammals
psql -U you -d mammals -c 'CREATE EXTENSION postgis'
psql -U you -d mammals -c 'CREATE EXTENSION postgis_topology'
shp2pgsql -s 4326 -W "latin1" ~/Downloads/TERRESTRIAL_MAMMALS/TERRESTRIAL_MAMMALS.shp | psql -U you mammals
(this will take about a minute or two)psql -U you mammals
UPDATE terrestrial_mammals SET geom = ST_MakeValid(geom);
(Took about half an hour for me)CREATE TABLE grouped_families AS SELECT family_nam, ST_Union(geom) AS geom FROM terrestrial_mammals GROUP BY family_nam;
(takes ~ 30 seconds)VACUUM ANALYZE grouped_families;
CREATE TABLE grouped_species AS SELECT species_na, ST_Union(geom) AS geom FROM terrestrial_mammals GROUP BY species_na;
VACUUM ANALYZE grouped_species;
--create index sIndex on terrestrial_mammals USING gist (geom); create index ON terrestrial_mammals (family_nam); create index on terrestrial_mammals (species_na); You can also install PGAdminIII to more easily view the data.
CREATE TABLE grouped_species (id integer, species text, geom geometry);
SELECT DISTINCT species_na FROM terrestrial_mammals;
For each in result...
INSERT INTO grouped_species (select species_na, ST_Union(geom) from terrestrial_mammals where species_na =
each GROUP BY species_na)`