#!/opt/anaconda3/envs/py37/bin/python from pandas import * import twd97,sys from pyproj import Proj import numpy as np def getarg(): """ read the setting of plot from argument(std input)""" import argparse ap = argparse.ArgumentParser() ap.add_argument("-f", "--fname", required = True, type=str,help = "csv with x,y,Name,Label") ap.add_argument("-n", "--NorH", required = True, type=str,help = "Normal/Highlight/Dot/Reddot/Blackdot/Polygon") ap.add_argument("-g", "--GEOG", required = True, type=str,help = "LL or TWD97") args = vars(ap.parse_args()) return args['fname'],args['NorH'],args['GEOG'] def isfloat(value): try: float(value) return True except ValueError: return False fname,NorH,geog=getarg() NorH,geog=NorH.upper(),geog.upper() LL,TWD97=False,False if geog=='LL': LL=True if geog=='TWD97': TWD97=True if NorH[0] not in 'HNDRBP' :sys.exit('NorH not right') NH=NorH.replace('C','').replace('L','') #B:target with black arona #R:red target #D:dot target stl={'N':'normalPlacemark','H':"highlightPlacemark",'D':"dotPlacemark",'B':"blackdotPlacemark",'R':"reddotPlacemark"} #csv with 4 columns, #xp,yp,Hour,ymdh #266567.0,2549275.0,hour=0,ymd=2019062315 df=read_csv(fname)#,encoding='big5') if isfloat(df.columns[0]): df=read_csv(fname,header=None)#,encoding='big5') STR='XYND' df.columns=[STR[i] for i in range(len(df.columns))] if len(df.columns)==2: df['Name']=['pt'+str(i) for i in df.index] df['Desc']=['Desc'+str(i) for i in df.index] TITLE=fname head0=''+ \ ''+TITLE+''+TITLE+'' #store the lines line=[head0] #icons may be used in KML file: sty_pngs={'H':'paddle/red-stars.png','N':'paddle/wht-blank.png','B':'pal4/icon25.png','D':'pal4/icon57.png','R':'pal4/icon49.png',} if 'P' not in NorH: #declarations of Placemark styles for s in stl: stl_url='' exec('styl'+s+"='"+stl_url+"'") exec('line.append(styl'+s+')') else: #colors prepare 10 colors, only one will be adopted, which is determined by random generator N=10 col = '#00FF0A #3FFF0A #7FFF0A #BFFF0A #FFFF0A #FECC0A #FD990A #FC660A #FB330A #FA000A'.replace('#', '').split() if len(col) != N: print ('color scale not right, please redo from http://www.zonums.com/online/color_ramp/') aa = '28' # ''28'~ 40%, '4d' about 75% rr, gg, bb = ([i[j:j + 2] for i in col] for j in [0, 2, 4]) col = [aa + b + g + r for b, g, r in zip(bb, gg, rr)] col0 = '4d6ecdcf' col_line0 = 'cc2d3939' st_head = '' st_med = '1' st_tail = '' for i in range(N): st_head += '