Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lernen Geometries: Points, Lines, and Polygons | Foundations of Geospatial Data
Practice
Projects
Quizzes & Challenges
Quizzes
Challenges
/
Geospatial Data Science with Python

bookGeometries: Points, Lines, and Polygons

Understanding geometric primitives is essential for representing and analyzing spatial features in geospatial data science. The three fundamental geometry types are points, lines, and polygons. Each of these serves a unique purpose when modeling real-world objects.

A point is the simplest geometry, representing a single location in space. You can use points to mark the locations of cities, weather stations, or specific events. For example, a point could represent the geographic center of Paris.

Lines (or more precisely, LineStrings) are sequences of points connected in order, representing linear features. These are ideal for modeling roads, rivers, or railway tracks. For instance, the route of a highway between two cities would be represented as a line.

Polygons are closed shapes defined by a sequence of points where the first and last point are the same. Polygons are used to represent areas such as country borders, lakes, or land parcels. For example, the boundary of a national park would be a polygon.

To work with these geometries in Python, you can use the shapely library, which provides classes for creating and manipulating geometric objects.

1234567891011121314151617181920
from shapely.geometry import Point, LineString, Polygon # Create a Point representing a city city = Point(2.3522, 48.8566) # Longitude, Latitude for Paris # Create a LineString representing a road road = LineString([(2.3522, 48.8566), (2.295, 48.8738), (2.1734, 48.8584)]) # Create a Polygon representing a park boundary park = Polygon([ (2.3490, 48.8647), (2.3530, 48.8647), (2.3530, 48.8617), (2.3490, 48.8617), (2.3490, 48.8647) # Close the polygon ]) print("City (Point):", city) print("Road (LineString):", road) print("Park (Polygon):", park)
copy
12345678910111213141516171819202122
import pandas as pd from shapely.geometry import Point, LineString, Polygon import geopandas as gpd # List of geometries: a city, a road, and a park geometries = [ Point(2.3522, 48.8566), LineString([(2.3522, 48.8566), (2.295, 48.8738), (2.1734, 48.8584)]), Polygon([ (2.3490, 48.8647), (2.3530, 48.8647), (2.3530, 48.8617), (2.3490, 48.8617), (2.3490, 48.8647) ]) ] # Create a GeoDataFrame gdf = gpd.GeoDataFrame({'geometry': geometries, 'type': ['City', 'Road', 'Park']}) # Display the structure of the GeoDataFrame print(gdf)
copy
question mark

Which geometry type would best represent a river?

Select the correct answer

War alles klar?

Wie können wir es verbessern?

Danke für Ihr Feedback!

Abschnitt 1. Kapitel 2

Fragen Sie AI

expand

Fragen Sie AI

ChatGPT

Fragen Sie alles oder probieren Sie eine der vorgeschlagenen Fragen, um unser Gespräch zu beginnen

Suggested prompts:

Can you explain more about how to use GeoDataFrames for spatial analysis?

What are some common operations you can perform with these geometric objects?

How do you visualize these geometries using Python libraries?

bookGeometries: Points, Lines, and Polygons

Swipe um das Menü anzuzeigen

Understanding geometric primitives is essential for representing and analyzing spatial features in geospatial data science. The three fundamental geometry types are points, lines, and polygons. Each of these serves a unique purpose when modeling real-world objects.

A point is the simplest geometry, representing a single location in space. You can use points to mark the locations of cities, weather stations, or specific events. For example, a point could represent the geographic center of Paris.

Lines (or more precisely, LineStrings) are sequences of points connected in order, representing linear features. These are ideal for modeling roads, rivers, or railway tracks. For instance, the route of a highway between two cities would be represented as a line.

Polygons are closed shapes defined by a sequence of points where the first and last point are the same. Polygons are used to represent areas such as country borders, lakes, or land parcels. For example, the boundary of a national park would be a polygon.

To work with these geometries in Python, you can use the shapely library, which provides classes for creating and manipulating geometric objects.

1234567891011121314151617181920
from shapely.geometry import Point, LineString, Polygon # Create a Point representing a city city = Point(2.3522, 48.8566) # Longitude, Latitude for Paris # Create a LineString representing a road road = LineString([(2.3522, 48.8566), (2.295, 48.8738), (2.1734, 48.8584)]) # Create a Polygon representing a park boundary park = Polygon([ (2.3490, 48.8647), (2.3530, 48.8647), (2.3530, 48.8617), (2.3490, 48.8617), (2.3490, 48.8647) # Close the polygon ]) print("City (Point):", city) print("Road (LineString):", road) print("Park (Polygon):", park)
copy
12345678910111213141516171819202122
import pandas as pd from shapely.geometry import Point, LineString, Polygon import geopandas as gpd # List of geometries: a city, a road, and a park geometries = [ Point(2.3522, 48.8566), LineString([(2.3522, 48.8566), (2.295, 48.8738), (2.1734, 48.8584)]), Polygon([ (2.3490, 48.8647), (2.3530, 48.8647), (2.3530, 48.8617), (2.3490, 48.8617), (2.3490, 48.8647) ]) ] # Create a GeoDataFrame gdf = gpd.GeoDataFrame({'geometry': geometries, 'type': ['City', 'Road', 'Park']}) # Display the structure of the GeoDataFrame print(gdf)
copy
question mark

Which geometry type would best represent a river?

Select the correct answer

War alles klar?

Wie können wir es verbessern?

Danke für Ihr Feedback!

Abschnitt 1. Kapitel 2
some-alt