In this article we will generate a RasterFrame then write it to a GeoTiFF file, a common file format for raster data. After this we will download it to a location on your desktop or laptop, where it can then be uploaded to other GIS software. For this case, we'll very briefly show the process for QGIS.
In a previous article, we calculated NDVI from MODIS data for the Yellowstone region. We'll briefly do that again here and write the RasterFrame results into a GeoTIFF file.
from earthai.init import *
catalog = earth_ondemand.read_catalog(
bandsNDVI = spark.read.raster(catalog, catalog_col_names=['B01', 'B02'],)\
.withColumnRenamed('B01', 'red') \
bandsNDVI = bandsNDVI.withColumn('ndvi', rf_normalized_difference('nir', 'red'))
When you run the code above you should end up with a Spark DataFrame named bandsNDVI that contains the red and NIR bands from the MODIS MCD43A4 collection, and the calculated column "ndvi" appended at the end. You can run the following code that displays a few of the attributes to confirm that the calculation succeeded.
Next we write the bandsNDVI Spark DataFrame to a GeoTIFF. In this case the GeoTIFF filename is chosen to be "ndvi.tiff" and it is saved to the local EarthAI Notebook directory. You also have to specify a coordinate reference system (CRS) for the destination file. In this case we're using EPSG:3857 as it helps with visualization on maps. Note that the code below will throw an error if you do not include a CRS.
This may take some time to complete. When finished you'll see the "ndvi.tiff" file appear in the file list on the left sidebar in the workspace.
Now right click "ndvi.tiff" and select "Download". This downloads the GeoTIFF to your desktop or laptop.
Now this GeoTIFF can be used in a wide array of GIS applications. One example is reading it into QGIS, an open-source GIS software platform (which you can download and install from here). With QGIS open on your computer and in an active project, under the Layer drop-down menu select Add Layer, and from the second pop-out menu select Add Raster Layer.... This will bring up a window where you can navigate to and select the "ndvi.tiff" file that you downloaded to your computer from EarthAI Notebook.