-
Notifications
You must be signed in to change notification settings - Fork 47
/
preface.qmd
187 lines (150 loc) · 9.84 KB
/
preface.qmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
# Preface {.unnumbered}
**Geocomputation with Python** (*geocompy*) is motivated by the need for an introductory resource for working with geographic data with the most popular programming language in the world.
A unique selling point of the book is its cohesive and joined-up coverage of *both vector and raster* geographic data models and consistent learning curve.
We aim to *minimize surprises*, with each section and chapter building on the previous.
If you're just starting out with Python for working with geographic data, this book is an excellent place to start.
There are many resources on Python on 'GeoPython' but none that fill this need for an introductory resource that provides strong foundations for future work.
We want to avoid reinventing the wheel and provide something that fills an 'ecological niche' in the wider free and open source software for geospatial (FOSS4G) ecosystem.
Key features include:
1. Doing basic operations well
1. Integration of vector and raster datasets operations
1. Clear explanation of each line of code in the book to minimize surprises
<!-- 4. Exercises at the end of each chapter with reproducible and open solutions -->
1. Provision of lucid example datasets and meaningful operations to illustrate the applied nature of geographic research
This book is complementary with, and adds value to, other projects in the ecosystem, as highlighted in the following comparison between *Geocomputation with Python* and related GeoPython books:
- *Learning Geospatial Analysis with Python*[^book_1] and *Geoprocessing with Python*[^book_2] are books in this space that focus on processing spatial data using low-level Python interfaces for GDAL, such as the **gdal**, **gdalnumeric**, and **ogr** packages from **osgeo**. This approach requires writing more lines of code. We believe our approach is more "Pythonic" and future-proof, in light of development of packages such as **geopandas** and **rasterio**.
- *Introduction to Python for Geographic Data Analysis*[^book_3] (in progress) seeks to provide a general introduction to 'GIS in Python', with parts focusing on Python essentials, using Python with GIS, and case studies. Compared with this book, which is also open source, and is hosted at pythongis.org, *Geocomputation with Python* has a narrower scope (not covering spatial network analysis, for example) and more coverage of raster data processing and raster-vector interoperability.
- *Geographic Data Science with Python*[^book_4] is an ambitious project with chapters dedicated to advanced topics, with Chapter 4 on Spatial Weights getting into complex topics relatively early, for example.
- *Python for Geospatial Data Analysis*[^book_5] introduces a wide range of approaches to working with geospatial data using Python, including automation of proprietary and open-source GIS software, as well as standalone open source Python packages (which is what we focus on and explain comprehensively in our book). Geocompy is shorter, simpler and more introductory, and cover raster and vector data with equal importance.
[^book_1]: [https://www.packtpub.com/product/learning-geospatial-analysis-with-python/9781783281138](https://www.packtpub.com/product/learning-geospatial-analysis-with-python/9781783281138)
[^book_2]: [https://www.manning.com/books/geoprocessing-with-python](https://www.manning.com/books/geoprocessing-with-python)
[^book_3]: [https://pythongis.org](https://pythongis.org)
[^book_4]: [https://geographicdata.science/book/intro.html](https://geographicdata.science/book/intro.html)
[^book_5]: [https://www.oreilly.com/library/view/python-for-geospatial/9781098104788/](https://www.oreilly.com/library/view/python-for-geospatial/9781098104788/)
Another unique feature of the book is that it is part of a wider community.
*Geocomputation with Python* is a sister project of *Geocomputation with R*[^geocompr][@lovelace_geocomputation_2019], a book on geographic data analysis, visualization, and modeling using the R programming language that has 60+ contributors and an active community, not least in the associated Discord group[^geocompr_discord].
Links with the vibrant 'R-spatial' community, and other communities such as GeoRust and JuliaGeo, lead to many opportunities for mutual benefit across open source ecosystems.
[^geocompr]: [https://r.geocompx.org/](https://r.geocompx.org/)
[^geocompr_discord]: [https://discord.gg/PMztXYgNxp](https://discord.gg/PMztXYgNxp)
## Prerequisites
We assume that the reader is:
* familiar with the Python language,
* is capable of running Python code and install Python packages, and
* is familiar with the `numpy` and `pandas` packages for working with data in Python.
From that starting point on, the book introduces the topic of working with *spatial data* in Python, through dedicated third-party packages---most importantly `geopandas` and `rasterio`.
We also assume familiarity with theoretical concepts of geographic data and GIS, such as coordinate systems, projections, spatial layer file formats, etc., which is necessary for understanding the reasoning of the examples.
## Code and sample data
To run the code examples, you can download[^book_data_zip] the ZIP file of the GitHub repository. In the ZIP file, the `ipynb` directory contains the source files of the chapters in Jupyter Notebook format, the `data` directory contains the sample data files, and the `output` directory contains the files created in code examples (some of which are also used as inputs in other code sections). Place them together as follows to run the code:
[^book_data_zip]: [https://github.com/geocompx/geocompy/zipball/master](https://github.com/geocompx/geocompy/zipball/master)
```text
├── data
│ ├── aut.tif
│ ├── ch.tif
│ ├── coffee_data.csv
│ ├── cycle_hire.gpkg
│ ├── cycle_hire_osm.gpkg
│ ├── cycle_hire_xy.csv
│ ├── dem.tif
│ ├── landsat.tif
│ ├── nlcd.tif
│ ├── nz_elev.tif
│ ├── nz.gpkg
│ ├── nz_height.gpkg
│ ├── seine.gpkg
│ ├── srtm.tif
│ ├── us_states.gpkg
│ ├── world.gpkg
│ ├── world_wkt.csv
│ ├── zion.gpkg
│ └── zion_points.gpkg
├── output
│ ├── cycle_hire_xy.csv
│ ├── dem_agg5.tif
│ ├── dem_contour.gpkg
│ ├── dem_resample_maximum.tif
│ ├── dem_resample_nearest.tif
│ ├── elev.tif
│ ├── grain.tif
│ ├── map.html
│ ├── ne_10m_airports.cpg
│ ├── ne_10m_airports.dbf
│ ├── ne_10m_airports.prj
│ ├── ne_10m_airports.README.html
│ ├── ne_10m_airports.shp
│ ├── ne_10m_airports.shx
│ ├── ne_10m_airports.VERSION.txt
│ ├── ne_10m_airports.zip
│ ├── nlcd_4326_2.tif
│ ├── nlcd_4326.tif
│ ├── nlcd_modified_crs.tif
│ ├── plot_geopandas.jpg
│ ├── plot_rasterio2.svg
│ ├── plot_rasterio.jpg
│ ├── r3.tif
│ ├── r_nodata_float.tif
│ ├── r_nodata_int.tif
│ ├── r.tif
│ ├── srtm_32612_aspect.tif
│ ├── srtm_32612_slope.tif
│ ├── srtm_32612.tif
│ ├── srtm_masked_cropped.tif
│ ├── srtm_masked.tif
│ ├── w_many_features.gpkg
│ ├── w_many_layers.gpkg
│ └── world.gpkg
├── 01-spatial-data.ipynb
├── 02-attribute-operations.ipynb
├── 03-spatial-operations.ipynb
├── 04-geometry-operations.ipynb
├── 05-raster-vector.ipynb
├── 06-reproj.ipynb
├── 07-read-write.ipynb
└── 08-mapping.ipynb
```
## Software
Python version used when rendering the book:
```{python}
#| echo: false
import sys
print(sys.version)
```
Versions of the main packages used in the book:
```{python}
#| echo: false
import subprocess
packages = [
'numpy',
'pandas',
'shapely',
'geopandas',
'rasterio',
'matplotlib',
'rasterstats'
]
result = ''
for i in packages:
x = 'pip freeze | grep ^%s==' % i
result += subprocess.run(x, shell=True, executable='/bin/bash', capture_output=True, text=True).stdout
print(result)
# Run micromamba list to get all installed packages and their versions
# cmd = "micromamba list -n geocompy"
# result = subprocess.run(cmd, shell=True, executable='/bin/bash', capture_output=True, text=True).stdout
# # Filter the result for the packages of interest
# filtered_result = ""
# lines = result.split('\n')
# # Skip all lines up to and including the header separator line
# start_index = next((i for i, line in enumerate(lines) if '─' in line), -1) + 1
# for line in lines[start_index:]:
# if line.strip(): # Ensure the line is not empty
# parts = line.split()
# package_name = parts[0] # Assuming package name is the first element
# if package_name in packages:
# version = parts[1] if len(parts) > 1 else "Unknown Version"
# filtered_result += f"{package_name} {version}\n"
# print(filtered_result)
```
## Acknowlegements
We acknowledge Robin Lovelace, Jakub Nowosad, and Jannes Muenchow---authors of *Geocomputation with R* (Robin and Jakub also author the present book), a book on the same topic for a different programming language (R). The structure, topics, and most of the theoretical discussions were adapted from that earlier publication.
We thank the authors of the Python language, and the authors of the **numpy**, **pandas**, **shapely**, **geopandas**, and **rasterio** packages which are used extensively in the book, for building these wonderful tools.
We acknowledge of GitHub users Will Deakin, Sean Gillies, Josh Cole, and Jt Miclat (at the time of writing; full list on GitHub[^github_contributors]) for their contributions during the open-source development of the book.
[^github_contributors]: [https://github.com/geocompx/geocompy/graphs/contributors](https://github.com/geocompx/geocompy/graphs/contributors)