Geospatial Web/Service API Methods

Once the data is in the database, the web service methods can be created so that the data can be displayed on the map. Inside the methods, sql statements are created to get the parks data to be displayed on the map.

Some of the web service functionality built was:

Items Search Method

The Items Search Method based sql statement to get all the item information by a search query parameter. The item information is returned in geojson format.

PostGIS’s Nearest Neighbor Method

The basis for the PostGIS geographical type is a point. Given a geometry it aims to find the x number of nearest neighbors and n geometries of data. A  query with to find the nearest objects to a geometric value has the following clause, ORDER BY geometry_column <-> geometric value LIMIT k. <-> in the ORDER BY clause is a “distance” operator that when combined with ORDER BY clause and LIMIT k allows query to find the k nearest objects to a geometric value. We will focus on using a point, so geometric value = ST_MakePoint(double x , double y), where x is longitude and y is latitude.

Here is an example PostgreSQL query with ST_MakePoint method to get the k = 5 points nearest to the given point (-110.547348214819,44.5964236630063) in the database:

SELECT ST_AsGeoJSON(geometry) as geometry FROM points ORDER BY ST_MakePoint(longitude,latitude) <-> ST_MakePoint(-110.547348214819,44.5964236630063) limit 5;

And here is the Nearest Neighbor Query Result from the query above :

{“type”:”Point”,”coordinates”:[-110.547348214819,44.5964236630063]} {“type”:”Point”,”coordinates”:[-110.709738503157,45.0298832732411]} {“type”:”Point”,”coordinates”:[-110.663536323832,44.0947376621328]} {“type”:”Point”,”coordinates”:[-110.728358647307,44.0885386251708]} {“type”:”Point”,”coordinates”:[-111.100823317053,44.6630655719391]}


Don't Just take our word for it