comparison python/tests/moving.txt @ 372:349eb1e09f45

Cleaned the methods/functions indicating if a point is in a polygon In general, shapely should be used, especially for lots of points: from shapely.geometry import Polygon, Point poly = Polygon(array([[0,0],[0,1],[1,1],[1,0]])) p = Point(0.5,0.5) poly.contains(p) -> returns True poly.contains(Point(-1,-1)) -> returns False You can convert a moving.Point to a shapely point: p = moving.Point(1,2) p.asShapely() returns the equivalent shapely point If you have several points to test, use moving.pointsInPolygon(points, polygon) where points are moving.Point and polygon is a shapely polygon.
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Tue, 16 Jul 2013 17:00:17 -0400
parents 027e254f0b53
children cd342a774806
comparison
equal deleted inserted replaced
371:924e38c9f70e 372:349eb1e09f45
47 13 47 13
48 48
49 >>> Point.distanceNorm2(Point(3,4),Point(1,7)) 49 >>> Point.distanceNorm2(Point(3,4),Point(1,7))
50 3.605551275463989 50 3.605551275463989
51 51
52 >>> Point(3,2).inPolygon([Point(0,0),Point(1,0),Point(1,1),Point(0,1)]) 52 >>> Point(3,2).inPolygonNoShapely(np.array([[0,0],[1,0],[1,1],[0,1]]))
53 False 53 False
54 >>> Point(3,2).inPolygon([Point(0,0),Point(4,0),Point(4,3),Point(0,3)]) 54 >>> Point(3,2).inPolygonNoShapely(np.array([[0,0],[4,0],[4,3],[0,3]]))
55 True 55 True
56 56
57 >>> predictPositionNoLimit(10, Point(0,0), Point(1,1)) # doctest:+ELLIPSIS 57 >>> predictPositionNoLimit(10, Point(0,0), Point(1,1)) # doctest:+ELLIPSIS
58 ((1.0...,1.0...), (10.0...,10.0...)) 58 ((1.0...,1.0...), (10.0...,10.0...))
59 59
68 >>> t1 = Trajectory([[0.5,1.5,2.5],[0.5,3.5,6.5]]) 68 >>> t1 = Trajectory([[0.5,1.5,2.5],[0.5,3.5,6.5]])
69 >>> t1.length() == 3. 69 >>> t1.length() == 3.
70 True 70 True
71 >>> t1[1] 71 >>> t1[1]
72 (1.500000,3.500000) 72 (1.500000,3.500000)
73 >>> t1.getTrajectoryInPolygon(np.array([[0,0],[4,0],[4,3],[0,3]])) 73 >>> t1.getTrajectoryInPolygonNoShapely(np.array([[0,0],[4,0],[4,3],[0,3]]))
74 (0.500000,0.500000) 74 (0.500000,0.500000)
75 >>> t1.getTrajectoryInPolygon(np.array([[10,10],[14,10],[14,13],[10,13]])).length() 75 >>> t1.getTrajectoryInPolygonNoShapely(np.array([[10,10],[14,10],[14,13],[10,13]])).length()
76 0 76 0
77 77
78 >>> from utils import LCSS 78 >>> from utils import LCSS
79 >>> lcss = LCSS(lambda x,y: Point.distanceNorm2(x,y) <= 0.1) 79 >>> lcss = LCSS(lambda x,y: Point.distanceNorm2(x,y) <= 0.1)
80 >>> Trajectory.lcss(t1, t1, lcss) 80 >>> Trajectory.lcss(t1, t1, lcss)