PostGIS Spatial Database Engine UMN Mapserver Boston Geographic Information Systems    Checkout our PostGIS in Action book.  First chapter is a free download   PostGreSQL Object Relational Database Management System
GIS Books  Home   Consulting Services  About Boston GIS   Boston GIS Blog  Postgres OnLine Journal
PostGIS in Action is out in hard-copy,
download the first chapter
and SQL Primer for free. Tips and Tricks for PostGIS
  GIS Article comments Comments Rss
PostGIS MakePoint

Creating Point Geometries with ST_MakePoint

There are numerous ways of creating point geometries in PostGIS. We have covered these ways in other snippets. Check out the fulling links for other examples.

ST_MakePoint is perhaps in terms of speed the fastest way of creating a PostGIS geometry and on tests I have done, can be as much as 5 to 10 times faster. The downside of MakePoint is that it is not defined in the OGC spec so its not quite as portable across other spatial databases as is ST_GeomFromText and PointFromText.

ST_MakePoint is used in the form MakePoint(x, y) which for pretty much all spatial reference systems means ST_MakePoint(longitude, latitude)

Transformable (Reprojectable) and Non-Transformable Geometries

MakePoint used alone creates a nontransformable geometry (one that has an SRID = -1, so because of that, MakePoint is usually used in conjunction with SetSRID to create a point geometry with spatial reference information. Examples below and the EWKT output to demonstrate the differences.

Example below can not be used in a transformation to transform to another Spatial Reference System

SELECT ST_MakePoint(-71.09405383923, 42.3151215523721) as the_point, AsEWKT(ST_MakePoint(-71.09405383923, 42.3151215523721)) as ewkt_rep Note - the ewkt_rep output looks exactly like the WKT output - e.g. no spatial reference information so can not be passed into a transformation call - POINT(-71.09405383923 42.3151215523721)

Emparting Spatial Information to MakePoint Geometry

SELECT SETSRID(ST_MakePoint(-71.09405383923, 42.3151215523721),4326) as the_point, ST_AsEWKT(ST_SetSRID(ST_MakePoint(-71.09405383923, 42.3151215523721),4326)) as ewkt_rep
Note - the ewkt_rep output looks like the regular WKT output but has extra information about the spatial refence system the point is defined in SRID=4326;POINT(-71.09405383923 42.3151215523721)

Post Comments About PostGIS MakePoint

7/15/2012 1:46:42 AMandresCREATE OR REPLACE FUNCTION _mkpunto(nrow integer, ncol integer, xsize double precision, ysize double precision, x0 double precision DEFAULT 1000000, y0 double precision DEFAULT 1000000)
SELECT (ST_Translate(cell, j * $3 + $5, i * $4 + $6))
FROM generate_series(0, $1 - 1) AS i,
generate_series(0, $2 - 1) AS j,
SELECT (ST_MakePoint(0,0))::geometry AS cell
) AS foo;
COST 100
ROWS 1000;

This Document is available under the GNU Free Documentation License 1.2 & for download at the BostonGIS site

Boston GIS      Copyright 2017      Paragon Corporation