Differences
This shows you the differences between two versions of the page.
— |
sigavance [2014/02/03 16:40] (current) glaroc created |
||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Utiliser R avec GRASS ====== | ||
+ | Avant la première utilisation (dans R): | ||
+ | |||
+ | <file> | ||
+ | install.packages('spgrass6', dependencies=TRUE) | ||
+ | |||
+ | Utilisateurs Mac: | ||
+ | install.packages('spgrass6', type='source', dependencies=TRUE) | ||
+ | </file> | ||
+ | |||
+ | Commandes spgrass 6: | ||
+ | <file> | ||
+ | execGRASS execute GRASS commands (when launched from R) | ||
+ | system execute GRASS commands (when launched from GRASS) | ||
+ | readRAST6 read GRASS raster files | ||
+ | writeRAST6 write GRASS raster files | ||
+ | readVECT6 read GRASS vector object files | ||
+ | writeVECT6 write GRASS vector object files | ||
+ | gmeta6 read GRASS metadata from the current LOCATION | ||
+ | getLocationProj return a PROJ.4 string of projection information | ||
+ | gmeta2grd create a GridTopology object from the GRASS region | ||
+ | vInfo return vector geometry information | ||
+ | vColumns return vector database columns information | ||
+ | vDataCount return count of vector database rows | ||
+ | vect2neigh return area neighbours with shared boundary length | ||
+ | </file> | ||
+ | |||
+ | Exemple de code dans R | ||
+ | |||
+ | <code> | ||
+ | library(spgrass6) | ||
+ | library(rgdal) | ||
+ | initGRASS(gisBase='/usr/lib/grass64',gisDbase='/home/glaroc/OSGIS/Day 2/',location='31h05',mapset='landsat',override=TRUE) | ||
+ | #Sous Windows, le chemin est du genre C:/GRASS/ | ||
+ | |||
+ | gmeta6() | ||
+ | elevp=readVECT6('Elevation_points') | ||
+ | |||
+ | RegHyd=readVECT6('Region_hydrique') | ||
+ | #Routes=readVECT6('Routes') | ||
+ | execGRASS("g.list",type="vect") | ||
+ | plot(RegHyd,lwd=2,col='blue') | ||
+ | plot(elevp,pch=19,lwd=0.5,col='brown',cex=0.5,add=TRUE) | ||
+ | |||
+ | </code> | ||
+ | |||
+ | ====== Utiliser PostGIS avec QGIS ====== | ||
+ | |||
+ | Téléchargez PostgreSQL [[http://www.postgresql.org/download/|pour votre plate-forme]]. | ||
+ | |||
+ | Suivez les instructions pour configurer Postgres sur votre ordinateur, incluant la création d'un utilisateur. Assurez-vous que l'extension pour [[http://postgis.net/docs/manual-2.1/postgis_installation.html|PostGIS est installée]]. | ||
+ | |||
+ | Créer une base de données qui peut accueillir des objets spatiaux. Remplacer my_spatial_db par le nom de la base de données désiré. Ce code doit être exécuté dans PostgreSQL. | ||
+ | <file> | ||
+ | CREATE DATABASE my_spatial_db TEMPLATE=template_postgis | ||
+ | </file> | ||
+ | |||
+ | Pour importer des fichiers vectoriels dans la base de données, utilisez le plugin DBManager de QGIS. Vous devez configurer une nouvelle connexion à une base de données en spécifiant les informations spécifiques à votre configuration de PostgreSQL. | ||
+ | |||
+ | Type de requête possible: | ||
+ | <file> | ||
+ | SELECT avg(elevation) FROM elevation_points, section_vote_31h5_utm WHERE section_vote_31h5_utm.tri_cep= 'JACQUESCARTIER' AND ST_within(elevation_points.geom,section_vote_31h5_utm.geom) | ||
+ | </file> | ||
+ | |||
+ | Cette requête nous donnera l'élévation moyenne pour tous les points d'élévation situés dans le district Jacques-Cartier. | ||
+ | |||
+ | Vous pouvez accéder à la [[http://postgis.net/docs/manual-1.3/ch06.html|liste des fonctions spécifiques à PostGIS ici.]] |