Mercurial Hosting > traffic-intelligence
view python/tests/utils.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 | a7af3519687e |
line wrap: on
line source
>>> from utils import * >>> from moving import Point >>> computeChi2([],[]) 0.0 >>> computeChi2(range(1,10),range(1,10)) 0.0 >>> computeChi2(range(1,9),range(1,10)) 0.0 >>> ceilDecimals(1.23, 0) 2.0 >>> ceilDecimals(1.23, 1) 1.3 >>> inBetween(1,2,1.5) True >>> inBetween(2.1,1,1.5) True >>> inBetween(1,2,0) False >>> f = openCheck('non_existant_file.txt') File non_existant_file.txt could not be opened. >>> removeExtension('test-adfasdf.asdfa.txt') 'test-adfasdf.asdfa' >>> removeExtension('test-adfasdf') 'test-adfasdf' >>> values = line2Ints('1 2 3 5 6') >>> values[0] 1 >>> values[-1] 6 >>> values = line2Floats('1.3 2.45 7.158e+01 5 6') >>> values[0] 1.3 >>> values[2] #doctest: +ELLIPSIS 71.5... >>> values[-1] 6.0 >>> stepPlot([3, 5, 7, 8], 1, 10, 0) ([1, 3, 3, 5, 5, 7, 7, 8, 8, 10], [0, 0, 1, 1, 2, 2, 3, 3, 4, 4]) >>> lcss = LCSS(lambda x,y: abs(x-y) <= 0.1) >>> lcss.compute(range(5), range(5)) 5 >>> lcss.compute(range(1,5), range(5)) 4 >>> lcss.compute(range(5,10), range(5)) 0 >>> lcss.compute(range(5), range(10)) 5 >>> lcss.compute(range(5), range(10), 2) 5 >>> lcss.similarityFunc = lambda x,y: x == y >>> lcss.compute(['a','b','c'], ['a','b','c', 'd']) 3 >>> lcss.computeNormalized(['a','b','c'], ['a','b','c', 'd']) #doctest: +ELLIPSIS 1.0 >>> lcss.computeNormalized(['a','b','c','x'], ['a','b','c', 'd']) #doctest: +ELLIPSIS 0.75 >>> lcss.compute(['a','b','c'], ['a','b','c', 'd']) 3 >>> lcss.compute(['a','x','b','c'], ['a','b','c','d','x']) 3 >>> lcss.compute(['a','b','c','x','d'], ['a','b','c','d','x']) 4 >>> lcss.delta = 1 >>> lcss.compute(['a','b','c'], ['a','b','x','x','c']) 2 >>> lcss.delta = float('inf') >>> lcss.compute(['a','b','c'], ['a','b','c', 'd'], computeSubSequence = True) 3 >>> lcss.subSequenceIndices [(0, 0), (1, 1), (2, 2)] >>> lcss.compute(['a','b','c'], ['x','a','b','c'], computeSubSequence = True) 3 >>> lcss.subSequenceIndices [(0, 1), (1, 2), (2, 3)] >>> lcss.compute(['a','g','b','c'], ['a','b','c', 'd'], computeSubSequence = True) 3 >>> lcss.subSequenceIndices [(0, 0), (2, 1), (3, 2)] >>> alignedLcss = LCSS(lambda x,y:(abs(x-y) <= 0.1), delta = 2, aligned = True) >>> alignedLcss.compute(range(5), range(5)) 5 >>> alignedLcss.compute(range(1,5), range(5)) 4 >>> alignedLcss.compute(range(5,10), range(10)) 5 >>> lcss.delta = 2 >>> lcss.compute(range(5,10), range(10)) 0 >>> alignedLcss.delta = 6 >>> alignedLcss.compute(range(5), range(5)) 5 >>> alignedLcss.compute(range(5), range(6)) 5 >>> lcss.delta = 10 >>> alignedLcss.compute(range(1,7), range(6)) 5