diff python/tests/moving_shapely.txt @ 781:7c38250ddfc7 dev

updated to deal with prepared polygons from shapely, and to extract the same positions from a second trajectory in a polygon (for velocities for example)
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Thu, 11 Feb 2016 11:56:50 -0500
parents 6ae68383071e
children
line wrap: on
line diff
--- a/python/tests/moving_shapely.txt	Mon Feb 08 12:24:26 2016 -0500
+++ b/python/tests/moving_shapely.txt	Thu Feb 11 11:56:50 2016 -0500
@@ -1,9 +1,28 @@
 >>> from moving import *
 >>> from shapely.geometry import Polygon
+>>> from shapely.prepared import prep
 
 >>> t1 = Trajectory([[0.5,1.5,2.5],[0.5,3.5,6.5]])
->>> t1.getTrajectoryInPolygon(Polygon([[0,0],[4,0],[4,3],[0,3]]))
+>>> poly = Polygon([[0,0],[4,0],[4,3],[0,3]])
+>>> sub1, sub2 = t1.getTrajectoryInPolygon(poly)
+>>> sub1
+(0.500000,0.500000)
+>>> sub1, sub2 = t1.getTrajectoryInPolygon(Polygon([[10,10],[14,10],[14,13],[10,13]]))
+>>> sub1.length()
+0
+>>> sub1, sub2 = t1.getTrajectoryInPolygon(prep(poly))
+>>> sub1
 (0.500000,0.500000)
->>> t1.getTrajectoryInPolygon(Polygon([[10,10],[14,10],[14,13],[10,13]])).length()
-0
+>>> t2 = t1.differentiate(True)
+>>> sub1, sub2 = t1.getTrajectoryInPolygon(prep(poly), t2)
+>>> sub1.length() == sub2.length()
+True
+>>> sub1
+(0.500000,0.500000)
+>>> sub2
+(1.000000,3.000000)
 
+>>> t1.proportionInPolygon(poly, 0.5)
+False
+>>> t1.proportionInPolygon(poly, 0.3)
+True