SlideShare ist ein Scribd-Unternehmen logo
1 von 23
Downloaden Sie, um offline zu lesen
©	
  Sensorly	
  Confiden.al
Hang Khuc
Pôle études et statistiques
1
CaRtogRaphie avec R
!
2014-06-18
©	
  Sensorly	
  Confiden.al
2
©	
  Sensorly	
  Confiden.al
3
1
Qu’est ce que la cartographie ? 
Les données spatiales ?
©	
  Sensorly	
  Confiden.al
4
1 Cartographie et données spatiales
Selon Wikipédia

 « La cartographie désigne la réalisation et l’étude des cartes géographiques et
géologiques. (…) Le principe majeur de la cartographie est la représentation de données
(…). L’objectif de la carte est d’offrir une représentation concise et efficace permettant la
simplification de phénomènes complexes pour une compréhension rapide et pertinente. »
!
Les données spatiales 
• Célèbre jeu de données : emplacement où ont eu lieu les crimes et délits à Chicago ;
• Répliques de tremblements de terre sont détectés et leur latitude, longitude et l'heure
de l'événement sont enregistrées ;
• La localisation des personnes touchées par une maladie pour étudier la propagation
de la maladie et retrouver son origine : Légionellose à Québec en 2012.
• Votre localisation lors d’un post sur Facebook ou Twitter ;
• Le lieu public où vous vous trouvez lorsque vous faites un check-in dans Foursquare ;
• Niveau de signal capté par votre smartphone lorsque vous contribuez à notre
application ;
• Les données OSM : Prolifération des services de géolocalisation : trouver l’arrêt
de métro le plus proche, afficher un itinéraire, chercher une pharmacie, un magasin,
etc.
!
!

 
 
 
 
 
 
 Les données spatiales sont partout !
©	
  Sensorly	
  Confiden.al
5
!
1. Création du fond de carte
!
!
2. Sélection de l’information
!
!
3. Choix du type de représentation
!
!
4. Définition des éléments à faire apparaître sur la carte
!
!
But : Proposer une lecture spatialisée du phénomène pour
mieux comprendre son mécanisme
!
2 Data visualisation
©	
  Sensorly	
  Confiden.al
6
2
Les données spatiales à la loupe
©	
  Sensorly	
  Confiden.al
7
1 Coordonnées géographiques
Situer un point géographique sur le globe terrestre revient à attribuer des
coordonnées à un objet dans un repère lié à la Terre :
• coordonnées polaires et ses variantes : N 43°51’45.6" E 03°48'28.3"
• avec coordonnées latitude-longitude : latitude=48.84262 longitude=2.291257
• avec 3 dimensions x,y et z : x=718.260 y=174.690
!
!
!
!
!
!
!
!
!
Une valeur de coordonnées est toujours situé dans un système géodésique de
référence terrestre (Coordiante Reference System - CRS)
©	
  Sensorly	
  Confiden.al
8
Les systèmes géodésiques/de projection les plus couramment utilisés reposent sur
une représentation ellipsoïde de la Terre.
Par exemple, pour représenter la Terre on utilise le système géodésique mondial
dit WGS-84.
!
La représentation de la France que l’on utilise est celle du Lambert-93 qui utilise
une projection conique de la Terre.
!
Chaque système a un code unique appelé code EPSG (European Petroleum Survey
Group) :

 - WGS-84 : 4326

 - Lambert-93 : 2154

 - Lambert-92 étendu : 27572
!
Attention, il peut exister des différences pouvant aller jusqu’à plusieurs centaines
de mètres entre deux systèmes.
!
Transformation de la coordonnée : passer d’un système de référence à un autre.

 - En utilisant les formules mathématiques de transformation

 - Fonction spTransform du package rgdal

 
 
 
 
 spTransform(…,CRS(« +init=epsg:27572"))
2 Les projections
©	
  Sensorly	
  Confiden.al
9
3
Un exemple de use case
©	
  Sensorly	
  Confiden.al
10
Pour chaque restaurant que j’ai fréquenté :

 - Date

 - Nom

 - Coordonnées géographiques latitude/longitude

 - Le temps approximatif que j’ai passé dans ce restaurant

 - La note que j’ai attribué à la nourriture que j’ai pu gouter
1 Données
date nom la.tude longitude tps note
02/01/2014 indien 48.842617 2.291257 00:45:00 3
13/01/2014 espagnol 48.846107 2.303054 03:00:00 5
02/02/2014 italien_1 48.861085 2.300355 01:30:00 4
08/02/2014 libanais 48.871137 2.334830 01:15:00 3
22/02/2014 sushi_1 48.860052 2.350237 00:50:00 3
©	
  Sensorly	
  Confiden.al
11
« This package serves two purposes: "
" (i) Provide a comfortable R interface to query the Google server for static maps, "
" (ii) Use the map as a background image to overlay plots within R. "
This requires proper coordinate scaling. »"
!
RgoogleMaps sert donc à faire des cartes statiques. Choix :

 - Type de fond de carte : roadmap, terrain, mobile, satellite

 - Couleur ou noir et blanc

 - Carte centrée : qbbox (quantile bounding box) et niveau de zoom

 - Tracer :

 
 - des points

 - des pie charts

 - polygone

 - à partir d’un shape

 - une image raster

 - courbes de béziers
- Ajouter 

 - un texte

 - une légende
- Et pleins d’autres choses !
2 Data visualisation avec RgoogleMaps
©	
  Sensorly	
  Confiden.al
12
3 Chargement d’une carte (1/2)
# Chargement de la carte	
	bbox<-qbbox(lat= meetup$latitude,lon= meetup$longitude)	
	nzoom<-min(MaxZoom(bbox$latR,bbox$lonR,size=c(640,640)))-1	
	MyMap1<-GetMap(center=c(mean(bbox$latR),mean(bbox
$lonR)),zoom=nzoom,maptype="roadmap",destfile=paste("carte.png",sep=""))	
	MyMap2<-GetMap(center=c(mean(bbox$latR),mean(bbox
$lonR)),zoom=nzoom,maptype="terrain",destfile=paste("carte.png",sep=""))	
	MyMap3<-GetMap(center=c(mean(bbox$latR),mean(bbox
$lonR)),zoom=nzoom,maptype="satellite",destfile=paste("carte.png",sep=""))	
	MyMapBW<-GetMap(center=c(mean(bbox$latR),mean(bbox
$lonR)),zoom=nzoom,maptype="mobile",destfile=paste("carte.png",sep=""),GRAYSCA
LE=T)	
		
		
	PlotOnStaticMap(MyMap1,mar=rep(1,4))	
	title("Roadmap",cex.main=0.8)	
	PlotOnStaticMap(MyMap2,mar=rep(1,4))	
	title("Terrain",cex.main=0.8)	
	PlotOnStaticMap(MyMap3,mar=rep(1,4))	
	title("Satellite",cex.main=0.8)	 	
	PlotOnStaticMap(MyMapBW,mar=rep(1,4))	
	title("Mobile noir et blanc",cex.main=0.8)
©	
  Sensorly	
  Confiden.al
13
3 Chargement d’une carte (2/2)Roadmap Terrain
Satellite Mobile noir et blanc
©	
  Sensorly	
  Confiden.al
14
# Avec PlotOnStaticMap	
PlotOnStaticMap(MyMapBW,lat=meetup$latitude,lon=meetup
$longitude,pch=21,bg="#8073ac80",col="#2d004b",cex=2)	
!
# Avec les markers	
mmarkers<-NULL	
for (i in 1:nrow(meetup)){	
	mm<-paste0("&markers=color:green|
label:",LETTERS[i],"|",meetup[i,"latitude"],",",meetup[i,"longitude"])	
	mmarkers<-paste0(mmarkers,mm)	
}	
!
> &markers=color:green|label:A|48.842617,2.291257&markers=color:green|
label:B|48.846107,2.303054&markers=color:green|label:C|
48.861085,2.300355 (…)	
!
!
MyMapMK<-GetMap(center=c(mean(bbox$latR),mean(bbox
$lonR)),zoom=nzoom,maptype=« mobile",destfile=paste("carte.png",sep=""),
markers=mmarkers)	
	PlotOnStaticMap(MyMapMK)
4 Localiser les restaurants (1/2)
©	
  Sensorly	
  Confiden.al
15
4 Localiser les restaurants (2/2)
©	
  Sensorly	
  Confiden.al
16
Dessiner des piecharts (1/3)5
# Réorganiser les données	
!
date nom latitude longitude tps note	
1 02/01/2014 indien 48.84262 2.291257 00:45:00 3	
2 13/01/2014 espagnol 48.84611 2.303054 03:00:00 5	
3 02/02/2014 italien_1 48.86109 2.300355 01:30:00 4 	
4 08/02/2014 libanais 48.87114 2.334830 01:15:00 3 	
5 22/02/2014 sushi_1 48.86005 2.350237 00:50:00 3 	
6 16/03/2014 francais_1 48.87097 2.334089 02:10:00 5 	
7 24/03/2014 espagnol 48.84611 2.303054 02:30:00 5 	
8 03/04/2014 coreen 48.86620 2.336010 02:20:00 5 	
9 11/04/2014 italien_2 48.87283 2.341554 01:15:00 1 	
10 18/04/2014 francais 48.86673 2.365907 02:30:00 4 	
11 19/04/2014 espagnol 48.84611 2.303054 02:10:00 3 	
12 04/05/2014 francais_2 48.83559 2.329515 03:15:00 5 	
13 09/05/2014 creperie 48.84358 2.321071 01:35:00 4 	
14 21/05/2014 coreen 48.86620 2.336010 01:05:00 4 	
15 29/02/2014 indien 48.84262 2.291257 00:30:00 3 	
!
©	
  Sensorly	
  Confiden.al
17
# Choix des couleurs	
couleur<-paste0(brewer.pal(11,"Paired")	
!
# Mise en forme du temps passé	
	tps<-hms(meetup$tps)	
	meetup$tps_sec<-hour(tps)*3600+minute(tps)*60+seconds(tps)		
!
# Temps moyen passé dans chaque restaurant	
	aa<-melt(meetup[,c("nom","tps_sec")],id="nom")	
	bb<-dcast(aa,nom~variable,value.var="value",mean)	
	cc<-meetup[!duplicated(meetup$nom),c("nom","latitude","longitude")]	
	dd<-merge(cc,bb,by=« nom")	
!
# Représentation graphique	
PlotOnStaticMap(MyMapBW)	
!for (n in 1:nrow(dd)){!
!! newcoord<-
LatLon2XY.centered(MyMapBW,lat=dd[n,"latitude"],lon=dd[n,"longitude"],zoom=nzoom)!!
!! r<-dd[n,"tps_sec"]/500!! ! !
!! floating.pie(xpos=newcoord$newX,newcoord
$newY,x=100,radius=r,col=paste0(couleur[n],"95"),border=couleur[n],lwd=2)!
!! shadowtext(newcoord$newX,newcoord$newY-(6+r),paste(round(dd[n,"tps_sec"]/3600,0),"
h",sep=""),cex=0.6,col="white",bg="blue")!
!}!
!
# Rajout d’une légende	
	legend("topleft",legend=dd$nom,col=couleur,lwd=10,bg="white")
5 Dessiner des piecharts (2/3)
©	
  Sensorly	
  Confiden.al
18
5 Dessiner des piecharts (3/3)
2 h2 h2 h2 h2 h2 h2 h2 h2 h
2 h2 h2 h2 h2 h2 h2 h2 h2 h
3 h3 h3 h3 h3 h3 h3 h3 h3 h
2 h2 h2 h2 h2 h2 h2 h2 h2 h
2 h2 h2 h2 h2 h2 h2 h2 h2 h
3 h3 h3 h3 h3 h3 h3 h3 h3 h
1 h1 h1 h1 h1 h1 h1 h1 h1 h
2 h2 h2 h2 h2 h2 h2 h2 h2 h
1 h1 h1 h1 h1 h1 h1 h1 h1 h
1 h1 h1 h1 h1 h1 h1 h1 h1 h
1 h1 h1 h1 h1 h1 h1 h1 h1 h
coreen
creperie
espagnol
francais
francais_1
francais_2
indien
italien_1
italien_2
libanais
sushi_1
©	
  Sensorly	
  Confiden.al
19
# Enveloppe convexe	
tr<-tri.mesh(cc[,"longitude"], cc[,"latitude"])	
trch<-convex.hull(tr)	
trch	
!
> $x	
[1] 2.291257 2.329515 2.365907 2.341554 2.334089 2.300355	
!
$y	
[1] 48.84262 48.83559 48.86673 48.87283 48.87097 48.86109	
!
$i	
[1] 1 10 9 8 6 3	
!
!
# Mise en forme des données	
mypolygon<-data.frame(trch$x,trch$y)	
colnames(mypolygon)<-c(« X","Y")	
!
# Représentation graphique	
PlotOnStaticMap(MyMapBW)	
	PlotPolysOnStaticMap(MyMapBW, mypolygon,add=T,col=paste0("#66bd63","40"),lwd=.5,
border="#a6d96a")	
6 Polygones (1/2)
©	
  Sensorly	
  Confiden.al
20
6 Polygones (1/2)
©	
  Sensorly	
  Confiden.al
21
7 Image raster (1/2)
# Importation des png	
	content<-readPNG("sticker-smiley-content.png")	
	pascontent<-readPNG("smiley-pascontent.png")	
	pouce<-readPNG("Smiley_pouce.png")	
!
# Note moyenne pour chaque restaurant	
	aa<-melt(meetup[,c("nom","note")],id="nom")	
	bb<-dcast(aa,nom~variable,value.var="value",mean)	
	cc<-meetup[!duplicated(meetup$nom),c("nom","latitude","longitude")]	
	dd<-merge(cc,bb,by="nom")	
!
# Représentation graphique	
	PlotOnStaticMap(MyMapBW)	
	for (i in 1:nrow(dd)){	
		 if (dd[i,"note"]<=3){	
		 	 nomsmiley<-"pascontent"	
		 } else {	
		 	 if (dd[i,"note"]==5) {	
		 	 	 nomsmiley <-"pouce"	
		 	 } else {	
		 	 	 nomsmiley <-"content"	
		 	 }	
		 }	
		 Rcoords0<-LatLon2XY.centered(MyMapBW,dd[i,"latitude"],dd[i,"longitude"])	
		 x<-Rcoords0$newX	
		 y<-Rcoords0$newY	
		 rasterImage(get(nomsmiley),x,y,x+60,y+60)	
}
©	
  Sensorly	
  Confiden.al
22
7 Image raster (1/2)
©	
  Sensorly	
  Confiden.al
Hang Khuc
Pôle études et statistiques
23
On recrute
Java Platform Engineer
!
https://www.linkedin.com/jobs2/view/10976225
!
!
Merci !!!!!

Weitere ähnliche Inhalte

Empfohlen

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

Empfohlen (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

CaRtogRaphie avec R

  • 1. ©  Sensorly  Confiden.al Hang Khuc Pôle études et statistiques 1 CaRtogRaphie avec R ! 2014-06-18
  • 3. ©  Sensorly  Confiden.al 3 1 Qu’est ce que la cartographie ? Les données spatiales ?
  • 4. ©  Sensorly  Confiden.al 4 1 Cartographie et données spatiales Selon Wikipédia « La cartographie désigne la réalisation et l’étude des cartes géographiques et géologiques. (…) Le principe majeur de la cartographie est la représentation de données (…). L’objectif de la carte est d’offrir une représentation concise et efficace permettant la simplification de phénomènes complexes pour une compréhension rapide et pertinente. » ! Les données spatiales • Célèbre jeu de données : emplacement où ont eu lieu les crimes et délits à Chicago ; • Répliques de tremblements de terre sont détectés et leur latitude, longitude et l'heure de l'événement sont enregistrées ; • La localisation des personnes touchées par une maladie pour étudier la propagation de la maladie et retrouver son origine : Légionellose à Québec en 2012. • Votre localisation lors d’un post sur Facebook ou Twitter ; • Le lieu public où vous vous trouvez lorsque vous faites un check-in dans Foursquare ; • Niveau de signal capté par votre smartphone lorsque vous contribuez à notre application ; • Les données OSM : Prolifération des services de géolocalisation : trouver l’arrêt de métro le plus proche, afficher un itinéraire, chercher une pharmacie, un magasin, etc. ! ! Les données spatiales sont partout !
  • 5. ©  Sensorly  Confiden.al 5 ! 1. Création du fond de carte ! ! 2. Sélection de l’information ! ! 3. Choix du type de représentation ! ! 4. Définition des éléments à faire apparaître sur la carte ! ! But : Proposer une lecture spatialisée du phénomène pour mieux comprendre son mécanisme ! 2 Data visualisation
  • 6. ©  Sensorly  Confiden.al 6 2 Les données spatiales à la loupe
  • 7. ©  Sensorly  Confiden.al 7 1 Coordonnées géographiques Situer un point géographique sur le globe terrestre revient à attribuer des coordonnées à un objet dans un repère lié à la Terre : • coordonnées polaires et ses variantes : N 43°51’45.6" E 03°48'28.3" • avec coordonnées latitude-longitude : latitude=48.84262 longitude=2.291257 • avec 3 dimensions x,y et z : x=718.260 y=174.690 ! ! ! ! ! ! ! ! ! Une valeur de coordonnées est toujours situé dans un système géodésique de référence terrestre (Coordiante Reference System - CRS)
  • 8. ©  Sensorly  Confiden.al 8 Les systèmes géodésiques/de projection les plus couramment utilisés reposent sur une représentation ellipsoïde de la Terre. Par exemple, pour représenter la Terre on utilise le système géodésique mondial dit WGS-84. ! La représentation de la France que l’on utilise est celle du Lambert-93 qui utilise une projection conique de la Terre. ! Chaque système a un code unique appelé code EPSG (European Petroleum Survey Group) : - WGS-84 : 4326 - Lambert-93 : 2154 - Lambert-92 étendu : 27572 ! Attention, il peut exister des différences pouvant aller jusqu’à plusieurs centaines de mètres entre deux systèmes. ! Transformation de la coordonnée : passer d’un système de référence à un autre. - En utilisant les formules mathématiques de transformation - Fonction spTransform du package rgdal spTransform(…,CRS(« +init=epsg:27572")) 2 Les projections
  • 10. ©  Sensorly  Confiden.al 10 Pour chaque restaurant que j’ai fréquenté : - Date - Nom - Coordonnées géographiques latitude/longitude - Le temps approximatif que j’ai passé dans ce restaurant - La note que j’ai attribué à la nourriture que j’ai pu gouter 1 Données date nom la.tude longitude tps note 02/01/2014 indien 48.842617 2.291257 00:45:00 3 13/01/2014 espagnol 48.846107 2.303054 03:00:00 5 02/02/2014 italien_1 48.861085 2.300355 01:30:00 4 08/02/2014 libanais 48.871137 2.334830 01:15:00 3 22/02/2014 sushi_1 48.860052 2.350237 00:50:00 3
  • 11. ©  Sensorly  Confiden.al 11 « This package serves two purposes: " " (i) Provide a comfortable R interface to query the Google server for static maps, " " (ii) Use the map as a background image to overlay plots within R. " This requires proper coordinate scaling. »" ! RgoogleMaps sert donc à faire des cartes statiques. Choix : - Type de fond de carte : roadmap, terrain, mobile, satellite - Couleur ou noir et blanc - Carte centrée : qbbox (quantile bounding box) et niveau de zoom - Tracer : - des points - des pie charts - polygone - à partir d’un shape - une image raster - courbes de béziers - Ajouter - un texte - une légende - Et pleins d’autres choses ! 2 Data visualisation avec RgoogleMaps
  • 12. ©  Sensorly  Confiden.al 12 3 Chargement d’une carte (1/2) # Chargement de la carte bbox<-qbbox(lat= meetup$latitude,lon= meetup$longitude) nzoom<-min(MaxZoom(bbox$latR,bbox$lonR,size=c(640,640)))-1 MyMap1<-GetMap(center=c(mean(bbox$latR),mean(bbox $lonR)),zoom=nzoom,maptype="roadmap",destfile=paste("carte.png",sep="")) MyMap2<-GetMap(center=c(mean(bbox$latR),mean(bbox $lonR)),zoom=nzoom,maptype="terrain",destfile=paste("carte.png",sep="")) MyMap3<-GetMap(center=c(mean(bbox$latR),mean(bbox $lonR)),zoom=nzoom,maptype="satellite",destfile=paste("carte.png",sep="")) MyMapBW<-GetMap(center=c(mean(bbox$latR),mean(bbox $lonR)),zoom=nzoom,maptype="mobile",destfile=paste("carte.png",sep=""),GRAYSCA LE=T) PlotOnStaticMap(MyMap1,mar=rep(1,4)) title("Roadmap",cex.main=0.8) PlotOnStaticMap(MyMap2,mar=rep(1,4)) title("Terrain",cex.main=0.8) PlotOnStaticMap(MyMap3,mar=rep(1,4)) title("Satellite",cex.main=0.8) PlotOnStaticMap(MyMapBW,mar=rep(1,4)) title("Mobile noir et blanc",cex.main=0.8)
  • 13. ©  Sensorly  Confiden.al 13 3 Chargement d’une carte (2/2)Roadmap Terrain Satellite Mobile noir et blanc
  • 14. ©  Sensorly  Confiden.al 14 # Avec PlotOnStaticMap PlotOnStaticMap(MyMapBW,lat=meetup$latitude,lon=meetup $longitude,pch=21,bg="#8073ac80",col="#2d004b",cex=2) ! # Avec les markers mmarkers<-NULL for (i in 1:nrow(meetup)){ mm<-paste0("&markers=color:green| label:",LETTERS[i],"|",meetup[i,"latitude"],",",meetup[i,"longitude"]) mmarkers<-paste0(mmarkers,mm) } ! > &markers=color:green|label:A|48.842617,2.291257&markers=color:green| label:B|48.846107,2.303054&markers=color:green|label:C| 48.861085,2.300355 (…) ! ! MyMapMK<-GetMap(center=c(mean(bbox$latR),mean(bbox $lonR)),zoom=nzoom,maptype=« mobile",destfile=paste("carte.png",sep=""), markers=mmarkers) PlotOnStaticMap(MyMapMK) 4 Localiser les restaurants (1/2)
  • 15. ©  Sensorly  Confiden.al 15 4 Localiser les restaurants (2/2)
  • 16. ©  Sensorly  Confiden.al 16 Dessiner des piecharts (1/3)5 # Réorganiser les données ! date nom latitude longitude tps note 1 02/01/2014 indien 48.84262 2.291257 00:45:00 3 2 13/01/2014 espagnol 48.84611 2.303054 03:00:00 5 3 02/02/2014 italien_1 48.86109 2.300355 01:30:00 4 4 08/02/2014 libanais 48.87114 2.334830 01:15:00 3 5 22/02/2014 sushi_1 48.86005 2.350237 00:50:00 3 6 16/03/2014 francais_1 48.87097 2.334089 02:10:00 5 7 24/03/2014 espagnol 48.84611 2.303054 02:30:00 5 8 03/04/2014 coreen 48.86620 2.336010 02:20:00 5 9 11/04/2014 italien_2 48.87283 2.341554 01:15:00 1 10 18/04/2014 francais 48.86673 2.365907 02:30:00 4 11 19/04/2014 espagnol 48.84611 2.303054 02:10:00 3 12 04/05/2014 francais_2 48.83559 2.329515 03:15:00 5 13 09/05/2014 creperie 48.84358 2.321071 01:35:00 4 14 21/05/2014 coreen 48.86620 2.336010 01:05:00 4 15 29/02/2014 indien 48.84262 2.291257 00:30:00 3 !
  • 17. ©  Sensorly  Confiden.al 17 # Choix des couleurs couleur<-paste0(brewer.pal(11,"Paired") ! # Mise en forme du temps passé tps<-hms(meetup$tps) meetup$tps_sec<-hour(tps)*3600+minute(tps)*60+seconds(tps) ! # Temps moyen passé dans chaque restaurant aa<-melt(meetup[,c("nom","tps_sec")],id="nom") bb<-dcast(aa,nom~variable,value.var="value",mean) cc<-meetup[!duplicated(meetup$nom),c("nom","latitude","longitude")] dd<-merge(cc,bb,by=« nom") ! # Représentation graphique PlotOnStaticMap(MyMapBW) !for (n in 1:nrow(dd)){! !! newcoord<- LatLon2XY.centered(MyMapBW,lat=dd[n,"latitude"],lon=dd[n,"longitude"],zoom=nzoom)!! !! r<-dd[n,"tps_sec"]/500!! ! ! !! floating.pie(xpos=newcoord$newX,newcoord $newY,x=100,radius=r,col=paste0(couleur[n],"95"),border=couleur[n],lwd=2)! !! shadowtext(newcoord$newX,newcoord$newY-(6+r),paste(round(dd[n,"tps_sec"]/3600,0)," h",sep=""),cex=0.6,col="white",bg="blue")! !}! ! # Rajout d’une légende legend("topleft",legend=dd$nom,col=couleur,lwd=10,bg="white") 5 Dessiner des piecharts (2/3)
  • 18. ©  Sensorly  Confiden.al 18 5 Dessiner des piecharts (3/3) 2 h2 h2 h2 h2 h2 h2 h2 h2 h 2 h2 h2 h2 h2 h2 h2 h2 h2 h 3 h3 h3 h3 h3 h3 h3 h3 h3 h 2 h2 h2 h2 h2 h2 h2 h2 h2 h 2 h2 h2 h2 h2 h2 h2 h2 h2 h 3 h3 h3 h3 h3 h3 h3 h3 h3 h 1 h1 h1 h1 h1 h1 h1 h1 h1 h 2 h2 h2 h2 h2 h2 h2 h2 h2 h 1 h1 h1 h1 h1 h1 h1 h1 h1 h 1 h1 h1 h1 h1 h1 h1 h1 h1 h 1 h1 h1 h1 h1 h1 h1 h1 h1 h coreen creperie espagnol francais francais_1 francais_2 indien italien_1 italien_2 libanais sushi_1
  • 19. ©  Sensorly  Confiden.al 19 # Enveloppe convexe tr<-tri.mesh(cc[,"longitude"], cc[,"latitude"]) trch<-convex.hull(tr) trch ! > $x [1] 2.291257 2.329515 2.365907 2.341554 2.334089 2.300355 ! $y [1] 48.84262 48.83559 48.86673 48.87283 48.87097 48.86109 ! $i [1] 1 10 9 8 6 3 ! ! # Mise en forme des données mypolygon<-data.frame(trch$x,trch$y) colnames(mypolygon)<-c(« X","Y") ! # Représentation graphique PlotOnStaticMap(MyMapBW) PlotPolysOnStaticMap(MyMapBW, mypolygon,add=T,col=paste0("#66bd63","40"),lwd=.5, border="#a6d96a") 6 Polygones (1/2)
  • 21. ©  Sensorly  Confiden.al 21 7 Image raster (1/2) # Importation des png content<-readPNG("sticker-smiley-content.png") pascontent<-readPNG("smiley-pascontent.png") pouce<-readPNG("Smiley_pouce.png") ! # Note moyenne pour chaque restaurant aa<-melt(meetup[,c("nom","note")],id="nom") bb<-dcast(aa,nom~variable,value.var="value",mean) cc<-meetup[!duplicated(meetup$nom),c("nom","latitude","longitude")] dd<-merge(cc,bb,by="nom") ! # Représentation graphique PlotOnStaticMap(MyMapBW) for (i in 1:nrow(dd)){ if (dd[i,"note"]<=3){ nomsmiley<-"pascontent" } else { if (dd[i,"note"]==5) { nomsmiley <-"pouce" } else { nomsmiley <-"content" } } Rcoords0<-LatLon2XY.centered(MyMapBW,dd[i,"latitude"],dd[i,"longitude"]) x<-Rcoords0$newX y<-Rcoords0$newY rasterImage(get(nomsmiley),x,y,x+60,y+60) }
  • 22. ©  Sensorly  Confiden.al 22 7 Image raster (1/2)
  • 23. ©  Sensorly  Confiden.al Hang Khuc Pôle études et statistiques 23 On recrute Java Platform Engineer ! https://www.linkedin.com/jobs2/view/10976225 ! ! Merci !!!!!