Skip to Content
Mastering Geospatial Analysis with Python
book

Mastering Geospatial Analysis with Python

by Silas Toms, Paul Crickard, Eric van Rees
April 2018
Beginner to intermediate content levelBeginner to intermediate
440 pages
11h 36m
English
Packt Publishing
Content preview from Mastering Geospatial Analysis with Python

Lines in the database

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)])) ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Learning Geospatial Analysis with Python

Learning Geospatial Analysis with Python

Joel Lawhead

Publisher Resources

ISBN: 9781788293334Supplemental Content