Skip to content

Commit

Permalink
GA build of book HTML
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Jun 1, 2024
1 parent ea73eb1 commit bd15ce6
Show file tree
Hide file tree
Showing 49 changed files with 108 additions and 104 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ _**Figure 5.2.** Vector and raster representations of roads and buildings._

### Geometry types

The most fundamental geometric objects when working with spatial data in vector format are **points**, **lines** and **areas**. Figure 5.3 represents the vector data model and illustrates the variety of geometric objects that are available. `Point` -object represents a single point in geographic space and the location of the point in space is determined with coordinates. Points can be either two-dimensional (with x, y -coordinates) or three dimensional (with x, y, and z coordinates). A single pair of coordinates forming a point is commonly called as *`coordinate`* *{term}`tuple`*. `LineString` -object (i.e. a line) represents a sequence of points joined together to form a line. Hence, a line consist of a list of at least two coordinate tuples. `Polygon` -object represents a filled area that consists of a list of at least three coordinate tuples that forms the outerior ring (called `LinearRing`) and a possible list of holes (as seen in the last plot of Figure 5.3) It is also possible to have a collection of geometric objects (i.e. multiple points, lines or areas) represented as `MultiPoint`, `MultiLineString` and `MultiPolygon` as shown in the bottom row of Figure 5.3. Geometry collections can be useful for example when you want to present multiple building polygons belonging to the same property as a single entity (like a Finnish summer house that typically has a separate sauna building). In addition to these, you might sometimes hear about other geometry objects, such as `Curve`, `Surface` or `GeometryCollection`, but these are basically implemented by the same `Point`, `LineString` and `Polygon` geometry types, hence we don't really use them in practice.
The most fundamental geometric objects when working with spatial data in vector format are **points**, **lines** and **areas**. Figure 5.3 represents the vector data model and illustrates the variety of geometric objects that are available. `Point` -object represents a single point in geographic space and the location of the point in space is determined with coordinates. Points can be either two-dimensional (with x, y -coordinates) or three dimensional (with x, y, and z coordinates). A single pair of coordinates forming a point is commonly called as a *`coordinate`* *{term}`tuple`*. `LineString` -object (i.e. a line) represents a sequence of points joined together to form a line. Hence, a line consist of a list of at least two coordinate tuples. `Polygon` -object represents a filled area that consists of a list of at least three coordinate tuples that forms the outerior ring (called `LinearRing`) and a possible list of holes (as seen in the last plot of Figure 5.3) It is also possible to have a collection of geometric objects (i.e. multiple points, lines or areas) represented as `MultiPoint`, `MultiLineString` and `MultiPolygon` as shown in the bottom row of Figure 5.3. Geometry collections can be useful for example when you want to present multiple building polygons belonging to the same property as a single entity (like a Finnish summer house that typically has a separate sauna building). In addition to these, you might sometimes hear about other geometry objects, such as `Curve`, `Surface` or `GeometryCollection`, but these are basically implemented by the same `Point`, `LineString` and `Polygon` geometry types, hence we don't really use them in practice.

All of these geometries are defined in *Simple Features Access Specification* ({cite}`Herring_2011`), which is a standard (ISO 19125-1) formalized by the *Open Geospatial Consortium* and *International Organization for Standardization*. Most (if not all) programming languages follow this same standard to represent spatial data. The text underneath each geometry (e.g. `Point (25 60.5)`) shows how each of these geometries can be represented as text (Figure 5.3). The way the text is formatted follows a specification called *{term}`Well-known text` (WKT)* which is also defined in the Simple Features Access Specification. The geometries can also be represented in binary format, which is called *{term}`Well-known binary` (WKB)*. WKB is useful for storing the geometries in a more compact form, but it is not human-readable. Most often, you don't need to worry about these technical details when working with spatial data in Python, but it is useful to know the foundations underlying most (if not all) GIS libraries.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"source": [
"### Geometry types\n",
"\n",
"The most fundamental geometric objects when working with spatial data in vector format are **points**, **lines** and **areas**. Figure 5.3 represents the vector data model and illustrates the variety of geometric objects that are available. `Point` -object represents a single point in geographic space and the location of the point in space is determined with coordinates. Points can be either two-dimensional (with x, y -coordinates) or three dimensional (with x, y, and z coordinates). A single pair of coordinates forming a point is commonly called as *`coordinate`* *{term}`tuple`*. `LineString` -object (i.e. a line) represents a sequence of points joined together to form a line. Hence, a line consist of a list of at least two coordinate tuples. `Polygon` -object represents a filled area that consists of a list of at least three coordinate tuples that forms the outerior ring (called `LinearRing`) and a possible list of holes (as seen in the last plot of Figure 5.3) It is also possible to have a collection of geometric objects (i.e. multiple points, lines or areas) represented as `MultiPoint`, `MultiLineString` and `MultiPolygon` as shown in the bottom row of Figure 5.3. Geometry collections can be useful for example when you want to present multiple building polygons belonging to the same property as a single entity (like a Finnish summer house that typically has a separate sauna building). In addition to these, you might sometimes hear about other geometry objects, such as `Curve`, `Surface` or `GeometryCollection`, but these are basically implemented by the same `Point`, `LineString` and `Polygon` geometry types, hence we don't really use them in practice. \n",
"The most fundamental geometric objects when working with spatial data in vector format are **points**, **lines** and **areas**. Figure 5.3 represents the vector data model and illustrates the variety of geometric objects that are available. `Point` -object represents a single point in geographic space and the location of the point in space is determined with coordinates. Points can be either two-dimensional (with x, y -coordinates) or three dimensional (with x, y, and z coordinates). A single pair of coordinates forming a point is commonly called as a *`coordinate`* *{term}`tuple`*. `LineString` -object (i.e. a line) represents a sequence of points joined together to form a line. Hence, a line consist of a list of at least two coordinate tuples. `Polygon` -object represents a filled area that consists of a list of at least three coordinate tuples that forms the outerior ring (called `LinearRing`) and a possible list of holes (as seen in the last plot of Figure 5.3) It is also possible to have a collection of geometric objects (i.e. multiple points, lines or areas) represented as `MultiPoint`, `MultiLineString` and `MultiPolygon` as shown in the bottom row of Figure 5.3. Geometry collections can be useful for example when you want to present multiple building polygons belonging to the same property as a single entity (like a Finnish summer house that typically has a separate sauna building). In addition to these, you might sometimes hear about other geometry objects, such as `Curve`, `Surface` or `GeometryCollection`, but these are basically implemented by the same `Point`, `LineString` and `Polygon` geometry types, hence we don't really use them in practice. \n",
"\n",
"All of these geometries are defined in *Simple Features Access Specification* ({cite}`Herring_2011`), which is a standard (ISO 19125-1) formalized by the *Open Geospatial Consortium* and *International Organization for Standardization*. Most (if not all) programming languages follow this same standard to represent spatial data. The text underneath each geometry (e.g. `Point (25 60.5)`) shows how each of these geometries can be represented as text (Figure 5.3). The way the text is formatted follows a specification called *{term}`Well-known text` (WKT)* which is also defined in the Simple Features Access Specification. The geometries can also be represented in binary format, which is called *{term}`Well-known binary` (WKB)*. WKB is useful for storing the geometries in a more compact form, but it is not human-readable. Most often, you don't need to worry about these technical details when working with spatial data in Python, but it is useful to know the foundations underlying most (if not all) GIS libraries.\n",
"\n",
Expand Down Expand Up @@ -307,7 +307,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.5"
"version": "3.11.7"
}
},
"nbformat": 4,
Expand Down
4 changes: 2 additions & 2 deletions docs/_sources/part2/chapter-06/md/0-learning-objectives.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jupyter:
<!-- #endregion -->

<!-- #region editable=true slideshow={"slide_type": ""} -->
Chapter six provides an overview of vector data processing in Python. You will learn how geographic objects can be represented and manipulated in Python, how coordinate reference systems can be defined and modified, and learn how to conduct common spatial analysis processes and techniques such as geocoding, spatial queries, spatial joins,nearest neighbor analysis and geographic overlay analysis.
Chapter six provides an overview of vector data processing in Python. You will learn how geographic objects can be represented and manipulated in Python, how coordinate reference systems can be defined and modified, and learn how to conduct common GIS techniques, such as geocoding, spatial queries, spatial join, nearest neighbor analysis and vector overlay operations.

Basic knowledge of tabular data manipulation using the pandas library introduced in Part I is a prerequisite for learning to use geopandas for spatial data analysis in this section.
<!-- #endregion -->
Expand All @@ -35,7 +35,7 @@ At the end of this chapter, you should be able to:
- Geocode addresses to coordinates using Python
- Perform spatial queries and spatial join operations
- Conduct nearest neighbor analysis
- Perform various geographic overlay analysis
- Perform and understand how different vector overlay operations work
```
<!-- #endregion -->
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ jupyter:
<!-- #region editable=true slideshow={"slide_type": ""} -->
# Representing geographic data in Python

In this section, we will learn how geometric objects (in vector format) are represented using the [shapely](https://shapely.readthedocs.io/en/stable/manual.html) [^shapely] library, which is one of the core vector data processing libraries in Python as discussed in Chapter 5. Basic knowledge of shapely is important for using higher-level tools that depend on it, such as **geopandas**, which we will use extensively in the following sections of this book for geographic data analysis.
In this section, you will learn how geometric objects, such as `Point`, `LineString` and `Polygon`, are represented on a computer in vector format. Creating and representing vector-based geometric objects is most commonly done using the shapely [^shapely] library which is one of the fundamental libraries in Python GIS ecosystem when working with geographic data. Thus, basic knowledge of shapely is highly useful when using higher-level tools that depend on it, such as **geopandas**, which we will use extensively in the following sections of this book for geographic data analysis.

Under the hood shapely uses a C++ library called [GEOS](https://trac.osgeo.org/geos) [^GEOS] to construct the geometries. GEOS is one of the standard libraries behind various GIS software, such as [PostGIS](https://postgis.net/) [^PostGIS] or [QGIS](http://www.qgis.org/en/site/) [^QGIS]. Objects and methods available in shapely adhere mainly to [the Open Geospatial Consortium’s Simple Features Access Specification](https://www.ogc.org/standards/sfa) [^OGC_sfa], making them compatible with various GIS tools. In this section, we give a quick overview of creating geometries using shapely.
Under the hood shapely uses a C++ library called GEOS [^GEOS] to construct the geometries. GEOS is one of the standard libraries behind various GIS software, such as PostGIS [^PostGIS] and QGIS [^QGIS]. Objects and methods available in shapely adhere mainly to the Open Geospatial Consortium’s Simple Features Access Specification [^OGC_sfa] (see Chapter 5.2), making them compatible with various GIS tools. Next, we will give a quick overview of how to create different kind of geometries using shapely.
<!-- #endregion -->

<!-- #region editable=true slideshow={"slide_type": ""} -->
Expand All @@ -26,7 +26,7 @@ Under the hood shapely uses a C++ library called [GEOS](https://trac.osgeo.org/g
When creating geometries with shapely, we first need to import the geometric object class which we want to create, such as `Point`, `LineString` or `Polygon`. Let's start by creating a simple `Point` object. First, we need to import the `Point` class which we can then use to create the point geometry. When creating the geometry, we need to pass the `x` and `y` coordinates (with a possible `z` -coordinate) into the `Point()` -class constructor, which will create the point geometry for us, as follows:
<!-- #endregion -->

```python jupyter={"outputs_hidden": false} editable=true slideshow={"slide_type": ""}
```python editable=true jupyter={"outputs_hidden": false} slideshow={"slide_type": ""}
from shapely import Point

point = Point(2.2, 4.2)
Expand All @@ -42,7 +42,7 @@ As we can see in the online version, Jupyter Notebook is able to visualize the p
We can use the `print()` statement to get the text representation of the point geometry as [Well Known Text (WKT)](https://en.wikipedia.org/wiki/Well-known_text_representation_of_geometry) [^WKT]. In the output, the letter `Z` after the `POINT` indicates that the geometry contains coordinates in three dimensions (x, y, z):
<!-- #endregion -->

```python jupyter={"outputs_hidden": false} editable=true slideshow={"slide_type": ""}
```python editable=true jupyter={"outputs_hidden": false} slideshow={"slide_type": ""}
print(point)
print(point3D)
```
Expand Down Expand Up @@ -297,11 +297,11 @@ Create examples of these shapes using your shapely skills:
- **Circle**
<!-- #endregion -->

```python tags=["remove_cell"] editable=true slideshow={"slide_type": ""}
```python editable=true slideshow={"slide_type": ""} tags=["remove_cell"]
# Use this cell to enter your solution.
```

```python tags=["hide_cell", "remove_book_cell"] editable=true slideshow={"slide_type": ""}
```python editable=true slideshow={"slide_type": ""} tags=["remove_book_cell", "hide-cell"]
# Solution

# Triangle
Expand Down
12 changes: 5 additions & 7 deletions docs/_sources/part2/chapter-06/md/01-geodataframe.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ jupyter:
<!-- #region editable=true slideshow={"slide_type": ""} -->
# Introduction to geopandas GeoDataFrames

Now that we have learned how to represent geometric objects in Python using shapely, we will continue on geographic data analysis using [geopandas](https://geopandas.org/) [^geopandas].

**Geopandas** is a Python library designed to make working with geospatial data in Python easier. It extends the data types used by pandas (which we covered in Part I) to allow geospatial operations and the handling of coordinate reference systems. Essentially, it provides a high-level interface for vector data (like points, lines, and polygons) that integrates with the existing pandas data analysis framework, as well as the extensive Python GIS ecosystem (see Figure 5.1 in Chapter 5). Geopandas is one of the core libraries for GIS in Python and it is widely used in different sectors (academia, industry, etc.) for geographic data analysis.
Now that you have seen how to create and represent geometric objects in Python using shapely, we will continue on learning various GIS techniques using **geopandas** [^geopandas]. Geopandas is a library designed to make working with geospatial data in Python easier. It extends the data types used by pandas (which we covered in Part I) to allow geospatial operations and the handling of coordinate reference systems. Essentially, it provides a high-level interface for vector data (like points, lines, and polygons) that integrates with the existing pandas data analysis framework, as well as the extensive Python GIS ecosystem (see Figure 5.1 in Chapter 5). Geopandas is one of the core libraries for GIS in Python and it is widely used in different sectors (academia, industry, etc.) for geographic data analysis.
<!-- #endregion -->

<!-- #region editable=true slideshow={"slide_type": ""} -->
Expand Down Expand Up @@ -104,7 +102,7 @@ Figure out the following information from our input data using your `pandas` ski
# You can use this cell to enter your solution.
```

```python editable=true slideshow={"slide_type": ""} tags=["remove_book_cell", "hide_cell"]
```python editable=true slideshow={"slide_type": ""} tags=["remove_book_cell", "hide-cell"]
# Solution

print("Number of rows", len(data))
Expand Down Expand Up @@ -166,7 +164,7 @@ Using your `pandas` skills, create a new column `pop_density_km2` and populate i
# Use this cell to enter your solution.
```

```python editable=true slideshow={"slide_type": ""} tags=["remove_book_cell", "hide_cell"]
```python editable=true slideshow={"slide_type": ""} tags=["remove_book_cell", "hide-cell"]
# Solution

# Calculate population density
Expand Down Expand Up @@ -210,11 +208,11 @@ Now we have successfully stored the data into a file called `austin_pop_density_
Read the output file using `geopandas` and check that the data looks ok.
<!-- #endregion -->

```python tags=["remove_cell"] editable=true slideshow={"slide_type": ""}
```python editable=true slideshow={"slide_type": ""} tags=["remove_cell"]
# Use this cell to enter your solution.
```

```python editable=true slideshow={"slide_type": ""} tags=["remove_book_cell", "hide_cell"]
```python editable=true slideshow={"slide_type": ""} tags=["remove_book_cell", "hide-cell"]
# Solution

temp = gpd.read_file(output_fp)
Expand Down
Loading

0 comments on commit bd15ce6

Please sign in to comment.