Skip to content

Commit

Permalink
Règle problème des cartes qui s'affichent pas (#165)
Browse files Browse the repository at this point in the history
* define ax

* là

* autres

* afficher chunk

* Automated changes

* update

* Automated changes

* tentative diff

* diff origin master

* try

* head

* cat file

* list new files

* rm subset

* Automated changes

* inversion ordre

* Automated changes

* update

* Automated changes

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
linogaliana and github-actions[bot] committed Oct 19, 2021
1 parent 6cdb336 commit 735e677
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 31 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/netlify-test.yaml
Expand Up @@ -37,6 +37,8 @@ jobs:
conda list
- name: Build to md
run: |
git diff --name-only origin/master origin/${GITHUB_HEAD_REF} >> diff.txt
cat diff.txt
Rscript -e 'source("./build/build_light.R")'
- name: Clean files with Python function
run: |
Expand Down
5 changes: 3 additions & 2 deletions build/build_light.R
@@ -1,7 +1,8 @@
content_rmd <- list.files("./content/course", recursive = TRUE, pattern = "*.Rmd", full.names = TRUE)
content_rmd <- readLines("diff.txt")
content_rmd <- content_rmd[startsWith(content_rmd, "content/course")]
content_rmd <- content_rmd[endsWith(content_rmd, ".Rmd")]
content_rmd <- content_rmd[!grepl("/git/", content_rmd)]
content_rmd <- content_rmd[!grepl("06a_exo_supp_webscraping.", content_rmd)]
content_rmd <- content_rmd[8:9]

file.remove(
gsub(
Expand Down
2 changes: 1 addition & 1 deletion content/course/manipulation/03_geopandas_TP.Rmd
Expand Up @@ -41,7 +41,7 @@ print_badges()

Installations préalables :

```{python, eval=FALSE, echo=TRUE}
```{python, eval=FALSE, echo=TRUE, include=TRUE}
!pip install pandas fiona shapely pyproj rtree # à faire obligatoirement en premier pour utiliser rtree ou pygeos pour les jointures spatiales
!pip install contextily
!pip install geopandas
Expand Down
94 changes: 66 additions & 28 deletions content/course/manipulation/03_geopandas_tutorial.Rmd
Expand Up @@ -243,7 +243,8 @@ du shapefile utilisé :
```{python}
paris = communes[communes.insee.str.startswith("75")]
ax = paris.plot(figsize=(10, 10), alpha=0.5, edgecolor='blue')
fig,ax = plt.subplots(figsize=(10, 10))
paris.plot(ax = ax, alpha=0.5, edgecolor='blue')
ctx.add_basemap(ax, crs = paris.crs.to_string())
ax.set_axis_off()
ax
Expand All @@ -262,7 +263,7 @@ knitr::include_graphics("map_paris1.png")
On voit ainsi que les données pour Paris ne comportent pas d'arrondissement,
ce qui est limitant pour une analyse focalisée sur Paris. On va donc les
récupérer sur le site d'open data de la ville de Paris et les substituer
à Paris
à Paris :

```{python}
arrondissements = gpd.read_file("https://opendata.paris.fr/explore/dataset/arrondissements/download/?format=geojson&timezone=Europe/Berlin&lang=fr")
Expand All @@ -276,7 +277,10 @@ espéré

```{python}
paris = communes[communes.insee.str.startswith("75")]
ax = paris.plot(figsize=(10, 10), alpha=0.5, edgecolor='k')
fig,ax = plt.subplots(figsize=(10, 10))
paris.plot(ax = ax, alpha=0.5, edgecolor='k')
ctx.add_basemap(ax, crs = paris.crs.to_string())
ax.set_axis_off()
ax
Expand Down Expand Up @@ -315,25 +319,59 @@ communes['dep'] = communes.insee.str[:2]

On peut se rassurer en affichant les données sur la carte des communes d'Île-de-France.

Découvrez ci-dessous par étape les différentes lignes de commandes permettant d'afficher une carte complète,
```{python, include = FALSE}
fig,ax = plt.subplots(figsize=(10, 10))
stations.sample(200).plot(ax = ax, color = 'red', alpha = 0.4, zorder=2)
communes[communes['dep'].isin(['75','92','93','94'])].plot(ax = ax, zorder=1, edgecolor = "black", facecolor="none",
color = None)
ctx.add_basemap(ax, crs = stations.crs.to_string(), source = ctx.providers.Stamen.Watercolor)
ax.set_axis_off()
ax
```

```{python, echo = FALSE, include = FALSE}
plt.tight_layout(pad=0, h_pad = 0)
plt.savefig('map1.png', bbox_inches='tight')
```

```{r, echo = FALSE}
knitr::include_graphics("map1.png")
```


Découvrez ci-dessous par étape les différentes lignes de commandes permettant d'afficher cette carte complète,
étape par étape:

1. Afficher le nuage de point de 200 stations vélibs prises au hasard
:one:
Afficher le nuage de points de 200 stations vélibs prises au hasard

```{python}
ax = stations.sample(200).plot(figsize = (10,10), color = 'red', alpha = 0.4, zorder=2)
```{python, include = FALSE}
fig,ax = plt.subplots(figsize=(10, 10))
stations.sample(200).plot(ax = ax, color = 'red', alpha = 0.4, zorder=2)
#communes[communes['dep'].isin(['75','92','93','94'])].plot(ax = ax, zorder=1, edgecolor = "black", facecolor="none",
# color = None)
#ctx.add_basemap(ax, crs = stations.crs.to_string(), source = ctx.providers.Stamen.Watercolor)
# ax.set_axis_off()
ax
```

```{python, echo = FALSE, include = FALSE}
plt.tight_layout(pad=0, h_pad = 0)
plt.show()
plt.savefig('map2aa.png', bbox_inches='tight')
```

```{r, echo = FALSE, include = FALSE}
knitr::include_graphics("map2aa.png")
```


:two:
Ajouter à cette couche, en dessous, les contours des communes

```{python}
ax = stations.sample(200).plot(figsize = (10,10), color = 'red', alpha = 0.4, zorder=2)
```{python, include = FALSE}
fig,ax = plt.subplots(figsize=(10, 10))
stations.sample(200).plot(ax = ax, color = 'red', alpha = 0.4, zorder=2)
communes[communes['dep'].isin(['75','92','93','94'])].plot(ax = ax, zorder=1, edgecolor = "black", facecolor="none",
color = None)
#ctx.add_basemap(ax, crs = stations.crs.to_string(), source = ctx.providers.Stamen.Watercolor)
Expand All @@ -343,19 +381,22 @@ ax

```{python, echo = FALSE, include = FALSE}
plt.tight_layout(pad=0, h_pad = 0)
plt.show()
plt.savefig('map2a.png', bbox_inches='tight')
```

```{r, echo = FALSE}
```{r, echo = FALSE, include = FALSE}
knitr::include_graphics("map2a.png")
```


3. Ajouter un fond de carte de type *open street map* grâce au package
:three:
Ajouter un fond de carte de type *open street map* grâce au package
`contextily`

```{python}
ax = stations.sample(200).plot(figsize = (10,10), color = 'red', alpha = 0.4, zorder=2)
```{python, include = FALSE}
fig,ax = plt.subplots(figsize=(10, 10))
stations.sample(200).plot(ax = ax, color = 'red', alpha = 0.4, zorder=2)
communes[communes['dep'].isin(['75','92','93','94'])].plot(ax = ax, zorder=1, edgecolor = "black", facecolor="none",
color = None)
ctx.add_basemap(ax, crs = stations.crs.to_string(), source = ctx.providers.Stamen.Watercolor)
Expand All @@ -372,28 +413,21 @@ plt.savefig('map3a.png', bbox_inches='tight')
knitr::include_graphics("map3a.png")
```

:four:
Ne reste plus qu'à retirer l'axe des coordonnées, qui n'est pas très
esthétique. Pour cela:

```{python}
ax = stations.sample(200).plot(figsize = (10,10), color = 'red', alpha = 0.4, zorder=2)
```{python, include = FALSE, eval = FALSE}
fig,ax = plt.subplots(figsize=(10, 10))
stations.sample(200).plot(ax = ax, color = 'red', alpha = 0.4, zorder=2)
communes[communes['dep'].isin(['75','92','93','94'])].plot(ax = ax, zorder=1, edgecolor = "black", facecolor="none",
color = None)
ctx.add_basemap(ax, crs = stations.crs.to_string(), source = ctx.providers.Stamen.Watercolor)
ax.set_axis_off()
ax
```

*In fine*, on obtient la carte ci-dessous:

```{python, echo = FALSE, include = FALSE}
plt.tight_layout(pad=0, h_pad = 0)
plt.savefig('map1.png', bbox_inches='tight')
```

```{r, echo = FALSE}
knitr::include_graphics("map1.png")
```
*In fine*, on obtient la carte désirée.


## Opérations sur les attributs
Expand Down Expand Up @@ -433,7 +467,8 @@ attribus avec la méthode `dissolve`:


```{python}
ax = communes[communes.dep != "97"].dissolve(by='dep', aggfunc='sum').plot(column = "surf_ha")
fig,ax = plt.subplots(figsize=(10, 10))
communes[communes.dep != "97"].dissolve(by='dep', aggfunc='sum').plot(ax = ax, column = "surf_ha")
ax.set_axis_off()
ax
```
Expand Down Expand Up @@ -569,7 +604,8 @@ communes = communes.set_crs(2154)
Alors que la reprojection (projection Albers: 5070) s'obtient de la manière suivante:

```{python}
ax = communes[communes.dep != "97"].dissolve(by='dep', aggfunc='sum').to_crs(5070).plot()
fig,ax = plt.subplots(figsize=(10, 10))
communes[communes.dep != "97"].dissolve(by='dep', aggfunc='sum').to_crs(5070).plot(ax = ax)
ax
```

Expand All @@ -595,7 +631,9 @@ nord-américain (et encore, pas dans son ensemble !).

```{python, eval = TRUE}
world = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))
ax = world[world.continent == "North America"].to_crs(5070).plot(alpha = 0.2, edgecolor = "k")
fig,ax = plt.subplots(figsize=(10, 10))
world[world.continent == "North America"].to_crs(5070).plot(alpha = 0.2, edgecolor = "k", ax = ax)
ax
```

Expand Down

0 comments on commit 735e677

Please sign in to comment.