Add geojson export method for Trajectory groundtrack and instrument FoVs
It should be possible to export the Trajectory
groundtrack and InstrumentTrajectory
field of views as valid geosjon
files.
geojson
file must be provided as WGS 84
projected data and sliced at the 180° antimeridian. Therefore the data need to projected with an Equirectangular(lon_e_0=0)
projection, sliced into multiple polygons and json-formatted.
Proposed interface:
export_geojson(fname, traj, props=('utc', 'alt', 'inc'), color='inc', cmap='turbo', vmin=None, vmax=None)
Use case:
Expected output in geojson.io:
We can see that the polygons at the antimeridian and the poles were properly sliced.
Here is a proposal of implementation of the slicing part:
EQ_PROJ = Equirectangular(lon_e_0=0) # Equirectangular projection centered at 180° required by RFC7946
def export_geojson(fname, traj):
"""Export trajectory field of views as geojson file."""
proj_paths = EQ_PROJ.xy_collection(traj.fovs).get_paths()
geojson = json.dumps({
'type': 'Feature',
'geometry': {
'type': 'MultiPolygon',
'coordinates': [
[
vertices.tolist()
for vertices in np.split(
proj_path.vertices,
np.where(proj_path.codes == Path.CLOSEPOLY)[0] + 1
)[:-1]
]
for proj_path in proj_paths
if proj_path is not None
]
},
'properties': {},
})
pathlib.Path(fname).write_text(geojson)
return fname
Support for the properties broadcasting need to be added.
In the case of SpacecraftTrajectory
object (without an instrument FoV), the output should return a sliced MultiLineString
of the groundtrack.