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:

Binary Installers

Binary distributions of PostGIS are available for various operating systems.

Windows

OSX

Red Hat / Centos / Scientific Linux

Ubuntu / Debian

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
); 
gipoco.com is neither affiliated with the authors of this page nor responsible for its contents. This is a safe-cache copy of the original web site.