Skip to content

Commit 2451313

Browse files
authored
Merge pull request #20 from pdallago97/master
Replaced conda with pixi
2 parents 79e26f9 + af319c4 commit 2451313

1 file changed

Lines changed: 16 additions & 28 deletions

File tree

‎index.Rmd‎

Lines changed: 16 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -41,39 +41,26 @@ Today we will explore a variety of Python packages for vector data handling:
4141
- Be able to plot spatial vector data with Matplotlib
4242

4343
## Setting up the Python Environment
44-
45-
Make a directory structure for this tutorial:
44+
Open Positron and create a new directory for this tutorial using pixi:
4645

4746
```{r, eval=FALSE,engine='bash'}
4847
cd ~/Documents/
49-
mkdir PythonVector #or give the directory a name to your liking
50-
cd ./PythonVector
51-
mkdir data
52-
mkdir output
48+
pixi init PythonVector #or give the directory a name to your liking
5349
```
5450

55-
The conda environment we are using today contains more (and larger) packages than yesterday, but the process we use to create and activate it is the same. Create a text file, (re)name it (to) `vector.yaml`, and copy the following content into the file:
51+
The environment we are using today contains more (and larger) packages than yesterday, but the process we use to create and activate it is the same. Add the following packages into the environment:
5652

5753
```
58-
name: vector
59-
dependencies:
60-
- matplotlib
61-
- spyder
62-
- gdal
63-
- shapely
64-
- geopandas=>1.0
65-
- owslib
66-
- osmnx
67-
- contextily
54+
pixi add matplotlib spyder gdal shapely geopandas>=1.0 owslib osmnx contextily
6855
```
6956

70-
Now, create the environment with:
57+
Activate the shell:
7158

72-
```{r, eval=FALSE,engine='bash'}
73-
mamba env create --file vector.yaml
59+
```
60+
pixi shell
7461
```
7562

76-
Activate the environment, open Spyder, create a script in the root directory and start coding.
63+
Then create a script in the root directory and start coding.
7764

7865
# Vector Geometries and Python
7966

@@ -441,7 +428,8 @@ newBuildingsGDF = newBuildingsGDF.to_crs(epsg=3857)
441428
442429
# Plot with 50% transparency
443430
ax = newBuildingsGDF.plot(figsize=(10, 10), alpha=0.5, edgecolor='k')
444-
ctx.add_basemap(ax, source=ctx.providers.OpenStreetMap.Mapnik, zoom=17)
431+
#Load basemap
432+
ctx.add_basemap(ax, zoom=17) #Basemap can be adjusted using the 'source' argument of add_basemap()
445433
ax.set_axis_off()
446434
```
447435

@@ -558,17 +546,17 @@ import osmnx as ox
558546
559547
# Using a geocoder to get the extent
560548
city = ox.geocoder.geocode_to_gdf('Wageningen, Netherlands')
561-
ox.plot.plot_footprints(ox.project_gdf(city), color='lightblue', bgcolor='#FFFFFF',
562-
alpha=0.8, edge_color='grey', edge_linewidth=2)
549+
city.plot(color = 'lightblue', edgecolor = 'grey', linewidth = 0.5, alpha = 0.8)
550+
563551
# Get bike network and create graph
564552
wageningenRoadsGraph = ox.graph.graph_from_place('Wageningen, Netherlands', network_type='bike')
565553
566554
# Plot and save
567555
ox.plot.plot_graph(wageningenRoadsGraph, figsize=(10, 10), node_size=2)
568-
ox.io.save_graph_shapefile(G=wageningenRoadsGraph, filepath='data/OSMnetwork_Wageningen.shp')
556+
gdf_nodes, gdf_edges = ox.graph_to_gdfs(G=wageningenRoadsGraph)
557+
gdf_edges.to_file('./output/OSMnetwork_Wageningen.shp', driver='ESRI Shapefile')
569558
570559
# Metadata
571-
gdf_nodes, gdf_edges = ox.graph_to_gdfs(G=wageningenRoadsGraph)
572560
print(gdf_nodes.info())
573561
print(gdf_edges.info())
574562
```
@@ -608,8 +596,8 @@ Folium uses leaflet on the backend to make web maps, easily visualized on a webp
608596
```{Python, eval=FALSE}
609597
import folium
610598
611-
# Initialize the map
612-
campusMap = folium.Map([51.98527485, 5.66370505205543], zoom_start=17)
599+
# Initialize the map with satellite basemap
600+
campusMap = folium.Map([51.98527485, 5.66370505205543], tiles = "https://server.arcgisonline.com/ArcGIS/rest/services/""World_Imagery/MapServer/tile/{z}/{y}/{x}", attr = "Tiles © ESRI", zoom_start=17)
613601
614602
# Re-project
615603
buildingsGDF = buildingsGDF.to_crs(4326)

0 commit comments

Comments
 (0)