данные в словари area_country, d, area_x, area_z - добавляются автоматически вовремя парсинга логов, тут указаны вручную
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import glob, MySQLdb, time, re
from configobj import ConfigObj
def inArea(x, z, ax, az):
c=0
for i in range(len(ax)):
if (((az[i]<=z and z<az[i-1]) or (az[i-1]<=z and z<az[i])) and \
(x > (ax[i-1] - ax[i]) * (z - az[i]) / (az[i-1] - az[i]) + ax[i])): c = 1 - c
return c
area_country = {}
area_country['15360']='501'
area_country['124928']='501'
area_country['13312']='105'
area_country['19456']='501'
area_country['17408']='105'
area_country['129024']='0'
area_country['27648']='0'
area_country['122880']='0'
area_country['126976']='105'
d ={}
d["pos-x"]='29922.178'
d["pos-z"]='30734.535'
#area_x.update({d['aid'] : ax})
#area_z.update({d['aid'] : az})
area_x = {}
area_x['15360']='(27963.0, 24298.0, 28409.0, 29784.0, 32941.0, 42717.0, 41692.0, 54988.0, 55002.0, 54989.0)'
area_x['124928']='(25248.0, 27442.0, 27915.0, 35216.0, 41691.0, 42714.0, 32938.0, 29777.0, 28402.0, 24297.0, 23766.0)'
area_x['13312']='(54996.0, 54969.0, 54988.0, 41692.0, 38751.0, 34648.0, 30690.0, 26752.0, 25229.0)'
area_x['19456']='(24289.0, 27952.0, -5019.0, -4935.0, 11701.0, 13443.0, 19510.0)'
area_x['17408']='(25219.0, 26741.0, 20298.0, 11701.0, -4935.0, -4995.0, -4988.0)'
area_x['129024']='(24673.0, 25241.0, 23756.0, 24288.0, 19515.0, 13452.0, 11702.0, 23903.0, 23929.0)'
area_x['27648']='(27480.0, 27860.0, 28391.0, 27431.0, 25248.0, 24682.0, 23932.0, 23875.0, 25482.0)'
area_x['122880']='(30687.0, 34648.0, 38749.0, 41691.0, 35228.0, 27915.0, 28407.0, 27870.0, 27488.0, 26753.0)'
area_x['126976']='(11702.0, 20288.0, 26726.0, 27483.0, 23867.0, 23903.0)'
area_z = {}
area_z['15360']='(54983.0, 39109.0, 37779.0, 34705.0, 31049.0, 38109.0, 26800.0, 24150.0, 39702.0, 54989.0)'
area_z['124928']='(29122.0, 28304.0, 27667.0, 28386.0, 26800.0, 38103.0, 31048.0, 34701.0, 37772.0, 39099.0, 34735.0)'
area_z['13312']='(-5022.0, 6022.0, 24147.0, 26799.0, 19110.0, 18498.0, 17271.0, 13429.0, -4962.0)'
area_z['19456']='(39109.0, 54983.0, 54971.0, 26587.0, 24350.0, 31317.0, 37136.0)'
area_z['17408']='(-4963.0, 13429.0, 14389.0, 24349.0, 26581.0, 11197.0, -5000.0)'
area_z['129024']='(25766.0, 29118.0, 34735.0, 39099.0, 37129.0, 31310.0, 24350.0, 24448.0, 24989.0)'
area_z['27648']='(22899.0, 25262.0, 27033.0, 28300.0, 29112.0, 25761.0, 24982.0, 23823.0, 23422.0)'
area_z['122880']='(17280.0, 18508.0, 19118.0, 26799.0, 28368.0, 27667.0, 27043.0, 25261.0, 22891.0, 13445.0)'
area_z['126976']='(24349.0, 14408.0, 13437.0, 22883.0, 23818.0, 24447.0)'
captured = 0
for area in area_country:
print area, float(d['pos-x']), float(d['pos-z']), area_x[area], area_z[area]
print type(d['pos-x']), type(d['pos-z']), type(area_x[area]), type(area_z[area])
landed_area = (inArea(float(d['pos-x']), float(d['pos-z']), area_x[area], area_z[area]))
print landed_area
print area
if landed_area == 1:
break
print "stop"
Traceback (most recent call last):
File "D:\Python!\PARSER-OTHER\trabl2.py", line 59, in <module>
landed_area = (inArea(float(d['pos-x']), float(d['pos-z']), area_x[area], area_z[area]))
File "D:\Python!\PARSER-OTHER\trabl2.py", line 9, in inArea
if (((az[i]<=z and z<az[i-1]) or (az[i-1]<=z and z<az[i])) and \
IndexError: string index out of range