When I use novalis's patch from
http://code.djangoproject.com/attachment/ticket/11948/contrib-gis-linearref.patch
on Django 1.1.1, projection and interpolation seem to work properly,
including on MultiLineStrings for multiple line segments. I will try to
figure out why the same code isn't working in shapely.geometry.base.
from django.contrib.gis.geos import geometry
point = geometry.Point(1, 1)
line = geometry.LineString([[0, 0], [2, 0]])
assert line.project(point) == 1
print line.interpolate(line.project(point))
multiLine = geometry.MultiLineString(geometry.LineString([[0,0],[2,0]]),
geometry.LineString([[3,0],[3,3]]))
assert multiLine.project(point) == 1
print multiLine.interpolate(multiLine.project(point))
On 01/22/2010 09:37 AM, Roy Hyunjin Han wrote:
I have been trying to use the GEOS linear referencing functions
through the base geometry class as Sean suggested in an earlier email,
and although interpolation works, projection does not
(lgeos.GEOSProject gives a return code of 0 instead of 1). Do you
have any idea why this is happening?
from shapely.geometry import base, LineString
from shapely.geos import lgeos
line = LineString([[0, 0], [2, 0]])
print '==== Interpolation ===='
point = base.geom_factory(lgeos.GEOSInterpolateNormalized(line._geom,
base.c_double(0.5)))
print point.wkt
print '==== Projection ===='
scalar = base.c_double()
returnCode = lgeos.GEOSProject(point._geom, line._geom,
base.byref(scalar))
if returnCode == 1:
print 'Projection of %s onto %s is %s' % (point.wkt, line.wkt,
scalar.value)
else:
print 'Projection failed'
from django.contrib.gis.geos import geometry
point = geometry.Point(1, 1)
line = geometry.LineString([[0, 0], [2, 0]])
assert line.project(point) == 1
print line.interpolate(line.project(point))
multiLine = geometry.MultiLineString(geometry.LineString([[0,0],[2,0]]),
geometry.LineString([[3,0],[3,3]]))
assert multiLine.project(point) == 1
print multiLine.interpolate(multiLine.project(point))
_______________________________________________
Community mailing list
[email protected]
http://lists.gispython.org/mailman/listinfo/community