April 2018
Beginner to intermediate
440 pages
11h 36m
English
The first section of this chapter focused on point operations. Now, we will turn our attention to lines. For the following examples, you will create a new table and insert three lines. The following code will accomplish that:
from shapely.geometry import LineStringfrom shapely.geometry import MultiLineStringconnection = psycopg2.connect(database="pythonspatial",user="postgres", password="postgres")cursor = c.cursor()cursor.execute("CREATE TABLE lines (id SERIAL PRIMARY KEY, location GEOMETRY)")thelines=[]thelines.append(LineString([(-106.635585,35.086972),(-106.621294,35.124997)]))thelines.append(LineString([(-106.498309,35.140108),(-106.497010,35.069488)]))thelines.append(LineString([(-106.663878,35.106459),(-106.586506,35.103979)])) ...