Compiling from Source
PostGIS has many packaged installations, but if you are more adventurous
and want to compile your own, refer to our source download and compilation
instructions:
- Source Download and Compile Instructions
Binary Installers
Binary distributions of PostGIS are available for various operating systems.
Windows
- More details about getting up and running with windows can be found on Windows Downloads page.
OSX
- The most reliable way to get PostGIS on OSX is to download and install Postgres.app. Great for development and testing. Do not mix with other installations.
- The builds from KingChaos are sometimes more up-to-date. Read the instructions carefully. Do not mix with other installations.
- The OSX PostgreSQL/Stackbuilder combination from EnterpriseDB has had mixed reliability. Avoid.
- Instructions for MacPorts and HomeBrew would be welcome contributions.
Red Hat / Centos / Scientific Linux
- The best place to get the latest binaries for both PostgreSQL and PostGIS is the PostgreSQL Yum repository
- Choose the correct “repository RPM” for your distribution, download and install it.
- Edit the yum configuration to exclude the base system PostgreSQL packages from yum (see the “Important note” section).
- Remove any existing PostgreSQL server packages from your system, with
rpm -e postgresql-server
.
- Install PostGIS and dependencies by running
yum install postgis2
.
Ubuntu / Debian
- The PostgreSQL build team is working on an APT repository for PostgreSQL builds. They may include PostGIS builds in the future.
- The DebianGIS project has built PostGIS in the past, but is currently not very up-to-date.
Getting Started
These instructions are for PostgreSQL 9.1 and higher, PostGIS 2.0 and higher.
Enabling PostGIS
PostGIS is an optional extension that must be enabled in your database before you can use it. Installing the software is just the first step.
Connect to your database with psql
or PgAdmin. Run the following SQL:
-- Enable PostGIS (includes raster)
CREATE EXTENSION postgis;
Spatial SQL
See the documentation for more guidance.
-- Create table with spatial column
CREATE TABLE mytable (
id SERIAL PRIMARY KEY,
geom GEOMETRY(Point, 26910),
name VARCHAR(128)
);
-- Add a spatial index
CREATE INDEX mytable_gix
ON mytable
USING GIST (geom);
-- Add a point
INSERT INTO mytable (geom) VALUES (
ST_GeomFromText('POINT(0 0)', 26910)
);
-- Query for nearby points
SELECT id, name
FROM mytable
WHERE ST_DWithin(
geom,
ST_GeomFromText('POINT(0 0)', 26910)),
1000
);