Grupo 1 Accessing Satellite Imagery Using Python
Grupo 1 Accessing Satellite Imagery Using Python
Open in app
Search
Get unlimited access to the best of Medium for less than $1/week. Become a member
As a Geospatial Analyst, you may want to access and analyze satellite imagery
using python and carry out your analysis from there. This article is meant to give
you an understanding of how you can do that simply using Python. This may be
carried out in either Jupyter Notebooks or Google Colab.
NB: I have provided a link to the Github repository at the end of this article from
1 de 14 6/06/24, 17:38
Accessing Satellite Imagery Using Python | by LAW... https://medium.com/@kimutai.lawrence19/accessing-s...
where you can access the code. You can run this code on Google Colab as we go
along.
Accessing data: We will use Sentinel 2 data. There are many options to access
Sentinel 2 images and most of them will require you to access through website
interaction whether directly via a downloading service utility or via the cloud.
However, since we are using Jupyter notebook, we will access them right here
using, sentinelsat a python library which makes searching, retrieving and
downloading Sentinel satellite images easy. So let us start installing sentinelsat
through pip. We also install other packages that we will use as we continue.
import folium
import os
import numpy as np
import pandas as pd
import numpy as np
import rasterio
import fiona
import wget
2 de 14 6/06/24, 17:38
Accessing Satellite Imagery Using Python | by LAW... https://medium.com/@kimutai.lawrence19/accessing-s...
You are set to use sentinelsat and download Sentinel Satellite images.We then use
define the study area in this article we are going to use boundary data from Lagos
City, Nigeria.(I uploaded the boundary for Lagos city,Nigeria here on google
colab) . We thus access the boundary data(Lagos shapefile) via the Lagos
shapefile path and we will read it with Geopandas and visualize it with Folium
python library.
print("Installing geopandas...")
print("Loading Shapefile...")
shapefile = gpd.read_file("/content/Lagosnigeria.shp")
# The "head" function prints out the first five rows in full, so
3 de 14 6/06/24, 17:38
Accessing Satellite Imagery Using Python | by LAW... https://medium.com/@kimutai.lawrence19/accessing-s...
shapefile.head()
Lagos Shapefile.
One last step before we can search and download sentinel 2 images is to create a
footprint from the Lagos Shapefile Geometry. Here we will use Shapely Python
library since our data is in Shapefiles and have read it already as Geopandas
GeodataFrame. (Note that if you have Geojson data, sentinelsatprovides a handy
way to convert your data into a proper format in the query).
footprint = None
for i in shapefile['geometry']:
footprint = i
Now we can run a query on the api we have created above. There are different
ways you can construct your query here depending on your use case. In this
example, we will create a query for Sentinel 2 images Level 2A with cloud
coverage between 0 and 10 that fall or intersect with the footprint (Area of
study:”in our case Lagos City”). For the time period, we are interested only in
Sentinel Level 2A satellite images taken between ‘20220101’ and ‘20220120’ (For
reference on valid search queries please refer to scihub).
products = api.query(footprint,
4 de 14 6/06/24, 17:38
Accessing Satellite Imagery Using Python | by LAW... https://medium.com/@kimutai.lawrence19/accessing-s...
platformname = 'Sentinel-2',
processinglevel = 'Level-2A',
cloudcoverpercentage = (0,10)
products_gdf = api.to_geodataframe(products)
products_gdf_sorted =
products_gdf.sort_values(['cloudcoverpercentage'],
ascending=[True])
products_gdf_sorted
From the results that are acquired above, you can now download your Sentinel 2
data (specific) from the list of outputs.
api.download("ab40b37d-d1ae-4592-bb01-3ed0adf2527a")
5 de 14 6/06/24, 17:38
Accessing Satellite Imagery Using Python | by LAW... https://medium.com/@kimutai.lawrence19/accessing-s...
You can conduct analysis from the Satellite Imagery you have just accessed!
Follow
Geospatial Data Science, Python, Java, AI, ML, GIS. Email: [email protected] and my Portfolio
Website: https://lawrence65.carrd.co/com +254759629059
6 de 14 6/06/24, 17:38