Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
txt = line.split(',')[5][:25]
#print txt
bv = binary.ais6tobitvec(txt) #line[5][:19]
# Try to throw out points as soon as possible. Use float rather than decimal. faster?? Maybe not
#lon = ais_msg_1.decodelongitude(bv)
lon = binary.signedIntFromBV(bv[61:89])/600000.0
if lonmaxx: continue
#print 'close1:',lon
#lat = ais_msg_1.decodelatitude(bv)
lat = binary.signedIntFromBV(bv[89:116])/600000.0
if latmaxy: continue
#print 'close2: POINT ('+str(lon)+' '+str(lat)+')'
point = Geometry.fromWKT('POINT ('+str(lon)+' '+str(lat)+')')
inside = point.within(poly)
if 1==inside:
outfile.write(line)
count+= 1
return count
def filter_file(infile, outfile, polygonWKT, verbose=False):
'''
For messages 1,2, and 3, see if the message is within the bounding box and send it to outfile if it is.
Polygon should look something like this... 'POLYGON ((-1.0 50.5, -0.5 51.2, 0.3 50.9, -1 50.5))'
param polygon: bounding region for the query
type polygon: WKT polygon string
'''
poly = Geometry.fromWKT(polygonWKT)
bbox = poly.envelope()
minx = bbox.minx # for speed, throw out points as soon as possible
maxx = bbox.maxx
miny = bbox.miny
maxy = bbox.maxy
if verbose:
print 'minLon maxLon minLat maxLat filename'
print minx, maxx, miny, maxy
count = 0
linenum=0
for line in infile:
linenum += 1
if linenum%1000==0:
sys.stderr.write('line '+str(linenum)+' -- count='+str(count)+'\n')