PostgreSQL : How to do research using geolocation in PostgreSQL?

Use PostGIS for do this. You can with PostGIS consult by geographic coordinates using as latitude and longitude, or even through an IP. You can solve issues such as what are the nearest locations of me or what is the shortest distance between two points with these functions.

Examples of queries that can be performed using these functions:

– Distance calculation using GEOGRAPHY (122.2km)
SELECT ST_Distance (‘LINESTRING (-122.33 47,606 0.0 51.5)’ :: geography, ‘POINT (64.15 -21.96)’ :: geography);

– Distance calculation using GEOMETRY (13.3 “degrees”)
SELECT ST_Distance (‘LINESTRING (-122.33 47,606 0.0 51.5)’ :: geometry, ‘POINT (64.15 -21.96)’ :: geometry);

What is PostGIS?

PostGIS is a spatial database extender for PostgreSQL object-relational database. It adds support for geographic objects Allowing location queries to be run in SQL.

How to use?

You must have PostgreSQL installed and you need download and install the PostGIS.

You can see the steps to be performed according to your operating system:

http://postgis.net/install

+ More Infos :

Oficial WebSite : http://postgis.net/

Documentantion : http://postgis.net/docs/manual-2.1/using_postgis_dbmanagement.html#Geography_Basics

Good example using with IP locations : http://tapoueh.org/blog/2013/10/09-ip4r

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s