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 valuesIn:   from shapely.geometry import Point      point = Point(2.0, 2.0)      q = Point((2.0, 2.0))      q       # line geometryIn:    from shapely.geometry import LineString line = LineString([(0, 0), ...

Get Mastering Geospatial Analysis with Python now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.