Www.tandfonline.com



Search.py-----------------------------------------------------------#!/usr/bin/env python # -*- coding:utf-8 -*-code='000010000110100110000110100000000'llh='+59.0_+170.0_+0000'time=['2015032912000','2015032918000','2015033000000','2015033006000','2015033012001','2015033018001','2015033100001']file1='/Users/yujian/Desktop/毕设/区域查询文件2/1_5.txt'file2='/Users/yujian/Desktop/毕设/区域查询文件2/1_5_code.txt'result1='['result2='['lat_lon_h='['lat_lon_h_t='['for j in range(2, 7): code_t = code + time[j] for k in range(10): code_t = code_t[:-2] + str(k) + code_t[-1] result2 = result2 + '\'' + code_t + '\'' + ','for j in range(2,7): llh_t=llh+'_'+time[j] for k in range(10): llh_t=llh_t[:-2]+str(k)+llh_t[-1] lat_lon_h_t=lat_lon_h_t+'\''+llh_t+'\''+','result1=result1[:-1]+']'result2=result2[:-1]+']'lat_lon_h=lat_lon_h[:-1]+']'lat_lon_h_t=lat_lon_h_t[:-1]+']'with open(file1,'w') as f1: f1.write(lat_lon_h) f1.write('\n') f1.write(lat_lon_h_t)with open(file2,'w') as f1: f1.write(result1) f1.write('\n')f1.write(result2)-----------------------------------------------------------MongoClient.py-----------------------------------------------------------#!/usr/bin/env python # -*- coding:utf-8 -*-import sys##reload(sys)##sys.setdefaultencoding('utf-8')file='/Users/yujian/Desktop/毕设/ocean2/data.txt'from pymongo import MongoClientmongo_url='127.0.0.1:27017'client=MongoClient(mongo_url)DATABASE='ocean_bin_10'db=client[DATABASE]COLLECTION='ocean_all'collection=db[COLLECTION]logs=collection.find({'$and':[{'lat':{'$gte':53,'$lt':57}},{'lon':{'$gte':151,'$lt':155}},{'height':0},{'time':{'$gte':2015032912000,'$lt':2015032912090}}]},{'_id':1,'code':1})result1='['result2='['for item in logs: result1=result1+'\''+item['_id']+'\''+',' result2=result2+'\''+item['code']+'\''+','result1=result1[:-1]+']'result2=result2[:-1]+']''''print(result1)print(result2)'''with open(file,'w') as f: f.write(result1) f.write('\n') f.write(result2)-----------------------------------------------------------Expand.py-----------------------------------------------------------#!/usr/bin/env python # -*- coding:utf-8 -*-import jsonfile='/Users/yujian/Desktop/毕设/ocean2/ocean_bin.json'file1='/Users/yujian/Desktop/毕设/ocean2/ocean_bin_x10.json'result=[]with open(file,'r') as f: for line in f: for i in range(10): linei = json.loads(line) if len(linei['_id'])==33: linei['_id']+='2015032912000' linei['_id']=linei['_id'][:-2]+str(i)+linei['_id'][-1] linei['time']=int(linei['_id'][-13:]) result.append(linei)with open(file1,'w') as k: for j in result: k.write(json.dumps(j)) k.write('\n')-----------------------------------------------------------Complete.py-----------------------------------------------------------#!/usr/bin/env python# -*- coding:utf-8 -*-import jsonfile='/Users/yujian/Desktop/毕设/ocean2/ocean_bin_x10.json'file1='/Users/yujian/Desktop/毕设/ocean2/ocean_bin_all_1.json'result=[]with open(file,'r') as f: for line in f: linei=json.loads(line) linei['geosot_3d']=linei['_id'][:33] linei['geosot_4d']=linei['_id'] linei['lat'] = float('%.1f' % linei['lat']) linei['lon'] = float('%.1f' % linei['lon']) linei['height'] = int(linei['height']) lat=str(linei['lat']) lon=str(linei['lon']) height=str(linei['height']) if len(lat)<5 : if lat[0]=='-': lat=lat[1:] lat=lat.rjust(4,'0') lat='-'+lat else: lat=lat.rjust(4,'0') lat='+'+lat if len(lon)<6: if lon[0]=='-': lon=lon[1:] lon=lon.rjust(5,'0') lon='-'+lon else: lon=lon.rjust(5,'0') lon='+'+lon if len(height)<5: if height[0]=='-': height=height[1:] height=height.rjust(4,'0') height='-'+height else: height=height.rjust(4,'0') height='+'+height linei['lat_lon_h']=lat+'_'+lon+'_'+height linei['lat_lon_h_t']=linei['lat_lon_h']+'_'+str(linei['time']) result.append(linei)with open(file1,'w') as f1: for j in result: f1.write(json.dumps(j)) f1.write('\n')-----------------------------------------------------------GeoSOT_3d.py-----------------------------------------------------------#!/usr/bin/env python # -*- coding:utf-8 -*-from geosot_encode3d import decode_geosot_3ddef bin2hex(str_num): #二进制转十六进制 return str(hex(int(str_num,2)))[2:].zfill(3)file='/Users/yujian/Desktop/毕设/区域查询文件2/4x4_18-124.txt'file1='/Users/yujian/Desktop/毕设/区域查询文件2/4x4_18-124_1.txt'file2='/Users/yujian/Desktop/毕设/区域查询文件2/4x4_18-124_1_code.txt'result1='['result2='['lat_lon_h='['lat_lon_h_t='['timestr='['time=['2015032912000','2015032918000','2015033000000','2015033006000','2015033012001','2015033018001','2015033100001']with open(file,'r') as f: for line in f: lon=line.split()[0] lat=line.split()[1] lon=bin(int(lon))[2:] lat=bin(int(lat))[2:] lon=lon.rjust(32,'0') lat=lat.rjust(32,'0') lon=lon[:11] lat=lat[:11] code='' for i in range(11): code=code+lat[i]+lon[i]+'0' result1=result1+'\''+code+'\''+',' for j in range(1,2): code_t=code+time[j] for k in range(10): code_t=code_t[:-2]+str(k)+code_t[-1] result2=result2+'\''+code_t+'\''+',' llh='' lat_1=float('%.1f' % decode_geosot_3d(code)['min_coord'][0]) lon_1=float('%.1f' % decode_geosot_3d(code)['min_coord'][1]) height_1=int(float('%.1f' % decode_geosot_3d(code)['min_coord'][2])) lat=str(lat_1) lon=str(lon_1) height=str(height_1) if len(lat)<5 : if lat[0]=='-': lat=lat[1:] lat=lat.rjust(4,'0') lat='-'+lat else: lat=lat.rjust(4,'0') lat='+'+lat if len(lon)<6: if lon[0]=='-': lon=lon[1:] lon=lon.rjust(5,'0') lon='-'+lon else: lon=lon.rjust(5,'0') lon='+'+lon if len(height)<5: if height[0]=='-': height=height[1:] height=height.rjust(4,'0') height='-'+height else: height=height.rjust(4,'0') height='+'+height llh=lat+'_'+lon+'_'+height lat_lon_h=lat_lon_h+'\''+llh+'\''+',' for j in range(2,7): llh_t=llh+'_'+time[j] for k in range(10): llh_t=llh_t[:-2]+str(k)+llh_t[-1] lat_lon_h_t=lat_lon_h_t+'\''+llh_t+'\''+','''' for j in range(2,7): timei=time[j] for k in range(10): timei = timei[:-2] + str(k) + timei[-1] timestr = timestr + '\'' + timei + '\'' + ','' '''result1=result1[:-1]+']'result2=result2[:-1]+']'lat_lon_h=lat_lon_h[:-1]+']'lat_lon_h_t=lat_lon_h_t[:-1]+']'''' timestr=timestr[:-1]+']' '''with open(file1,'w') as f1: f1.write(lat_lon_h) f1.write('\n') f1.write(lat_lon_h_t)with open(file2,'w') as f1: f1.write(result1) f1.write('\n') f1.write(result2)-----------------------------------------------------------NoIndex.py-----------------------------------------------------------#!/usr/bin/env python # -*- coding:utf-8 -*-import jsonfile='/Users/yujian/Desktop/毕设/ocean2/ocean_bin_x10.json'file1='/Users/yujian/Desktop/毕设/ocean2/ocean_bin_x10_no.json'result=[]with open(file,'r') as f: for line in f: linei=json.loads(line) linei['geosotcode']=linei.pop('_id') result.append(linei)with open(file1,'w') as f: for i in result: f.write(json.dumps(i)) f.write('\n')-----------------------------------------------------------transfer.py-----------------------------------------------------------#!/usr/bin/env python # -*- coding:utf-8 -*-import jsonimport copyimport osimport sysfilepath='/Users/yujian/Desktop/毕设/ocean2/ocean_bin_all_1.json'decpath='/Users/yujian/Desktop/毕设/ocean2/ocean_dec.json'octpath='/Users/yujian/Desktop/毕设/ocean2/ocean_oct.json'hexpath='/Users/yujian/Desktop/毕设/ocean2/ocean_hex.json'def bin2dec(str_num): #二进制转十进制 return str(int(str_num,2)).zfill(4)def bin2oct(str_num): #二进制转八进制 return str(oct(int(str_num,2)))[2:].zfill(4)def bin2hex(str_num): #二进制转十六进制 return str(hex(int(str_num,2)))[2:].zfill(3)resultdec=[]resultoct=[]resulthex=[]with open(filepath,'r') as file: for line in file: code=json.loads(line)['_id'] lat='' lon='' height='' for i in range(11): lat+=code[3*i] lon+=code[3*i+1] height+=code[3*i+2]#二进制转十六进制 lat_hex = bin2hex(lat) lon_hex = bin2hex(lon) height_hex = bin2hex(height) codehex = '' for j in range(len(lat_hex)): codehex += lat_hex[j] codehex += lon_hex[j] codehex += height_hex[j] linek=json.loads(line) linek['geosot_3d'] = codehex codehex += code[33:] linek['_id'] = codehex linek['geosot_4d'] = codehex resulthex.append(linek)'''with open(decpath,'w') as f: for i in resultdec: f.write(json.dumps(i)) f.write('\n')with open(octpath, 'w') as f1: for j in resultoct: f1.write(json.dumps(j)) f1.write('\n')'''with open(hexpath, 'w') as f2: for k in resulthex: f2.write(json.dumps(k)) f2.write('\n')-----------------------------------------------------------Geosot_encode3d.py-----------------------------------------------------------# def encode_geosot_2d(level, lat, lon):# let lat_deg_min_sec = get_deg_min_sec(lat)# let lon_deg_min_sec = get_deg_min_sec(lon)## let lat_deg_bin = lat_deg_min_sec[0].toString(2)# let lon_deg_bin = lon_deg_min_sec[0].toString(2)# lat_deg_bin = Array(9 - lat_deg_bin.length).join('0') + lat_deg_bin# lon_deg_bin = Array(9 - lon_deg_bin.length).join('0') + lon_deg_bin## let lat_min_bin = lat_deg_min_sec[1].toString(2)# let lon_min_bin = lon_deg_min_sec[1].toString(2)# lat_min_bin = Array(7 - lat_min_bin.length).join('0') + lat_min_bin# lon_min_bin = Array(7 - lon_min_bin.length).join('0') + lon_min_bin## let lat_sec_bin = Math.floor(lat_deg_min_sec[2] / LON_LAT_DMS_TABLE[level]).toString(2)# let lon_sec_bin = Math.floor(lon_deg_min_sec[2] / LON_LAT_DMS_TABLE[level]).toString(2)# if(level>15){# //b0 = Array(0).join('0'); --> ''# //b1 = Array(1).join('0'); --> ''# //b2 = Array(2).join('0'); --> '0'# //b3 = Array(3).join('0'); --> '00'## lat_sec_bin = Array(level + 1 - 15 - lat_sec_bin.length).join('0') + lat_sec_bin# lon_sec_bin = Array(level + 1 - 15 - lon_sec_bin.length).join('0') + lon_sec_bin# }# else{# lat_sec_bin = ""# lon_sec_bin = ""# }# let lat_bin = lat_deg_bin.substr(0, 9) + lat_min_bin.substr(0, 7) + lat_sec_bin# let lon_bin = lon_deg_bin.substr(0, 9) + lon_min_bin.substr(0, 7) + lon_sec_bin# let lat_cap = lat >= 0 ? '0' : '1'# let lon_cap = lon >= 0 ? '0' : '1'## lat_bin = lat_cap + lat_bin# lon_bin = lon_cap + lon_bin# let code_array = Array()# for var i = 0; i < level; i++:# code_array.append(lat_bin[i])# code_array.append(lon_bin[i])## return code_array.join('')# edited by lm-2018-11-29import mathLON_LAT_TABLE = { 0: 512, 1: 256, 2: 128, 3: 64, 4: 32, 5: 16, 6: 8, 7: 4, 8: 2, 9: 1, 10: 1 / 2, 11: 1 / 4, 12: 1 / 8, 13: 1 / 16, 14: 1 / 32, 15: 1 / 64, 16: 1 / 128, 17: 1 / 256, 18: 1 / 512, 19: 1 / 1024, 20: 1 / 2048, 21: 1 / 5096}LON_LAT_DMS_TABLE = { 0: 512, 1: 256, 2: 128, 3: 64, 4: 32, 5: 16, 6: 8, 7: 4, 8: 2, 9: 1, 10: 32, 11: 16, 12: 8, 13: 4, 14: 2, 15: 1, 16: 32, 17: 16, 18: 8, 19: 4, 20: 2, 21: 1, 22: 1 / 2, 23: 1 / 4, 24: 1 / 8, 25: 1 / 16, 26: 1 / 32, 27: 1 / 64, 28: 1 / 128, 29: 1 / 256, 30: 1 / 512, 31: 1 / 1024, 32: 1 / 2048}HEIGHT_TABLE = {};HEIGHT_TABLE_UNDERGROUND = {}def create_table(max_height): HEIGHT_TABLE[0] = max_height; for i in range(1,31): HEIGHT_TABLE[i] = HEIGHT_TABLE[i - 1] / 2;def create_table_underground(max_height): HEIGHT_TABLE_UNDERGROUND[0] = max_height for i in range(1,31): HEIGHT_TABLE_UNDERGROUND[i] = HEIGHT_TABLE_UNDERGROUND[i - 1] / 2create_table(math.pow(2, 27))create_table_underground(pow(2, 23))def get_deg_min_sec(degree): degree = abs(degree) deg = math.floor(degree) minute = math.floor(degree * 60 - deg * 60) second = degree * 3600 - deg * 3600 - minute * 60 return [deg, minute, second]def encode_geosot_3d(level, lat, lon, height,HEIGHT_TABLE_UNDERGROUND): lat_deg_min_sec = get_deg_min_sec(lat) lon_deg_min_sec = get_deg_min_sec(lon) # lat_deg_bin = lat_deg_min_sec[0].toString(2) # lon_deg_bin = lon_deg_min_sec[0].toString(2) # lat_deg_bin = Array(9 - lat_deg_bin.length).join('0') + lat_deg_bin # lon_deg_bin = Array(9 - lon_deg_bin.length).join('0') + lon_deg_bin # 转2进制字符串 # print(bin(lat_deg_min_sec[0])) lat_deg_bin = bin(lat_deg_min_sec[0])[2:] # print(bin(lat_deg_min_sec[0])[2:]) lon_deg_bin = bin( lon_deg_min_sec[0])[2:] # 补位 lat_deg_bin = ''.join(['0' for i in range(8 - len(lat_deg_bin))]) + lat_deg_bin lon_deg_bin = ''.join(['0' for i in range(8 - len(lon_deg_bin))]) + lon_deg_bin # lat_min_bin = lat_deg_min_sec[1].toString(2) # lon_min_bin = lon_deg_min_sec[1].toString(2) # lat_min_bin = Array(7 - lat_min_bin.length).join('0') + lat_min_bin # lon_min_bin = Array(7 - lon_min_bin.length).join('0') + lon_min_bin lat_min_bin = bin(lat_deg_min_sec[1])[2:] lon_min_bin = bin(lon_deg_min_sec[1])[2:] lat_min_bin = ''.join(['0' for i in range(6 - len(lat_min_bin))]) + lat_min_bin lon_min_bin = ''.join(['0' for i in range(6 -len(lon_min_bin))]) + lon_min_bin lat_sec_bin = bin(math.floor(lat_deg_min_sec[2] / LON_LAT_DMS_TABLE[level]))[2:] lon_sec_bin = bin(math.floor(lon_deg_min_sec[2] / LON_LAT_DMS_TABLE[level]))[2:] if(level>15): lat_sec_bin = ''.join(['0' for i in range(level-15 - len(lat_sec_bin))]) + lat_sec_bin lon_sec_bin =''.join(['0' for i in range(level-15 - len(lon_sec_bin))]) + lon_sec_bin# lat_sec_bin = Array(level + 1 - 15 - lat_sec_bin.length).join('0') + lat_sec_bin# lon_sec_bin = Array(level + 1 - 15 - lon_sec_bin.length).join('0') + lon_sec_bin else: lat_sec_bin = "" lon_sec_bin = "" lat_bin = lat_deg_bin[0: 8] + lat_min_bin[0: 6] + lat_sec_bin lon_bin = lon_deg_bin[0: 8] + lon_min_bin[0: 6] + lon_sec_bin if (height>0): height_bin = bin(math.floor(abs(height) / HEIGHT_TABLE[level]))[2:] else: height_bin = bin(math.floor(abs(height) / HEIGHT_TABLE_UNDERGROUND[level]))[2:] height_bin = ''.join(['0' for i in range(level - len(height_bin))]) + height_bin # height_bin = Array(level - height_bin.length).join('0') + height_bin lat_cap = '0' if lat >= 0 else '1' lon_cap = '0' if lon >= 0 else '1' height_cap = '0' if height >= 0 else '1' lat_bin = lat_cap + lat_bin lon_bin = lon_cap + lon_bin height_bin = height_cap + height_bin codeList = [] for i in range(level): codeList.append(lat_bin[i]) codeList.append(lon_bin[i]) codeList.append(height_bin[i]) return ('').join(codeList)def decode_geosot_3d(code): level=len(code)/3 part_label=0 latArray_degree='' lonArray_degree='' latArray_minute='' lonArray_minute='' latArray_second='' lonArray_second='' heightArray='' for i in range(3,len(code)): if i%3==0: if part_label<9-1: latArray_degree+=code[i] elif part_label<15-1: latArray_minute+=code[i] else: latArray_second+=code[i] elif i%3==1: if part_label<9-1: lonArray_degree+=code[i] elif part_label<15-1: lonArray_minute+=code[i] else: lonArray_second+=code[i] part_label+=1 else: heightArray+=code[i] if len(lonArray_degree)>0: latInt_degree=int(latArray_degree,2) lonInt_degree=int(lonArray_degree,2) else: latInt_degree=0 lonInt_degree=0 if len(lonArray_minute)>0: latInt_minute=int(latArray_minute,2) lonInt_minute=int(lonArray_minute,2) else: latInt_minute=0 lonInt_minute=0 if len(lonArray_second)>0: latInt_second=int(latArray_second,2) lonInt_second=int(lonArray_second,2) else: latInt_second=0 lonInt_second=0 latminute_part_min=60 if latInt_minute*LON_LAT_DMS_TABLE[level if level<15 else 15]>60 else latInt_minute*LON_LAT_DMS_TABLE[level if level<15 else 15] lonminute_part_min=60 if lonInt_minute*LON_LAT_DMS_TABLE[level if level<15 else 15]>60 else lonInt_minute*LON_LAT_DMS_TABLE[level if level<15 else 15] latsecond_part_min=60 if latInt_second*LON_LAT_DMS_TABLE[level] >60 else latInt_second*LON_LAT_DMS_TABLE[level] lonsecond_part_min=60 if lonInt_second*LON_LAT_DMS_TABLE[level] >60 else lonInt_second*LON_LAT_DMS_TABLE[level] unlatMin=latInt_degree*LON_LAT_DMS_TABLE[level if level<9 else 9]+latminute_part_min/60 +latsecond_part_min/3600 unlonMin=lonInt_degree*LON_LAT_DMS_TABLE[level if level<9 else 9]+lonminute_part_min/60 +lonsecond_part_min/3600 if level<=9: unlatMax=(latInt_degree+1)*LON_LAT_DMS_TABLE[level] unlonMax=(lonInt_degree+1)*LON_LAT_DMS_TABLE[level] unlatMax=unlatMax if unlatMax<90 else 90 unlonMax=unlonMax if unlonMax<180 else 180 elif level<=15: latminute_part_max=60 if (latInt_minute+1)*LON_LAT_DMS_TABLE[level]>60 else (latInt_minute+1)*LON_LAT_DMS_TABLE[level] lonminute_part_max=60 if (lonInt_minute+1)*LON_LAT_DMS_TABLE[level]>60 else (lonInt_minute+1)*LON_LAT_DMS_TABLE[level] unlatMax=latInt_degree*LON_LAT_DMS_TABLE[9]+latminute_part_max/60 unlonMax=lonInt_degree*LON_LAT_DMS_TABLE[9]+lonminute_part_max/60 else: latsecond_part_max=60 if (latInt_second+1)*LON_LAT_DMS_TABLE[level]>60 else (latInt_second+1)*LON_LAT_DMS_TABLE[level] lonsecond_part_max=60 if (lonInt_second+1)*LON_LAT_DMS_TABLE[level]>60 else (lonInt_second+1)*LON_LAT_DMS_TABLE[level] unlatMax=latInt_degree*LON_LAT_DMS_TABLE[9]+latInt_minute*LON_LAT_DMS_TABLE[15]/60 +latsecond_part_max/3600 unlonMax=lonInt_degree*LON_LAT_DMS_TABLE[9]+lonInt_minute*LON_LAT_DMS_TABLE[15]/60 +lonsecond_part_max/3600 latMin=unlatMin if code[0]=='0' else -unlatMax lonMin=unlonMin if code[1]=='0' else -unlonMax latMax=unlatMax if code[0]=='0' else -unlatMin lonMax=unlonMax if code[1]=='0' else -unlonMin heightInt=int(heightArray,2) heightResolution=HEIGHT_TABLE[level] heightResolution_Underground=HEIGHT_TABLE_UNDERGROUND[level] heightMin=heightInt*heightResolution if code[2]=='0' else -heightInt*heightResolution_Underground-heightResolution_Underground heightMax=heightInt*heightResolution+heightResolution if code[2]=='0' else -heightInt*heightResolution_Underground latMin=-90 if latMin<-90 else latMin lonMin=-180 if lonMin<-180 else lonMin latMax= 90 if latMax>90 else latMax lonMax=180 if lonMax>180 else lonMax return { 'level':level, 'min_coord':[latMin,lonMin,heightMin], 'max_coord':[latMax,lonMax,heightMax]}if __name__ =="__main__": print(encode_geosot_3d(11,-29.533,49,0,HEIGHT_TABLE_UNDERGROUND)) print('100010010010100100110000110000100') print(decode_geosot_3d('110010010110010100100010010000000'))-----------------------------------------------------------test.py-----------------------------------------------------------#!/usr/bin/env python # -*- coding:utf-8 -*-import reimport jsonfrom geosot_encode3d import decode_geosot_3dfilepath='/Users/yujian/Desktop/毕设/ocean2/ocean2.txt'jsonpath='/Users/yujian/Desktop/毕设/ocean2/ocean_bin.json'result=[]with open(filepath,'r') as file: line=file.readline() while line : a={'_id':None,'lat':None,'lon':None,'height':None,'time':None,'cur_uz':None,'cur_vz':None,'hs':None,'tem':None,'wind':None} b=[] b=list(re.split('[,\s=:]',line)) a['_id']=b[1] code=b[1][:33] a[b[4]]=b[-2] a['lat']=float('%.3f' % decode_geosot_3d(code)['min_coord'][0]) a['lon']=float('%.3f' % decode_geosot_3d(code)['min_coord'][1]) a['height'] = float('%.3f' % decode_geosot_3d(code)['min_coord'][2]) a['time']=b[1][33:] line=file.readline() b = list(re.split('[,\s=:]', line)) while a['_id']==b[1]: a[b[4]]=b[-2] line=file.readline() if not line: break b = list(re.split('[,\s=:]', line)) result.append(a)with open(jsonpath,'w') as f: for i in result: f.write(json.dumps(i)) f.write('\n')-----------------------------------------------------------txtEdit.py-----------------------------------------------------------#!/usr/bin/env python # -*- coding:utf-8 -*-file='/Users/yujian/Library/Mobile Documents/com~apple~TextEdit/Documents/2x2.txt'with open(file,'r') as f: line=f.readline() str='[' while line: code=line[10:58] str+=code str+=',' line=f.readline() str=str[:-1] str+=']' print(str)with open(file,'w') as f: f.write(str)----------------------------------------------------------- ................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download