sk-zk / streetlevel

download panoramas and metadata from Street View, Look Around, and more
https://streetlevel.readthedocs.io
MIT License
49 stars 11 forks source link

Getting specific date #20

Closed noahdasanaike closed 1 month ago

noahdasanaike commented 1 month ago

Sorry if I missed this in the API documentation, but is there any way to query the same place over time? And then select which of those dates I want?

sk-zk commented 1 month ago

I assume this is about GSV.

find_panorama does not have a date filter, but the panorama object it returns has a historical field containing older panoramas at this location:

In [1]: from streetlevel import streetview

In [2]: pano = streetview.find_panorama(48.8548288, 2.3454405)

In [3]: pano.historical
Out[3]:
[NAYJRGhvXbDfDIY7X-JzKw (48.85484, 2.34539) [2022-12],
 LCWVDUTW7uSAjiwQnUR21w (48.85482, 2.34540) [2022-06],
 _Y_RsKNbhH--8fILJ-btIA (48.85484, 2.34542) [2021-04],
 Eu2kWLk8B_aPbKjfwN9M9Q (48.85484, 2.34541) [2020-07],
 LzVj6vni9JwlIixlO6b8QQ (48.85483, 2.34539) [2020-03],
 75kAPQkNF9qswPHD0GjwOQ (48.85485, 2.34539) [2019-06],
 oPg_jBRgtbnSh7sKZj3c9A (48.85481, 2.34541) [2018-05],
 dP7uLLzOcHrnlYH2PDemxw (48.85483, 2.34543) [2017-08],
 d57Q1yk40R8fxTNlL-fq8A (48.85483, 2.34543) [2016-10],
 EjEuCcmaFbmUnOj1JgczuQ (48.85481, 2.34540) [2015-07],
 hCZ52URIH9Bd5G7QjCzA9g (48.85483, 2.34543) [2014-07],
 iAXJcbBNIVV5pLTNO-d5bQ (48.85482, 2.34546) [2012-07],
 gNyWYmkQHZhF5pmDoOkpiQ (48.85481, 2.34541) [2010-11],
 SOLZBq9LOSZ0zOLWyji3lA (48.85485, 2.34539) [2008-05]]
noahdasanaike commented 1 month ago

Thanks—it is, but I'm having trouble downloading historical panoramas.

For instance, streetview.download_panorama(pano.historical[3], "test.png") doesn't work: "pano.image_sizes is None".

It looks like _generate_tile_list works given a historical pano id, but the _validate_get_panorama_params check fails.

sk-zk commented 1 month ago

The list of connected panos returned by the API, which is parsed into historical, neighbors, links, and building_levels, includes at most id, lat/lon, elevation, heading, rotation, date, and address (and the building level if applicable). For all other metadata, including image_sizes, you need to make another request:

hpano = streetview.find_panorama_by_id(pano.historical[3].id)
streetview.download_panorama(hpano, f"{hpano.id}.jpg")

The reason image_sizes is required to download a panorama is that official panoramas come in four different resolutions (and third-party panoramas can be pretty much any size), so get_panorama/ download_panorama need to know what that resolution is to generate the correct tile coordinates and properly reassemble the image.

noahdasanaike commented 1 month ago

This is great. Thanks!