Creating geometries with Shapely

Just like OGR, you can use Shapely to create geometries. Jupyter Notebook will plot the geometries after you've created them, as opposed to OGR. You don't have to use extra plot statements to do this, just repeat the variable name used to store the geometries:

In:   from shapely.geometry import Polygon
p1 = Polygon(((1, 2), (5, 3), (5, 7), (1, 9), (1, 2)))
p2 = Polygon(((6,6), (7,6), (10,4), (11,8), (6,6)))
p1
# A new command line is required for printing the second polygon:
In: p2

# Point takes tuples as well as positional coordinate values
In: from shapely.geometry import Point
point = Point(2.0, 2.0)
q = Point((2.0, 2.0))
q

# line geometry
In: from shapely.geometry import LineString
line = LineString([(0, 0), (10,10)])
line

# linear rings
In: from shapely.geometry.polygon import LinearRing
ring = LinearRing([(0,0), (3,3), (3,0)])
ring

# collection of points
In: from shapely.geometry import MultiPoint
points = MultiPoint([(0.0, 0.0), (3.0, 3.0)])
points

# collection of lines
In: from shapely.geometry import MultiLineString
coords = [((0, 0), (1, 1)), ((-1, 0), (1, 0))]
coords

# collection of polygons
In: from shapely.geometry import MultiPolygon
polygons = MultiPolygon([p1, p2,])
polygons
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset