#!/usr/bin/env python # coding: utf-8 # In[1]: get_ipython().run_line_magic('matplotlib', 'inline') # In[2]: import matplotlib.pyplot as plt # In[24]: from geographiclib.geodesic import Geodesic lat1, lon1 = 43, -75 lat2, lon2 = 1.359, 103.989 g = Geodesic.WGS84.Inverse(lat1, lon1, lat2, lon2) h = Geodesic.WGS84.Direct(lat1, lon1, g['azi1'], g['s12']/2) # In[25]: gc = [Geodesic.WGS84.Direct(lat1, lon1, g['azi1'], i) for i in range(0,int(g['s12']),100000)] # In[26]: lat = [i['lat2'] for i in gc] lat.append(lat2) lon = [i['lon2'] for i in gc] lon.append(lon2) plt.plot(lon,lat,'-'); # In[27]: from geojson import MultiPoint, LineString mp =[(coors['lon2'], coors['lat2']) for coors in gc ] f = open('new.geojson','w') f.write(str(LineString(mp))) f.close() # ##GeoJson # In[28]: get_ipython().system('/usr/local/bin/gist -p new.geojson') # ##CZML # In[29]: a = [] for p in mp: a.extend([p[0],p[1],0]) # In[30]: get_ipython().run_cell_magic('file', 'czml_templates.py', '\npolyline_tpl = """\n {\n "polyline": {\n "width":%s,\n "material":{\n "solidColor":{\n "color":{\n "rgba":[\n %s,%s,%s,%s\n ]\n }\n }\n },\n "positions": {\n "%s": %s\n }, "id": "%s"\n }\n }\n """ \n\nczml_tpl = """\n[\n {\n "version": "1.0",\n "id": "document"\n },\n %s\n]\n"""\n') # In[31]: from czml_templates import polyline_tpl, czml_tpl import numpy as np def polyline(width=1, rgba=(0,255,255,255), coorstype="cartographicDegrees", coors=[], id=""): polyline = polyline_tpl % (width, rgba[0], rgba[1], rgba[2], rgba[3], coorstype, coors, id) return polyline def czml(features): czml=czml_tpl % features return czml pl1 = polyline(coors=a, id='test1') pl2 = polyline(coors=list(np.array(a)/2), id='test2') # In[32]: features = str(pl1)+','+str(pl2) # In[41]: polyline1 = czml(str(pl1)) # In[42]: polyline2 = czml(features) # In[43]: from CesiumWidget import CesiumWidget # In[44]: cesiumExample = CesiumWidget(width="100%", czml=polyline1) # In[46]: cesiumExample # In[47]: cesiumExample.czml = polyline2 # In[37]: from IPython.core.display import Image Image("screen.png") # In[ ]: