opengeos / leafmap

A Python package for interactive mapping and geospatial analysis with minimal coding in a Jupyter environment
https://leafmap.org
MIT License
3.22k stars 386 forks source link

Google's Solar API integration #533

Closed sandorkonya closed 1 year ago

sandorkonya commented 1 year ago

Description

Google has a Solar API, and the endpoint returns data encoded as GeoTIFF files. One of these is a Surface Model (DSM). It would be awesome to be able to visualise such data with leafmap (which is probably possible). Below a simple snipplet to retrieve the DSM as a bytestring.

Source code

Following sniplet retrieves data for a given lat&long.

apikey =  "YOUR_KEY_HERE"
url = "https://solar.googleapis.com/v1/dataLayers:get"
params = {
    "location.latitude": 50.97579908646006,
    "location.longitude": 11.023334842349778,
    "radiusMeters": 50,
    "view": "FULL_LAYERS",
    "requiredQuality": "HIGH",
    "pixelSizeMeters": 0.1,
    "key": apikey
}

headers = {
  "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36"
}

solar_data= requests.get(url, params=params, headers=headers)

#the url for the digital height map ---
url = solar_data.json()["dsmUrl"] + "&key=" + apikey
response = requests.get(url, headers=headers)
giswqs commented 1 year ago

Good suggestion. I tested it. The URL is not a TMS tile URL, so we can't visualize it on the fly. The GeoTIFF file needs to be downloaded locally for visualization.

image

sandorkonya commented 1 year ago

@giswqs nice! Do you happen to have a dwmo script for that?

giswqs commented 1 year ago

I will add functions to leafmap to make it easier to download and visualize the data.

For now, you can use leafmap.download_file(url, filename) to download data.

giswqs commented 1 year ago

Peek 2023-09-06 11-28

sandorkonya commented 1 year ago

@giswqs this looks very promising! For me RGB, Mask, xxxFlux is working like a charm with leafmap.download_file but the dsm does not.

giswqs commented 1 year ago

See https://github.com/opengeos/leafmap/blob/master/examples/notebooks/80_solar.ipynb

giswqs commented 1 year ago

https://leafmap.org/notebooks/80_solar

https://github.com/opengeos/leafmap/assets/5016453/b6da6570-01f6-4eaf-81c2-3889fbc7ea7d