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

Length of a line

Points have no length and if they intersect, they have the same coordinates. Lines, however, have a length and can intersect at a point not specified in the table, between two of the points used to create the line. The following code will return the length of all of the lines:

cu.execute("SELECT id, ST_Length(location::geography) FROM lines ")cu.fetchall()

The previous code uses the ST_Length function. The function will accept both geometry and geography. In this example, ::geography was used to convert the geometry so meters would be returned.

The results are as follows:

[(1, 4415.21026808109), (2, 7835.65405408195), (3, 7059.45840502359)]

You can add an ORDER BY clause to the previous query and the database will return ...

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