HomeData scienceIntroduction to Shapely in Python | by Tarık Emre Yorulmaz | Oct,...

Introduction to Shapely in Python | by Tarık Emre Yorulmaz | Oct, 2024


Shapely is a Python library for working with geometric objects. It permits us to carry out varied operations on primary geometric shapes resembling factors, traces, and polygons. We will create factors, traces, and polygons with Shapely. We will verify the relationships between two geometries resembling inclusion and intersection. We will carry out geometric operations resembling distinction and buffering.

Fig. 1: Level, line and polygon samples (Supply: Bookdown)

First, let’s set up the library;

!pip set up shapely

First step is to create factors, traces and polygons. Let’s begin with level. For this, we’ll import the Level class from the Shapely library;

from shapely.geometry import Level
# Create some extent
level = Level(1, 1)
print(level)

Let’s create a line. For this, we’ll import the LineString class from the Shapely library;

from shapely.geometry import LineString
# Create a line
line = LineString([(0, 0), (1, 1), (2, 2)])
print(line)

Lastly, we’ll create a polygon. For this, we’ll import the Polygon class from the Shapely library;

from shapely.geometry import Polygon
# Create a polygon
polygon = Polygon([(0, 0), (1, 1), (1, 0), (0, 1)])
print(polygon)

In my subsequent weblog put up, I’ll share the geometric evaluation you are able to do with the shapely library.



Supply hyperlink

latest articles

ChicMe WW
Lightinthebox WW

explore more