miracle2k
miracle2k

Reputation: 32067

GIS: line_locate_point() in Python

I'm pretty much a beginner when it comes to GIS, but I think I understand the basics - it doesn't seem to hard. But: All these acronyms and different libraries, GEOS, GDAL, PROJ, PCL, Shaply, OpenGEO, OGR, OGC, OWS and what not, each seemingly depending on any number of others, is slightly overwhelming me.

Here's what I would like to do: Given a number of points and a linestring, I want to determine the location on the line closest to a certain point. In other words, what PostGIS's line_locate_point() does:

http://postgis.refractions.net/documentation/manual-1.3/ch06.html#line_locate_point

Except I want do use plain Python. Which library or libraries should I have a look at generally for doing these kinds of spatial calculations in Python, and is there one that specifically supports a line_locate_point() equivalent?

Upvotes: 2

Views: 1152

Answers (4)

trideset3
trideset3

Reputation: 85

All you need is Shapely, if you have shapefiles for points and linestrings, a line.distance(point) in for loop will do the trick. With that you can find the closest point to the line or vice versa. Make sure you check GDAL, Fiona, Shapely in order to complete this.

Upvotes: 0

fmark
fmark

Reputation: 58597

For posterity, these functions are available in Shapely 1.2

Upvotes: 2

sgillies
sgillies

Reputation: 2251

In another forum I suggested reimplementing the (simple) PostGIS algorithm in Python using Shapely.

Upvotes: 2

Related Questions