Mercurial Hosting > traffic-intelligence
comparison 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 |
comparison
equal
deleted
inserted
replaced
780:1b22d81ef5ff | 781:7c38250ddfc7 |
---|---|
1 >>> from moving import * | 1 >>> from moving import * |
2 >>> from shapely.geometry import Polygon | 2 >>> from shapely.geometry import Polygon |
3 >>> from shapely.prepared import prep | |
3 | 4 |
4 >>> t1 = Trajectory([[0.5,1.5,2.5],[0.5,3.5,6.5]]) | 5 >>> t1 = Trajectory([[0.5,1.5,2.5],[0.5,3.5,6.5]]) |
5 >>> t1.getTrajectoryInPolygon(Polygon([[0,0],[4,0],[4,3],[0,3]])) | 6 >>> poly = Polygon([[0,0],[4,0],[4,3],[0,3]]) |
7 >>> sub1, sub2 = t1.getTrajectoryInPolygon(poly) | |
8 >>> sub1 | |
6 (0.500000,0.500000) | 9 (0.500000,0.500000) |
7 >>> t1.getTrajectoryInPolygon(Polygon([[10,10],[14,10],[14,13],[10,13]])).length() | 10 >>> sub1, sub2 = t1.getTrajectoryInPolygon(Polygon([[10,10],[14,10],[14,13],[10,13]])) |
11 >>> sub1.length() | |
8 0 | 12 0 |
13 >>> sub1, sub2 = t1.getTrajectoryInPolygon(prep(poly)) | |
14 >>> sub1 | |
15 (0.500000,0.500000) | |
16 >>> t2 = t1.differentiate(True) | |
17 >>> sub1, sub2 = t1.getTrajectoryInPolygon(prep(poly), t2) | |
18 >>> sub1.length() == sub2.length() | |
19 True | |
20 >>> sub1 | |
21 (0.500000,0.500000) | |
22 >>> sub2 | |
23 (1.000000,3.000000) | |
9 | 24 |
25 >>> t1.proportionInPolygon(poly, 0.5) | |
26 False | |
27 >>> t1.proportionInPolygon(poly, 0.3) | |
28 True |