PostGIS Integration Tips

Similar documents
PostgreSQL as an integrated data analysis platform

Stéphane LOIGEROT CARMEN s project manager BRGM/DSI/ISTN/SDI INSPIRE Compliant Data and Services on the Cloud

Write a Foreign Data Wrapper in 15 minutes

Geodatabase Programming with SQL

Introduction ToIP/Asterisk Quelques applications Trixbox/FOP Autres distributions Conclusion. Asterisk et la ToIP. Projet tuteuré

Introduction Les failles les plus courantes Les injections SQL. Failles Web. Maxime Arthaud. net7. Jeudi 03 avril 2014.

OGRS Lab «Practical introduction to OrbisGIS 2.1» 9th, July 2009 Ecole Centrale of Nantes

Administrer les solutions Citrix XenApp et XenDesktop 7.6 CXD-203

src Documentation Release Pierre Humblot

Supported DBMS platforms DB2. Informix. Enterprise ArcSDE Technology. Oracle. GIS data. GIS clients DB2. SQL Server. Enterprise Geodatabase 9.

ESMA REGISTERS OJ/26/06/2012-PROC/2012/004. Questions/ Answers

SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";! SET time_zone = "+00:00";!

GeoPackage, The Shapefile Of The Future

site et appel d'offres

Repris de : Version Debian (de base)

«Object-Oriented Multi-Methods in Cecil» Craig Chambers (Cours IFT6310, H08)

Chapter 6: Data Acquisition Methods, Procedures, and Issues

Enterprise Risk Management & Board members. GUBERNA Alumni Event June 19 th 2014 Prepared by Gaëtan LEFEVRE

Pennsylvania Geospatial Data Sharing Standards (PGDSS) V 2.5

Remote Method Invocation

Mastering Advanced GeoNetwork

Développer des applications mobiles avec ArcGIS 10.1

Memo bconsole. Memo bconsole

CASifier une application

Institute of Natural Resources Departament of General Geology and Land use planning Work with a MAPS

Chapter 5 Spatial is not Special: Managing Tracking Data in a Spatial Database

Introduction. GEAL Bibliothèque Java pour écrire des algorithmes évolutionnaires. Objectifs. Simplicité Evolution et coévolution Parallélisme

Introduction to Using PostGIS Training Workbook Last Updated 18 June 2014

GIS Databases With focused on ArcSDE

The Need For Speed. leads to PostgreSQL. Dimitri Fontaine 28 Mars 2013

The manual can be used as a practical tutorial and aims to teach users how to:

Archived Content. Contenu archivé

Account Manager H/F - CDI - France

Liste d'adresses URL

TP : Configuration de routeurs CISCO


POB-JAVA Documentation

Data Integration for ArcGIS Users Data Interoperability. Charmel Menzel, ESRI Don Murray, Safe Software

CompatibleOne & le SLA

Introduction au BIM. ESEB Seyssinet-Pariset Economie de la construction contact@eseb.fr

How To Use Postgresql With Foreign Data In A Foreign Server In A Multi Threaded Database (Postgres)

Bienvenue au Forum Vector 2007

Primitive type: GEOMETRY: matches SDO_GEOMETRY and GEOMETRY_COLUMN types.

Setting up a monitoring and remote control tool

Institute of Computational Modeling SB RAS

An Introduction to Open Source Geospatial Tools

Stockage distribué sous Linux

Jimmy Hébergement Cloud - TechDay

THE DEVELOPMENT OF OFFICE SPACE AND ERGONOMICS STANDARDS AT THE CITY OF TORONTO: AN EXAMPLE OF SUCCESSFUL INCLUSION OF ERGONOMICS AT THE DESIGN STAGE

Introduction à EMF Eclipse Modeling Framework

CFT ICT review Questions/Answers

Introduction to Spatial Data Management with Postgis. Spatial Data Management

Group Projects M1 - Cubbyhole

Méthodes ensemblistes pour une localisation robuste de robots sous-marins

Spatial Database Support

RAPPORT FINANCIER ANNUEL PORTANT SUR LES COMPTES 2014

Personnalisez votre intérieur avec les revêtements imprimés ALYOS design

DEVELOPING AND IMPLEMENTING MULTIUSER, FULLY RELATIONAL GIS DATABASE FOR DESKTOP SYSTEMS USING OPEN SOURCE TECHNOLOGIES

Building a Spatial Database in PostgreSQL

Introduction to PostGIS

Note concernant votre accord de souscription au service «Trusted Certificate Service» (TCS)

Reconstruction d un modèle géométrique à partir d un maillage 3D issu d un scanner surfacique

LinShare project version 0.8 File sharing and vault application

Integrate 'Oracle Forms', 'Oracle Reports', 'Oracle

"Internationalization vs. Localization: The Translation of Videogame Advertising"

Analysis of the Free GIS Software Applications in respect to INSPIRE services and OGC standards

Licence Informatique Année Exceptions

Accélérer le développement d'applications avec DevOps

SOFTWARE DEFINED SOLUTIONS JEUDI 19 NOVEMBRE Nicolas EHRMAN Sr Presales SDS

Memory Eye SSTIC Yoann Guillot. Sogeti / ESEC R&D yoann.guillot(at)sogeti.com

--Nom: Laurent Senécal-Léonard

Voici votre rapport sur votre service OpenERP en ligne.

PRMS.

--- Vincent Hamel, hamv

Aucune validation n a été faite sur l exemple.

COLLABORATIVE LCA. Rachel Arnould and Thomas Albisser. Hop-Cube, France

ATP Co C pyr y ight 2013 B l B ue C o C at S y S s y tems I nc. All R i R ghts R e R serve v d. 1

You can choose to install the plugin through Magento Connect or by directly using the archive files.

Creating a GIS based learning tool for the Faculty of Forest & Environment at the HNE Eberswalde

SUN SEEBEYOND ebam STUDIO RELEASE NOTES. Release 5.1.2

EMBL-EBI. Database Replication - Distribution

Frank Warmerdam President, OSGeo

Using SAS ACCESS to retrieve and store data in relational database management systems

Sharding with postgres_fdw

ishare in the Cloud Service Definition v5.0

VIREMENTS BANCAIRES INTERNATIONAUX

Mise en pratique : installation d'openvpn sur OpenWRT

Interfaces de programmation pour les composants de la solution LiveCycle ES (juillet 2008)

TP : Système de messagerie - Fichiers properties - PrepareStatement

LocatorHub. Migrating LocatorHub to Version 5.2. The Transition from ArcObjects Based Plug-Ins to ArcGIS for Server Services

Transcription:

PostGIS Integration Tips PG Session #7-2015 - Paris Licence GNU FDL 24. septembre 2015 / www.oslandia.com / infos@oslandia.com

A quoi sert un SIG? «Fleuve, Pont, Ville...»

SELECT nom_comm FROM commune WHERE population * 1000 > 100000 AND code_dept!= '75' EXCEPT SELECT DISTINCT nom_comm FROM commune co, cours_eau ce WHERE Population * 1000 > 100000 AND ce.classe='1' AND co.toponyme!= '' AND ST_Intersects(co.geom, ce.geom) CLERMONT-FERRAND NIMES BREST DIJON AIX-EN-PROVENCE TOULON

#1 Data Intégration External WS Data API Flat files PostgreSQL Other databases

#1 Data Intégration External WS Data API Flat files Other databases ETL PostgreSQL Réponse courante «Utilisez un ETL»

#1 Data Intégration External WS Data API Flat files FDW PostgreSQL Other databases Réponse alternative : «Utilisez les Foreign Data Wrapper de PostgreSQL»

https://wiki.postgresql.org/wiki/foreign_data_wrappers SQL Management of External Data (SQL/MED) ajouté au standard SQL Permet l accès à des objets distants à la base de données via du SQL Disponible dans PostgreSQL depuis la 9.3

https://wiki.postgresql.org/wiki/foreign_data_wrappers SQL Management of External Data (SQL/MED) ajouté au standard SQL Permet l accès à des objets distants à la base de données via du SQL Disponible dans PostgreSQL depuis la 9.3 ~50 connecteurs natifs déjà disponibles (et plus encore via l'extension Multicorn)

Shapefile OGR FDW PostgreSQL WFS Server (TinyOWS)

https://github.com/pramsey/pgsql-ogr-fdw Installation de OGR FDW git clone https://github.com/pramsey/pgsql-ogr-fdw.git cd pgsql-ogr-fdw make sudo make install

Définition d'un FDW wrapper CREATE EXTENSION postgis; CREATE EXTENSION ogr_fdw; CREATE SERVER shapefile_france FOREIGN DATA WRAPPER ogr_fdw OPTIONS ( datasource '/tmp/fdw_ogr/france.shp', format 'ESRI Shapefile' ); Récupération des données attributaires du shapefile ogrinfo -al -so /tmp/fdw_ogr/france.shp

Création de la Foreign Table CREATE SCHEMA shp; CREATE FOREIGN TABLE shp.france ( id_geofla integer, geom geometry, code_chf_l varchar, nom_chf_l varchar, x_chf_lieu varchar, y_chf_lieu varchar, x_centroid integer, y_centroid integer, nom_dept varchar, code_reg varchar, nom_region varchar, code_dept varchar ) SERVER shapefile_france OPTIONS (layer 'france'); Vérification SELECT id_geofla, ST_AsEWKT(ST_Centroid(geom)) AS geom FROM shp.france LIMIT 1 ;

Création d'une vue pour la Foreign Table https://github.com/pramsey/pgsql-ogr-fdw/issues/11 CREATE OR REPLACE VIEW shp.france_wfs AS SELECT id_geofla, ST_Multi(ST_SetSRID(geom,27572))::geometry(MultiPolygon,27572) AS geom, code_dept, nom_dept FROM france;

Configuration TinyOWS <tinyows online_resource="http://127.0.0.1/cgi-bin/tinyows" schema_dir="/usr/local/share/tinyows/schema/" estimated_extent="1" display_bbox="0"> <pg host="127.0.0.1" user="pggis" password="***" dbname="db" /> <metadata name="tinyows WFS Server" title="tinyows Server OGR FDW Service" /> <layer retrievable="1" writable="0" ns_prefix="tows" ns_uri="http://www.tinyows.org/" schema="shp" name="france_wfs" title="france" /> </tinyows> Vérification wget -O out http://127.0.0.1/cgi-bin/tinyows? SERVICE=WFS&REQUEST=GetFeature&Typename=tows:france_wfs

#2 Data intégration : Oracle Spatial Oracle Spatial Oracle FDW http://pgxn.org/dist/oracle_fdw/

CREATE EXTENSION postgres_fdw; CREATE EXTENSION oracle_fdw; CREATE SERVER orcl FOREIGN DATA WRAPPER oracle_fdw OPTIONS (dbserver '${ORACLE_URI}'); Mapping utilisateur Oracle GRANT USAGE ON FOREIGN SERVER orcl TO ${PGUSER}; CREATE USER orcl_map FOR ${PGUSER} SERVER orcl OPTIONS (user '${ORAUSER}', password '${ORAPWD}');

CREATE SCHEMA fdw; CREATE FOREIGN TABLE fdw.foo ( id double precision, label varchar, last_update date, geom geometry(point, 2154), ) SERVER orcl OPTIONS (schema '${ORAUSER}', table 'FOO');

CREATE SCHEMA mat; CREATE MATERIALIZED VIEW mat.foo AS SELECT * FROM fdw.foo; CREATE UNIQUE INDEX ON mat.foo(id); CREATE INDEX ON mat.foo USING GIST(geom); REFRESH MATERIALIZED VIEW CONCURRENTLY mat.foo;

#3 Data Validity SELECT count(*) FROM my_schema.my_table WHERE NOT ST_IsValid(geom);

#3 Data Validity SELECT count(*) FROM my_schema.my_table WHERE NOT ST_IsValid(geom);

UPDATE my_schema."my_table" SET geom=st_collectionextract(st_makevalid(geom), 3) WHERE ST_IsValidReason(geom)!= 'Valid Geometry' AND (GeometryType(geom) = 'POLYGON' OR GeometryType(geom) = 'MULTIPOLYGON');

UPDATE my_schema."my_table" SET geom=st_collectionextract(st_makevalid(geom), 3) WHERE ST_IsValidReason(geom)!= 'Valid Geometry' AND (GeometryType(geom) = 'POLYGON' OR GeometryType(geom) = 'MULTIPOLYGON'); Autres cas à gérer : Surface nulle Empty Linéaire avec un seul point infime translation ending point

#4 Traitement données avec PL/Python Utilisation librairie Python existante depuis PostgreSQL Appel depuis fonction SQL Un exemple avec GeoPy, Installation : sudo apt-get install postgresql-plpython-9.4 python3-geopy createdb db createlang plpython3u db psql db -c "CREATE EXTENSION postgis" S'inscrire sur GeoNames Activer free WebService sur votre compte

Function de géocodage basique en Pl/Python CREATE OR REPLACE FUNCTION geoname(toponym text) RETURNS geometry(point,4326) AS $$ from geopy import geocoders g = geocoders.geonames(username="your_username") try: place, (lat, lng) = g.geocode(toponym) result = plpy.execute( "SELECT 'SRID=4326;POINT(%s %s)'::geometry(point, 4326) AS geom" % (lng, lat), 1) return result[0]["geom"] except: plpy.warning('geocoding Error') return None $$ LANGUAGE plpython3u;

Vérification : psql db -c "SELECT ST_AsGeoJSON(geoname('New York, NY 10022'))" {"type":"point","coordinates":[-74.00597,40.71427]} http://www.openstreetmap.org/?mlon=-74.00597&mlat=40.71427&zoom=12

#5 QGIS Db Manager

; (row_number() OVER())::integer AS gid

www.oslandia.com http://www.oslandia.com/pages/jobs.html