How to do it...

Carry out the following steps:

  1. Create the following table to host weather stations' data:
      CREATE TABLE chp08.wstations 
      ( 
        id bigint NOT NULL, 
        the_geom geometry(Point,4326), 
        name character varying(48), 
        temperature real, 
        CONSTRAINT wstations_pk PRIMARY KEY (id ) 
      ); 
  1. Create an account at https://openweathermap.org to get an API key. Then, check the JSON response for the web service you are going to use. If you want the 10 closest weather stations from a point (the city centroid), the request you need to run is as follows (test it in a browser): http://api.openweathermap.org/data/2.5/find?lat=55&lon=37&cnt=10&appid=YOURKEY
  2. You should get the following JSON response (the closest 10 stations and their relative data are ordered ...

Get PostGIS Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.