# From “Geometries (shapely)”#

Last updated: 2023-05-27 16:40:30


## Exercise 07-f#

import shapely.geometry
import shapely.wkt

MULTIPOLYGON
(((40 40, 20 45, 45 30, 40 40)),
((20 35, 10 30, 10 10, 30 5, 45 20, 20 35), (30 20, 20 15, 20 25, 30 20)))
""")
b3 = shapely.geometry.box(*pol3.bounds)
b3.difference(pol3)

pol1 = shapely.wkt.loads("POLYGON ((0 0, 0 -1, 7.5 -1, 7.5 0, 0 0))")
pol1.buffer(1).difference(pol1)


## Exercise 07-h#

rect = shapely.wkt.loads("POLYGON ((0 0, 0 1, 1 1, 1 0, 0 0))")
circ = pnt.buffer(0.5)

rect.union(circ)

rect.intersection(circ)

rect.intersection(circ).area

0.19603428065912124

rect.union(circ).area

1.5881028419773635


## Exercise 07-i#

import pandas as pd
import shapely.geometry
stops = stops[["stop_id", "stop_name", "stop_lon", "stop_lat"]]
stop_times = stop_times[["trip_id", "stop_id", "stop_sequence"]]
sel = stop_times["trip_id"] == "55745843_180421"
stop_times = stop_times[sel]
stops = pd.merge(stop_times, stops, on="stop_id")
stops = stops.sort_values("stop_sequence")

coords = stops.loc[:, ["stop_lon", "stop_lat"]].to_numpy().tolist()
stops_pnt = shapely.geometry.MultiPoint(coords)
stops_pnt

stops_line = shapely.geometry.LineString(coords)
stops_line

coords1 = [coords[0], coords[len(coords)-1]]
stops_line1 = shapely.geometry.LineString(coords1)
stops_line1

ch = stops_pnt.convex_hull
ch