SlideShare a Scribd company logo
1 of 32
Download to read offline
Intro to PostGis
  For beginners


Alban de Lavenne


17 décembre 2012
How do you organise your data ?


The problem :
    lots of dierent les, formats : csv, txt, xls, shp, asc ...
    in dierent folders more or less well organised and easy to nd
    lack of descriptions (source, stations, projection, last version ...)
    reproducible science ?
    easy sharing ?
    easy backup ?

Do you need a database ?
    not so dicult to built
    enforce you to organize you data
    save you a lot of time in the long run




A. de Lavenne (INRA, Rennes)          University of Trento              17 décembre 2012   2 / 25
How do you organise your data ?


The problem :
    lots of dierent les, formats : csv, txt, xls, shp, asc ...
    in dierent folders more or less well organised and easy to nd
    lack of descriptions (source, stations, projection, last version ...)
    reproducible science ?
    easy sharing ?
    easy backup ?

Do you need a database ?
    not so dicult to built
    enforce you to organize you data
    save you a lot of time in the long run




A. de Lavenne (INRA, Rennes)          University of Trento              17 décembre 2012   2 / 25
How do you organise your data ?


The problem :
    lots of dierent les, formats : csv, txt, xls, shp, asc ...
    in dierent folders more or less well organised and easy to nd
    lack of descriptions (source, stations, projection, last version ...)
    reproducible science ?
    easy sharing ?
    easy backup ?

Do you need a database ?
    not so dicult to built
    enforce you to organize you data
    save you a lot of time in the long run




A. de Lavenne (INRA, Rennes)          University of Trento              17 décembre 2012   2 / 25
How do you organise your data ?


The problem :
    lots of dierent les, formats : csv, txt, xls, shp, asc ...
    in dierent folders more or less well organised and easy to nd
    lack of descriptions (source, stations, projection, last version ...)
    reproducible science ?
    easy sharing ?
    easy backup ?

Do you need a database ?
    not so dicult to built
    enforce you to organize you data
    save you a lot of time in the long run




A. de Lavenne (INRA, Rennes)          University of Trento              17 décembre 2012   2 / 25
How do you organise your data ?


The problem :
    lots of dierent les, formats : csv, txt, xls, shp, asc ...
    in dierent folders more or less well organised and easy to nd
    lack of descriptions (source, stations, projection, last version ...)
    reproducible science ?
    easy sharing ?
    easy backup ?

Do you need a database ?
    not so dicult to built
    enforce you to organize you data
    save you a lot of time in the long run




A. de Lavenne (INRA, Rennes)          University of Trento              17 décembre 2012   2 / 25
How do you organise your data ?


The problem :
    lots of dierent les, formats : csv, txt, xls, shp, asc ...
    in dierent folders more or less well organised and easy to nd
    lack of descriptions (source, stations, projection, last version ...)
    reproducible science ?
    easy sharing ?
    easy backup ?

Do you need a database ?
    not so dicult to built
    enforce you to organize you data
    save you a lot of time in the long run




A. de Lavenne (INRA, Rennes)          University of Trento              17 décembre 2012   2 / 25
How do you organise your data ?


The problem :
    lots of dierent les, formats : csv, txt, xls, shp, asc ...
    in dierent folders more or less well organised and easy to nd
    lack of descriptions (source, stations, projection, last version ...)
    reproducible science ?
    easy sharing ?
    easy backup ?

Do you need a database ?
    not so dicult to built
    enforce you to organize you data
    save you a lot of time in the long run




A. de Lavenne (INRA, Rennes)          University of Trento              17 décembre 2012   2 / 25
What Is PostGIS ?




Open source object-relational database management system (ORDBMS)
Widely considered as the most full-featured open-source database system.




PostGIS = database extender for the PostgreSQL Database Management System
     open source, freely available, fairly OGC compliant
In a nutshell it adds spatial functions such as :
     distance, area, union, intersection
     specialty geometry data types to the database
A. de Lavenne (INRA, Rennes)       University of Trento           17 décembre 2012   3 / 25
Installing PostgreSQL with PostGIS Functionality



         Install PostgreSQL rst, then PostGIS extension (using Stack Builder)
                        http://www.postgresql.org/download/
                      http://postgis.refractions.net/download/

Windows
http://www.postgresql.org/download/windows

Mac
http://www.kyngchaos.com/software:postgres

Ubuntu
sudo apt-get install postgresql postgis
psql -d template1 -c alter user postgres with password 'postgres'




A. de Lavenne (INRA, Rennes)        University of Trento            17 décembre 2012   4 / 25
Creating a database




Using pgAdminIII interface
Right clic on database

or using SQL query

CREATE DATABASE blavet
  WITH ENCODING=' UTF8 '
       OWNER=postgres
       LC_COLLATE=' fr_FR . UTF -8 '
       LC_CTYPE=' fr_FR . UTF -8 '
       CONNECTION LIMIT =−1;




A. de Lavenne (INRA, Rennes)       University of Trento   17 décembre 2012   5 / 25
Adding spatial extension




Using pgAdminIII interface
Right clic on extensions

or using SQL query

CREATE EXTENSION postgis
   VERSION  2.0.1 


Check the table spatial_ref_sys
Check also that you have lots of new functions




A. de Lavenne (INRA, Rennes)         University of Trento   17 décembre 2012   6 / 25
Organising a database




How would you organise a database ? Having :
   Runo time series of dierent basins
   Rainfall time series of dierent raingauges
   Spatial description of those measurements
   Other spatial informations (like soil type, geology...)




A. de Lavenne (INRA, Rennes)         University of Trento    17 décembre 2012   7 / 25
Adding tables


Table of basins
CREATE TABLE basins
(
     id_basin serial NOT NULL ,
     name text ,
     city text ,
     altitude numeric ,
     area numeric ,
     x_lambert2e numeric ,
     y_lambert2e numeric ,
     CONSTRAINT basins_pkey PRIMARY KEY           ( id_basin   )
)
WITH (
  OIDS=TRUE
);
ALTER TABLE basins
  OWNER TO postgres ;




A. de Lavenne (INRA, Rennes)    University of Trento               17 décembre 2012   8 / 25
Adding tables


Table of measures of runo
CREATE TABLE measures_runoff
(
     id_runoff serial NOT NULL ,
     id_basin integer NOT NULL ,
     datehourmeasure timestamp with time zone NOT NULL ,
     runoff numeric ,
     timestep text ,
     unit text ,
     source text ,
     CONSTRAINT measures_runoff_pkey PRIMARY KEY ( id_runoff    ,
         id_basin , datehourmeasure )
)
WITH (
  OIDS=FALSE
);
ALTER TABLE measures_runoff
  OWNER TO postgres ;




A. de Lavenne (INRA, Rennes)    University of Trento   17 décembre 2012   9 / 25
Adding tables

Table of raingauges

CREATE TABLE raingauges
(
     id_raingauge serial ,
     id_meteofrance integer ,
     city text ,
     name_raingauge text ,
     altitude numeric ,
     type_raingauge text ,
     producer text ,
     latitude_dec numeric ,
     longitude_dec numeric ,
     CONSTRAINT raingauge_pkey PRIMARY KEY             ( id_raingauge   )
)
WITH (
  OIDS=TRUE
);
ALTER TABLE raingauges
  OWNER TO postgres ;




A. de Lavenne (INRA, Rennes)    University of Trento               17 décembre 2012   10 / 25
Adding tables


Table of measures of rainfall
CREATE TABLE measures_rainfall
(
     id_rainfall serial ,
     id_raingauge integer ,
     datehourmeasure timestamp with time zone ,
     rainfall numeric ,
     timestep text ,
     unit text ,
     CONSTRAINT rainfall_pkey PRIMARY KEY ( id_rainfall    ,
         id_raingauge , datehourmeasure )
)
WITH (
  OIDS=FALSE
);
ALTER TABLE measures_rainfall
  OWNER TO postgres ;




A. de Lavenne (INRA, Rennes)     University of Trento     17 décembre 2012   11 / 25
Adding tables



Table of antilope points

CREATE TABLE antilope_points
(
     id_point numeric NOT NULL ,
     x_lambert2e numeric ,
     y_lambert2e numeric ,
     CONSTRAINT antilope_points_pkey PRIMARY KEY       ( id_point   )
)
WITH (
  OIDS=TRUE
);
ALTER TABLE antilope_points
  OWNER TO postgres ;




A. de Lavenne (INRA, Rennes)    University of Trento        17 décembre 2012   12 / 25
Adding tables


Table of measures of antilope points

CREATE TABLE measures_rainfall_antilope
(
     id_measure serial ,
     id_point integer ,
     datehourmeasure timestamp with time zone ,
     rainfall numeric ,
     units text ,
     CONSTRAINT measures_rainfall_antilope_pkey PRIMARY KEY      (
         id_measure )
)
WITH (
  OIDS=FALSE
);
ALTER TABLE measures_rainfall_antilope
  OWNER TO postgres ;




A. de Lavenne (INRA, Rennes)     University of Trento   17 décembre 2012   13 / 25
Filling tables


Import les to database

COPY basins ( id_basin , name , city , altitude , x_lambert2e , y_lambert2e )
    FROM ' .../ Intro_to_PostGIS / basins . csv ' with delimiter '; ' ;
COPY measures_runoff ( id_basin , datehourmeasure , runoff , timestep ,
    unit ) FROM ' .../ Intro_to_PostGIS / runoff . csv ' with delimiter '
    ;' ;
COPY raingauges ( id_raingauge , id_meteofrance , city , name_raingauge ,
    altitude , latitude_dms , longitude_dms , type_raingauge , producer ,
    latitude_dec , longitude_dec ) FROM ' .../ Intro_to_PostGIS /
    raingauges . csv ' with delimiter '; ' ;
COPY measures_rainfall ( id_raingauge , datehourmeasure , rainfall ,
    timestep , unit ) FROM ' .../ Intro_to_PostGIS / rainfall . csv ' with
    delimiter '; ' ;
COPY antilope_points ( id_point , x_lambert2e , y_lambert2e ) FROM ' .../
    Intro_to_PostGIS / antilope_points . csv ' with delimiter '; ' ;
COPY measures_rainfall_antilope ( id_point , datehourmeasure , rainfall
    , units ) FROM ' .../ Intro_to_PostGIS / antilope_rainfall . csv '
    with delimiter '; ' ;




A. de Lavenne (INRA, Rennes)    University of Trento        17 décembre 2012   14 / 25
Adding internal spatial information
AddGeometryColumn

AddGeometryColumn ( schema_name           ,   table_name      ,   column_name   ,   srid ,
    type , dimension )




                               (Source : JUMP, Technical Report)
A. de Lavenne (INRA, Rennes)           University of Trento               17 décembre 2012   15 / 25
Adding internal spatial information




                      (Source : OpenGIS Simple Features Specication for SQL)



A. de Lavenne (INRA, Rennes)             University of Trento               17 décembre 2012   16 / 25
Geometry Constructors and Geometry Accessors



ST_MakePoint

ST_MakePoint ( x         ,     y   ,   z   )



                               Full list here : Geometry Constructors
ST_X, ST_Y and ST_Z

ST_X ( geometry )
ST_Y ( geometry )
ST_Z ( geometry )


                                   Full list here : Geometry Accessors




A. de Lavenne (INRA, Rennes)                   University of Trento      17 décembre 2012   17 / 25
Geometry Editors

ST_SetSRID

ST_SetSRID ( geom , srid )



ST_Transform

ST_Transform ( geom , srid )


                               Full list here : Geometry Editors


A Spatial Reference System Identier (SRID) is a unique value used to unambiguously
   identify projected, unprojected, and local spatial coordinate system denitions.

Large database of SRID created by the European Petroleum Survey Group (EPSG) is
                                   widely used.

A. de Lavenne (INRA, Rennes)            University of Trento       17 décembre 2012   18 / 25
Spatial Relationships and Measurements


Spatial Relationships and Measurements

ST_Area ( geometry )
ST_Centroid ( geometry )
ST_Contains ( geometry , geometry )
ST_Distance ( geometry , geometry )


                  Full list here : Spatial Relationships and Measurements
Geometry Processing

ST_Buffer ( geometry , radius_of_buffer )
ST_Union ( geometry set g1field )
ST_Union ( geometry , geometry )
ST_Intersection ( geometry , geometry )


                               Full list here : Geometry Processing


A. de Lavenne (INRA, Rennes)             University of Trento         17 décembre 2012   19 / 25
Adding internal spatial information


Adding geometry columns

−−A d d i n g g e o m e t r y c o l u m n s
SELECT AddGeometryColumn ( ' basins ' , ' outlet_lambert2e ' , 2 7 5 7 2 , '
    POINT ' , 2 ) ;
SELECT AddGeometryColumn ( ' basins ' , ' outlet_lambert93 ' , 2 1 5 4 , '
    POINT ' , 2 ) ;
SELECT AddGeometryColumn ( ' basins ' , ' limits_lambert2e ' , 2 7 5 7 2 , '
    POLYGON ' , 2 ) ;
SELECT AddGeometryColumn ( ' basins ' , ' limits_lambert93 ' , 2 1 5 4 , '
    POLYGON ' , 2 ) ;
SELECT AddGeometryColumn ( ' raingauges ' , ' raingauges_lambert2e ' ,
    2 7 5 7 2 , ' POINT ' , 2 ) ;
SELECT AddGeometryColumn ( ' raingauges ' , ' raingauges_lambert93 ' ,
    2 1 5 4 , ' POINT ' , 2 ) ;
SELECT AddGeometryColumn ( ' antilope_points ' , '
    antilope_points_lambert2e ' , 2 7 5 7 2 , ' POINT ' , 2 ) ;
SELECT AddGeometryColumn ( ' antilope_points ' , '
    antilope_points_lambert93 ' , 2 1 5 4 , ' POINT ' , 2 ) ;




 A. de Lavenne (INRA, Rennes)                 University of Trento   17 décembre 2012   20 / 25
Adding internal spatial information


Filling geometry columns

−− F i l l g e o m e t r y c o l u m n s
UPDATE basins SET outlet_lambert2e=st_setsrid ( st_makepoint (
    x_lambert2e , y_lambert2e ) , 2 7 5 7 2 ) ;
UPDATE basins SET outlet_lambert93=st_transform ( outlet_lambert2e
       ,2154) ;
UPDATE raingauges SET raingauges_lambert2e=st_transform (
    st_setsrid ( st_makepoint ( longitude_dec , latitude_dec ) ,           4326)
       ,27572) ;
UPDATE raingauges SET raingauges_lambert93=st_transform (
    st_setsrid ( st_makepoint ( longitude_dec , latitude_dec ) ,           4326)
       ,2154) ;
UPDATE antilope_points SET antilope_points_lambert2e=st_setsrid (
    st_makepoint ( x_lambert2e , y_lambert2e ) , 2 7 5 7 2 ) ;
UPDATE antilope_points SET antilope_points_lambert93=st_transform
    ( st_setsrid ( st_makepoint ( x_lambert2e , y_lambert2e ) , 2 7 5 7 2 )
       ,2154) ;




 A. de Lavenne (INRA, Rennes)              University of Trento   17 décembre 2012   21 / 25
Adding external spatial information
Using graphical interface
Using Quantum-GIS extension (like QGIS spit)
pgShapeLoader
...

Using command line with shp2pgsql
shp2pgsql -iIDd -s 2154 -W utf8 basins_lambert93.shp basins_polygon                impo
psql -U postgres -W -h localhost -p 5432 -d blavet -f import.sql

                                           OR
shp2pgsql -iIDd -s 2154 -W utf8 basins_lambert93.shp basins_polygon |
psql -U postgres -W -h localhost -p 5432 -d blavet

Filling geometry columns

UPDATE basins SET limits_lambert93=st_geometryn ( geom , 1 )
FROM basins_polygon
WHERE basins_polygon . id_basin=basins . id_basin ;

and limits_lambert2e ...
A. de Lavenne (INRA, Rennes)        University of Trento      17 décembre 2012   22 / 25
Exemple SQL of query




Select a chronique of runo
Calculate the area of one basin
Select raingauges inside one basin
Select average antilope rainfall time serie for each basins
Import shapele geology and get a table of statistics of geology for each basin
Check if there is double measures in runo and rainfall




A. de Lavenne (INRA, Rennes)        University of Trento            17 décembre 2012   23 / 25
Visualizing your data




Using Qgis to vizualize your data
Plugin in Qgis for query and shapele creation
Plugin in Qgis for importing data




A. de Lavenne (INRA, Rennes)        University of Trento   17 décembre 2012   24 / 25
Connect to your database with R




A. de Lavenne (INRA, Rennes)        University of Trento    17 décembre 2012   25 / 25
Connect to your database with R




A. de Lavenne (INRA, Rennes)        University of Trento    17 décembre 2012   25 / 25

More Related Content

Viewers also liked

A sensitivity Analysis of Eddy Covariance Data Processing Methods for Evapotr...
A sensitivity Analysis of Eddy Covariance Data Processing Methods for Evapotr...A sensitivity Analysis of Eddy Covariance Data Processing Methods for Evapotr...
A sensitivity Analysis of Eddy Covariance Data Processing Methods for Evapotr...Troy Bernier
 
Python IDLE (Integrated Development and Learning Environment) for remote sens...
Python IDLE (Integrated Development and Learning Environment) for remote sens...Python IDLE (Integrated Development and Learning Environment) for remote sens...
Python IDLE (Integrated Development and Learning Environment) for remote sens...Ramesh Dhungel
 
Session I: Water Consumption – Evapotranspiration (ET) Case Study Tunisia
Session I: Water Consumption – Evapotranspiration (ET) Case Study TunisiaSession I: Water Consumption – Evapotranspiration (ET) Case Study Tunisia
Session I: Water Consumption – Evapotranspiration (ET) Case Study TunisiaNENAwaterscarcity
 
Using Git Inside Eclipse, Pushing/Cloning from GitHub
Using Git Inside Eclipse, Pushing/Cloning from GitHubUsing Git Inside Eclipse, Pushing/Cloning from GitHub
Using Git Inside Eclipse, Pushing/Cloning from GitHubAboutHydrology Slides
 
Time integration of evapotranspiration using a two source surface energy bala...
Time integration of evapotranspiration using a two source surface energy bala...Time integration of evapotranspiration using a two source surface energy bala...
Time integration of evapotranspiration using a two source surface energy bala...Ramesh Dhungel
 
Adding Confidence to Seasonal Drought Forecasts using reference evapotranspir...
Adding Confidence to Seasonal Drought Forecasts using reference evapotranspir...Adding Confidence to Seasonal Drought Forecasts using reference evapotranspir...
Adding Confidence to Seasonal Drought Forecasts using reference evapotranspir...DRIscience
 
2013 ASPRS Track, Developing an ArcGIS Toolbox for Estimating EvapoTranspirat...
2013 ASPRS Track, Developing an ArcGIS Toolbox for Estimating EvapoTranspirat...2013 ASPRS Track, Developing an ArcGIS Toolbox for Estimating EvapoTranspirat...
2013 ASPRS Track, Developing an ArcGIS Toolbox for Estimating EvapoTranspirat...GIS in the Rockies
 
Cu07821 3 precipitation and evapotranspiration
Cu07821 3  precipitation and evapotranspirationCu07821 3  precipitation and evapotranspiration
Cu07821 3 precipitation and evapotranspirationHenk Massink
 

Viewers also liked (20)

A sensitivity Analysis of Eddy Covariance Data Processing Methods for Evapotr...
A sensitivity Analysis of Eddy Covariance Data Processing Methods for Evapotr...A sensitivity Analysis of Eddy Covariance Data Processing Methods for Evapotr...
A sensitivity Analysis of Eddy Covariance Data Processing Methods for Evapotr...
 
6 measurement&representation
6   measurement&representation6   measurement&representation
6 measurement&representation
 
14 snow hydrology-part1
14 snow hydrology-part114 snow hydrology-part1
14 snow hydrology-part1
 
Python IDLE (Integrated Development and Learning Environment) for remote sens...
Python IDLE (Integrated Development and Learning Environment) for remote sens...Python IDLE (Integrated Development and Learning Environment) for remote sens...
Python IDLE (Integrated Development and Learning Environment) for remote sens...
 
Session I: Water Consumption – Evapotranspiration (ET) Case Study Tunisia
Session I: Water Consumption – Evapotranspiration (ET) Case Study TunisiaSession I: Water Consumption – Evapotranspiration (ET) Case Study Tunisia
Session I: Water Consumption – Evapotranspiration (ET) Case Study Tunisia
 
10 water in soil-rev 1
10   water in soil-rev 110   water in soil-rev 1
10 water in soil-rev 1
 
Introduction tohydrology b
Introduction tohydrology bIntroduction tohydrology b
Introduction tohydrology b
 
Introduction tohydrology c
Introduction tohydrology cIntroduction tohydrology c
Introduction tohydrology c
 
Using Git Inside Eclipse, Pushing/Cloning from GitHub
Using Git Inside Eclipse, Pushing/Cloning from GitHubUsing Git Inside Eclipse, Pushing/Cloning from GitHub
Using Git Inside Eclipse, Pushing/Cloning from GitHub
 
From land use to land cover: evapotraspiration assessment in a metropolitan r...
From land use to land cover: evapotraspiration assessment in a metropolitan r...From land use to land cover: evapotraspiration assessment in a metropolitan r...
From land use to land cover: evapotraspiration assessment in a metropolitan r...
 
4 introduction to uDig
4   introduction to uDig4   introduction to uDig
4 introduction to uDig
 
Time integration of evapotranspiration using a two source surface energy bala...
Time integration of evapotranspiration using a two source surface energy bala...Time integration of evapotranspiration using a two source surface energy bala...
Time integration of evapotranspiration using a two source surface energy bala...
 
Adding Confidence to Seasonal Drought Forecasts using reference evapotranspir...
Adding Confidence to Seasonal Drought Forecasts using reference evapotranspir...Adding Confidence to Seasonal Drought Forecasts using reference evapotranspir...
Adding Confidence to Seasonal Drought Forecasts using reference evapotranspir...
 
3 introduction gis
3   introduction gis3   introduction gis
3 introduction gis
 
2013 ASPRS Track, Developing an ArcGIS Toolbox for Estimating EvapoTranspirat...
2013 ASPRS Track, Developing an ArcGIS Toolbox for Estimating EvapoTranspirat...2013 ASPRS Track, Developing an ArcGIS Toolbox for Estimating EvapoTranspirat...
2013 ASPRS Track, Developing an ArcGIS Toolbox for Estimating EvapoTranspirat...
 
2 hydro-geomorphology
2  hydro-geomorphology2  hydro-geomorphology
2 hydro-geomorphology
 
Cu07821 3 precipitation and evapotranspiration
Cu07821 3  precipitation and evapotranspirationCu07821 3  precipitation and evapotranspiration
Cu07821 3 precipitation and evapotranspiration
 
#4- Comp Plan - Evaporation & Evapotranspiration
#4- Comp Plan - Evaporation & Evapotranspiration#4- Comp Plan - Evaporation & Evapotranspiration
#4- Comp Plan - Evaporation & Evapotranspiration
 
9 precipitations - rainfall
9   precipitations - rainfall9   precipitations - rainfall
9 precipitations - rainfall
 
15 Evapotranspiration
15   Evapotranspiration15   Evapotranspiration
15 Evapotranspiration
 

Similar to Introduction to post_gis

Python for Financial Data Analysis with pandas
Python for Financial Data Analysis with pandasPython for Financial Data Analysis with pandas
Python for Financial Data Analysis with pandasWes McKinney
 
Slides 111017220255-phpapp01
Slides 111017220255-phpapp01Slides 111017220255-phpapp01
Slides 111017220255-phpapp01Ken Mwai
 
Rattle Graphical Interface for R Language
Rattle Graphical Interface for R LanguageRattle Graphical Interface for R Language
Rattle Graphical Interface for R LanguageMajid Abdollahi
 
Deep learning and applications in non-cognitive domains II
Deep learning and applications in non-cognitive domains IIDeep learning and applications in non-cognitive domains II
Deep learning and applications in non-cognitive domains IIDeakin University
 
Vitus Masters Defense
Vitus Masters DefenseVitus Masters Defense
Vitus Masters DefensederDoc
 
H2O Distributed Deep Learning by Arno Candel 071614
H2O Distributed Deep Learning by Arno Candel 071614H2O Distributed Deep Learning by Arno Candel 071614
H2O Distributed Deep Learning by Arno Candel 071614Sri Ambati
 
A New Partnership for Cross-Scale, Cross-Domain eScience
A New Partnership for Cross-Scale, Cross-Domain eScienceA New Partnership for Cross-Scale, Cross-Domain eScience
A New Partnership for Cross-Scale, Cross-Domain eScienceUniversity of Washington
 
PyParis 2017 / Pandas - What's new and whats coming - Joris van den Bossche
PyParis 2017 / Pandas - What's new and whats coming - Joris van den BosschePyParis 2017 / Pandas - What's new and whats coming - Joris van den Bossche
PyParis 2017 / Pandas - What's new and whats coming - Joris van den BosschePôle Systematic Paris-Region
 
Stratosphere with big_data_analytics
Stratosphere with big_data_analyticsStratosphere with big_data_analytics
Stratosphere with big_data_analyticsAvinash Pandu
 
AWS SSA Webinar 20 - Getting Started with Data Warehouses on AWS
AWS SSA Webinar 20 - Getting Started with Data Warehouses on AWSAWS SSA Webinar 20 - Getting Started with Data Warehouses on AWS
AWS SSA Webinar 20 - Getting Started with Data Warehouses on AWSCobus Bernard
 
Empowering Transformational Science
Empowering Transformational ScienceEmpowering Transformational Science
Empowering Transformational ScienceChelle Gentemann
 
Debunking "Purpose-Built Data Systems:": Enter the Universal Database
Debunking "Purpose-Built Data Systems:": Enter the Universal DatabaseDebunking "Purpose-Built Data Systems:": Enter the Universal Database
Debunking "Purpose-Built Data Systems:": Enter the Universal DatabaseStavros Papadopoulos
 
ACT Talk, Giuseppe Totaro: High Performance Computing for Distributed Indexin...
ACT Talk, Giuseppe Totaro: High Performance Computing for Distributed Indexin...ACT Talk, Giuseppe Totaro: High Performance Computing for Distributed Indexin...
ACT Talk, Giuseppe Totaro: High Performance Computing for Distributed Indexin...Advanced-Concepts-Team
 
Tg noh jeju_workshop
Tg noh jeju_workshopTg noh jeju_workshop
Tg noh jeju_workshopTae-Gil Noh
 
Hands on data science with r.pptx
Hands  on data science with r.pptxHands  on data science with r.pptx
Hands on data science with r.pptxNimrita Koul
 
Positional Data Organization and Compression in Web Inverted Indexes
Positional Data Organization and Compression in Web Inverted IndexesPositional Data Organization and Compression in Web Inverted Indexes
Positional Data Organization and Compression in Web Inverted IndexesLeonidas Akritidis
 
Hive ICDE 2010
Hive ICDE 2010Hive ICDE 2010
Hive ICDE 2010ragho
 

Similar to Introduction to post_gis (20)

Python for Financial Data Analysis with pandas
Python for Financial Data Analysis with pandasPython for Financial Data Analysis with pandas
Python for Financial Data Analysis with pandas
 
Slides 111017220255-phpapp01
Slides 111017220255-phpapp01Slides 111017220255-phpapp01
Slides 111017220255-phpapp01
 
Rattle Graphical Interface for R Language
Rattle Graphical Interface for R LanguageRattle Graphical Interface for R Language
Rattle Graphical Interface for R Language
 
Democratizing Big Semantic Data management
Democratizing Big Semantic Data managementDemocratizing Big Semantic Data management
Democratizing Big Semantic Data management
 
Deep learning and applications in non-cognitive domains II
Deep learning and applications in non-cognitive domains IIDeep learning and applications in non-cognitive domains II
Deep learning and applications in non-cognitive domains II
 
Vitus Masters Defense
Vitus Masters DefenseVitus Masters Defense
Vitus Masters Defense
 
H2O Distributed Deep Learning by Arno Candel 071614
H2O Distributed Deep Learning by Arno Candel 071614H2O Distributed Deep Learning by Arno Candel 071614
H2O Distributed Deep Learning by Arno Candel 071614
 
A New Partnership for Cross-Scale, Cross-Domain eScience
A New Partnership for Cross-Scale, Cross-Domain eScienceA New Partnership for Cross-Scale, Cross-Domain eScience
A New Partnership for Cross-Scale, Cross-Domain eScience
 
PyParis 2017 / Pandas - What's new and whats coming - Joris van den Bossche
PyParis 2017 / Pandas - What's new and whats coming - Joris van den BosschePyParis 2017 / Pandas - What's new and whats coming - Joris van den Bossche
PyParis 2017 / Pandas - What's new and whats coming - Joris van den Bossche
 
Hadoop
HadoopHadoop
Hadoop
 
Stratosphere with big_data_analytics
Stratosphere with big_data_analyticsStratosphere with big_data_analytics
Stratosphere with big_data_analytics
 
AWS SSA Webinar 20 - Getting Started with Data Warehouses on AWS
AWS SSA Webinar 20 - Getting Started with Data Warehouses on AWSAWS SSA Webinar 20 - Getting Started with Data Warehouses on AWS
AWS SSA Webinar 20 - Getting Started with Data Warehouses on AWS
 
Empowering Transformational Science
Empowering Transformational ScienceEmpowering Transformational Science
Empowering Transformational Science
 
Debunking "Purpose-Built Data Systems:": Enter the Universal Database
Debunking "Purpose-Built Data Systems:": Enter the Universal DatabaseDebunking "Purpose-Built Data Systems:": Enter the Universal Database
Debunking "Purpose-Built Data Systems:": Enter the Universal Database
 
ACT Talk, Giuseppe Totaro: High Performance Computing for Distributed Indexin...
ACT Talk, Giuseppe Totaro: High Performance Computing for Distributed Indexin...ACT Talk, Giuseppe Totaro: High Performance Computing for Distributed Indexin...
ACT Talk, Giuseppe Totaro: High Performance Computing for Distributed Indexin...
 
Tg noh jeju_workshop
Tg noh jeju_workshopTg noh jeju_workshop
Tg noh jeju_workshop
 
Unit 3
Unit 3Unit 3
Unit 3
 
Hands on data science with r.pptx
Hands  on data science with r.pptxHands  on data science with r.pptx
Hands on data science with r.pptx
 
Positional Data Organization and Compression in Web Inverted Indexes
Positional Data Organization and Compression in Web Inverted IndexesPositional Data Organization and Compression in Web Inverted Indexes
Positional Data Organization and Compression in Web Inverted Indexes
 
Hive ICDE 2010
Hive ICDE 2010Hive ICDE 2010
Hive ICDE 2010
 

More from AboutHydrology Slides (12)

RoccoPancieraMesiano sept25 2013
RoccoPancieraMesiano sept25 2013RoccoPancieraMesiano sept25 2013
RoccoPancieraMesiano sept25 2013
 
Luca Brocca seminario trento
Luca Brocca seminario trentoLuca Brocca seminario trento
Luca Brocca seminario trento
 
3b jf h-readingdatafromconsole
3b jf h-readingdatafromconsole3b jf h-readingdatafromconsole
3b jf h-readingdatafromconsole
 
3 jf h-linearequations
3  jf h-linearequations3  jf h-linearequations
3 jf h-linearequations
 
2 jfh-yourveryfirstprogram
2  jfh-yourveryfirstprogram2  jfh-yourveryfirstprogram
2 jfh-yourveryfirstprogram
 
1 jf h-getting started
1  jf h-getting started1  jf h-getting started
1 jf h-getting started
 
La piattaforma acqua
La piattaforma acquaLa piattaforma acqua
La piattaforma acqua
 
La convenzione delle alpi
La convenzione delle alpiLa convenzione delle alpi
La convenzione delle alpi
 
1 introduction to hydrology
1   introduction to hydrology1   introduction to hydrology
1 introduction to hydrology
 
13 solar radiation
13   solar radiation13   solar radiation
13 solar radiation
 
0-RealBookStyleAndNotation
0-RealBookStyleAndNotation0-RealBookStyleAndNotation
0-RealBookStyleAndNotation
 
0-RealBooksOfHydrology
0-RealBooksOfHydrology0-RealBooksOfHydrology
0-RealBooksOfHydrology
 

Recently uploaded

4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptxmary850239
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...Nguyen Thanh Tu Collection
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfMr Bounab Samir
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomnelietumpap1
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4MiaBumagat1
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designMIPLM
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxAshokKarra1
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Mark Reed
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Celine George
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)lakshayb543
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17Celine George
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfTechSoup
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Celine George
 

Recently uploaded (20)

4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choom
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-design
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptx
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17
 

Introduction to post_gis

  • 1. Intro to PostGis For beginners Alban de Lavenne 17 décembre 2012
  • 2. How do you organise your data ? The problem : lots of dierent les, formats : csv, txt, xls, shp, asc ... in dierent folders more or less well organised and easy to nd lack of descriptions (source, stations, projection, last version ...) reproducible science ? easy sharing ? easy backup ? Do you need a database ? not so dicult to built enforce you to organize you data save you a lot of time in the long run A. de Lavenne (INRA, Rennes) University of Trento 17 décembre 2012 2 / 25
  • 3. How do you organise your data ? The problem : lots of dierent les, formats : csv, txt, xls, shp, asc ... in dierent folders more or less well organised and easy to nd lack of descriptions (source, stations, projection, last version ...) reproducible science ? easy sharing ? easy backup ? Do you need a database ? not so dicult to built enforce you to organize you data save you a lot of time in the long run A. de Lavenne (INRA, Rennes) University of Trento 17 décembre 2012 2 / 25
  • 4. How do you organise your data ? The problem : lots of dierent les, formats : csv, txt, xls, shp, asc ... in dierent folders more or less well organised and easy to nd lack of descriptions (source, stations, projection, last version ...) reproducible science ? easy sharing ? easy backup ? Do you need a database ? not so dicult to built enforce you to organize you data save you a lot of time in the long run A. de Lavenne (INRA, Rennes) University of Trento 17 décembre 2012 2 / 25
  • 5. How do you organise your data ? The problem : lots of dierent les, formats : csv, txt, xls, shp, asc ... in dierent folders more or less well organised and easy to nd lack of descriptions (source, stations, projection, last version ...) reproducible science ? easy sharing ? easy backup ? Do you need a database ? not so dicult to built enforce you to organize you data save you a lot of time in the long run A. de Lavenne (INRA, Rennes) University of Trento 17 décembre 2012 2 / 25
  • 6. How do you organise your data ? The problem : lots of dierent les, formats : csv, txt, xls, shp, asc ... in dierent folders more or less well organised and easy to nd lack of descriptions (source, stations, projection, last version ...) reproducible science ? easy sharing ? easy backup ? Do you need a database ? not so dicult to built enforce you to organize you data save you a lot of time in the long run A. de Lavenne (INRA, Rennes) University of Trento 17 décembre 2012 2 / 25
  • 7. How do you organise your data ? The problem : lots of dierent les, formats : csv, txt, xls, shp, asc ... in dierent folders more or less well organised and easy to nd lack of descriptions (source, stations, projection, last version ...) reproducible science ? easy sharing ? easy backup ? Do you need a database ? not so dicult to built enforce you to organize you data save you a lot of time in the long run A. de Lavenne (INRA, Rennes) University of Trento 17 décembre 2012 2 / 25
  • 8. How do you organise your data ? The problem : lots of dierent les, formats : csv, txt, xls, shp, asc ... in dierent folders more or less well organised and easy to nd lack of descriptions (source, stations, projection, last version ...) reproducible science ? easy sharing ? easy backup ? Do you need a database ? not so dicult to built enforce you to organize you data save you a lot of time in the long run A. de Lavenne (INRA, Rennes) University of Trento 17 décembre 2012 2 / 25
  • 9. What Is PostGIS ? Open source object-relational database management system (ORDBMS) Widely considered as the most full-featured open-source database system. PostGIS = database extender for the PostgreSQL Database Management System open source, freely available, fairly OGC compliant In a nutshell it adds spatial functions such as : distance, area, union, intersection specialty geometry data types to the database A. de Lavenne (INRA, Rennes) University of Trento 17 décembre 2012 3 / 25
  • 10. Installing PostgreSQL with PostGIS Functionality Install PostgreSQL rst, then PostGIS extension (using Stack Builder) http://www.postgresql.org/download/ http://postgis.refractions.net/download/ Windows http://www.postgresql.org/download/windows Mac http://www.kyngchaos.com/software:postgres Ubuntu sudo apt-get install postgresql postgis psql -d template1 -c alter user postgres with password 'postgres' A. de Lavenne (INRA, Rennes) University of Trento 17 décembre 2012 4 / 25
  • 11. Creating a database Using pgAdminIII interface Right clic on database or using SQL query CREATE DATABASE blavet WITH ENCODING=' UTF8 ' OWNER=postgres LC_COLLATE=' fr_FR . UTF -8 ' LC_CTYPE=' fr_FR . UTF -8 ' CONNECTION LIMIT =−1; A. de Lavenne (INRA, Rennes) University of Trento 17 décembre 2012 5 / 25
  • 12. Adding spatial extension Using pgAdminIII interface Right clic on extensions or using SQL query CREATE EXTENSION postgis VERSION 2.0.1 Check the table spatial_ref_sys Check also that you have lots of new functions A. de Lavenne (INRA, Rennes) University of Trento 17 décembre 2012 6 / 25
  • 13. Organising a database How would you organise a database ? Having : Runo time series of dierent basins Rainfall time series of dierent raingauges Spatial description of those measurements Other spatial informations (like soil type, geology...) A. de Lavenne (INRA, Rennes) University of Trento 17 décembre 2012 7 / 25
  • 14. Adding tables Table of basins CREATE TABLE basins ( id_basin serial NOT NULL , name text , city text , altitude numeric , area numeric , x_lambert2e numeric , y_lambert2e numeric , CONSTRAINT basins_pkey PRIMARY KEY ( id_basin ) ) WITH ( OIDS=TRUE ); ALTER TABLE basins OWNER TO postgres ; A. de Lavenne (INRA, Rennes) University of Trento 17 décembre 2012 8 / 25
  • 15. Adding tables Table of measures of runo CREATE TABLE measures_runoff ( id_runoff serial NOT NULL , id_basin integer NOT NULL , datehourmeasure timestamp with time zone NOT NULL , runoff numeric , timestep text , unit text , source text , CONSTRAINT measures_runoff_pkey PRIMARY KEY ( id_runoff , id_basin , datehourmeasure ) ) WITH ( OIDS=FALSE ); ALTER TABLE measures_runoff OWNER TO postgres ; A. de Lavenne (INRA, Rennes) University of Trento 17 décembre 2012 9 / 25
  • 16. Adding tables Table of raingauges CREATE TABLE raingauges ( id_raingauge serial , id_meteofrance integer , city text , name_raingauge text , altitude numeric , type_raingauge text , producer text , latitude_dec numeric , longitude_dec numeric , CONSTRAINT raingauge_pkey PRIMARY KEY ( id_raingauge ) ) WITH ( OIDS=TRUE ); ALTER TABLE raingauges OWNER TO postgres ; A. de Lavenne (INRA, Rennes) University of Trento 17 décembre 2012 10 / 25
  • 17. Adding tables Table of measures of rainfall CREATE TABLE measures_rainfall ( id_rainfall serial , id_raingauge integer , datehourmeasure timestamp with time zone , rainfall numeric , timestep text , unit text , CONSTRAINT rainfall_pkey PRIMARY KEY ( id_rainfall , id_raingauge , datehourmeasure ) ) WITH ( OIDS=FALSE ); ALTER TABLE measures_rainfall OWNER TO postgres ; A. de Lavenne (INRA, Rennes) University of Trento 17 décembre 2012 11 / 25
  • 18. Adding tables Table of antilope points CREATE TABLE antilope_points ( id_point numeric NOT NULL , x_lambert2e numeric , y_lambert2e numeric , CONSTRAINT antilope_points_pkey PRIMARY KEY ( id_point ) ) WITH ( OIDS=TRUE ); ALTER TABLE antilope_points OWNER TO postgres ; A. de Lavenne (INRA, Rennes) University of Trento 17 décembre 2012 12 / 25
  • 19. Adding tables Table of measures of antilope points CREATE TABLE measures_rainfall_antilope ( id_measure serial , id_point integer , datehourmeasure timestamp with time zone , rainfall numeric , units text , CONSTRAINT measures_rainfall_antilope_pkey PRIMARY KEY ( id_measure ) ) WITH ( OIDS=FALSE ); ALTER TABLE measures_rainfall_antilope OWNER TO postgres ; A. de Lavenne (INRA, Rennes) University of Trento 17 décembre 2012 13 / 25
  • 20. Filling tables Import les to database COPY basins ( id_basin , name , city , altitude , x_lambert2e , y_lambert2e ) FROM ' .../ Intro_to_PostGIS / basins . csv ' with delimiter '; ' ; COPY measures_runoff ( id_basin , datehourmeasure , runoff , timestep , unit ) FROM ' .../ Intro_to_PostGIS / runoff . csv ' with delimiter ' ;' ; COPY raingauges ( id_raingauge , id_meteofrance , city , name_raingauge , altitude , latitude_dms , longitude_dms , type_raingauge , producer , latitude_dec , longitude_dec ) FROM ' .../ Intro_to_PostGIS / raingauges . csv ' with delimiter '; ' ; COPY measures_rainfall ( id_raingauge , datehourmeasure , rainfall , timestep , unit ) FROM ' .../ Intro_to_PostGIS / rainfall . csv ' with delimiter '; ' ; COPY antilope_points ( id_point , x_lambert2e , y_lambert2e ) FROM ' .../ Intro_to_PostGIS / antilope_points . csv ' with delimiter '; ' ; COPY measures_rainfall_antilope ( id_point , datehourmeasure , rainfall , units ) FROM ' .../ Intro_to_PostGIS / antilope_rainfall . csv ' with delimiter '; ' ; A. de Lavenne (INRA, Rennes) University of Trento 17 décembre 2012 14 / 25
  • 21. Adding internal spatial information AddGeometryColumn AddGeometryColumn ( schema_name , table_name , column_name , srid , type , dimension ) (Source : JUMP, Technical Report) A. de Lavenne (INRA, Rennes) University of Trento 17 décembre 2012 15 / 25
  • 22. Adding internal spatial information (Source : OpenGIS Simple Features Specication for SQL) A. de Lavenne (INRA, Rennes) University of Trento 17 décembre 2012 16 / 25
  • 23. Geometry Constructors and Geometry Accessors ST_MakePoint ST_MakePoint ( x , y , z ) Full list here : Geometry Constructors ST_X, ST_Y and ST_Z ST_X ( geometry ) ST_Y ( geometry ) ST_Z ( geometry ) Full list here : Geometry Accessors A. de Lavenne (INRA, Rennes) University of Trento 17 décembre 2012 17 / 25
  • 24. Geometry Editors ST_SetSRID ST_SetSRID ( geom , srid ) ST_Transform ST_Transform ( geom , srid ) Full list here : Geometry Editors A Spatial Reference System Identier (SRID) is a unique value used to unambiguously identify projected, unprojected, and local spatial coordinate system denitions. Large database of SRID created by the European Petroleum Survey Group (EPSG) is widely used. A. de Lavenne (INRA, Rennes) University of Trento 17 décembre 2012 18 / 25
  • 25. Spatial Relationships and Measurements Spatial Relationships and Measurements ST_Area ( geometry ) ST_Centroid ( geometry ) ST_Contains ( geometry , geometry ) ST_Distance ( geometry , geometry ) Full list here : Spatial Relationships and Measurements Geometry Processing ST_Buffer ( geometry , radius_of_buffer ) ST_Union ( geometry set g1field ) ST_Union ( geometry , geometry ) ST_Intersection ( geometry , geometry ) Full list here : Geometry Processing A. de Lavenne (INRA, Rennes) University of Trento 17 décembre 2012 19 / 25
  • 26. Adding internal spatial information Adding geometry columns −−A d d i n g g e o m e t r y c o l u m n s SELECT AddGeometryColumn ( ' basins ' , ' outlet_lambert2e ' , 2 7 5 7 2 , ' POINT ' , 2 ) ; SELECT AddGeometryColumn ( ' basins ' , ' outlet_lambert93 ' , 2 1 5 4 , ' POINT ' , 2 ) ; SELECT AddGeometryColumn ( ' basins ' , ' limits_lambert2e ' , 2 7 5 7 2 , ' POLYGON ' , 2 ) ; SELECT AddGeometryColumn ( ' basins ' , ' limits_lambert93 ' , 2 1 5 4 , ' POLYGON ' , 2 ) ; SELECT AddGeometryColumn ( ' raingauges ' , ' raingauges_lambert2e ' , 2 7 5 7 2 , ' POINT ' , 2 ) ; SELECT AddGeometryColumn ( ' raingauges ' , ' raingauges_lambert93 ' , 2 1 5 4 , ' POINT ' , 2 ) ; SELECT AddGeometryColumn ( ' antilope_points ' , ' antilope_points_lambert2e ' , 2 7 5 7 2 , ' POINT ' , 2 ) ; SELECT AddGeometryColumn ( ' antilope_points ' , ' antilope_points_lambert93 ' , 2 1 5 4 , ' POINT ' , 2 ) ; A. de Lavenne (INRA, Rennes) University of Trento 17 décembre 2012 20 / 25
  • 27. Adding internal spatial information Filling geometry columns −− F i l l g e o m e t r y c o l u m n s UPDATE basins SET outlet_lambert2e=st_setsrid ( st_makepoint ( x_lambert2e , y_lambert2e ) , 2 7 5 7 2 ) ; UPDATE basins SET outlet_lambert93=st_transform ( outlet_lambert2e ,2154) ; UPDATE raingauges SET raingauges_lambert2e=st_transform ( st_setsrid ( st_makepoint ( longitude_dec , latitude_dec ) , 4326) ,27572) ; UPDATE raingauges SET raingauges_lambert93=st_transform ( st_setsrid ( st_makepoint ( longitude_dec , latitude_dec ) , 4326) ,2154) ; UPDATE antilope_points SET antilope_points_lambert2e=st_setsrid ( st_makepoint ( x_lambert2e , y_lambert2e ) , 2 7 5 7 2 ) ; UPDATE antilope_points SET antilope_points_lambert93=st_transform ( st_setsrid ( st_makepoint ( x_lambert2e , y_lambert2e ) , 2 7 5 7 2 ) ,2154) ; A. de Lavenne (INRA, Rennes) University of Trento 17 décembre 2012 21 / 25
  • 28. Adding external spatial information Using graphical interface Using Quantum-GIS extension (like QGIS spit) pgShapeLoader ... Using command line with shp2pgsql shp2pgsql -iIDd -s 2154 -W utf8 basins_lambert93.shp basins_polygon impo psql -U postgres -W -h localhost -p 5432 -d blavet -f import.sql OR shp2pgsql -iIDd -s 2154 -W utf8 basins_lambert93.shp basins_polygon | psql -U postgres -W -h localhost -p 5432 -d blavet Filling geometry columns UPDATE basins SET limits_lambert93=st_geometryn ( geom , 1 ) FROM basins_polygon WHERE basins_polygon . id_basin=basins . id_basin ; and limits_lambert2e ... A. de Lavenne (INRA, Rennes) University of Trento 17 décembre 2012 22 / 25
  • 29. Exemple SQL of query Select a chronique of runo Calculate the area of one basin Select raingauges inside one basin Select average antilope rainfall time serie for each basins Import shapele geology and get a table of statistics of geology for each basin Check if there is double measures in runo and rainfall A. de Lavenne (INRA, Rennes) University of Trento 17 décembre 2012 23 / 25
  • 30. Visualizing your data Using Qgis to vizualize your data Plugin in Qgis for query and shapele creation Plugin in Qgis for importing data A. de Lavenne (INRA, Rennes) University of Trento 17 décembre 2012 24 / 25
  • 31. Connect to your database with R A. de Lavenne (INRA, Rennes) University of Trento 17 décembre 2012 25 / 25
  • 32. Connect to your database with R A. de Lavenne (INRA, Rennes) University of Trento 17 décembre 2012 25 / 25