mapillary / mapillary-python-sdk

A Python 3 library built on the Mapillary API v4 to facilitate retrieving and working with Mapillary data.
MIT License
39 stars 15 forks source link

[Requirements] 3. Get Image Looking At #14

Closed Rubix982 closed 3 years ago

Rubix982 commented 3 years ago

Is your feature request related to a problem? Please describe. This issue deals with the 1st requirement from the PRD for specifying two 2 sets of longitude, and latitude, where the 2nd set is the "looking at" location from 1st set's perspective.

Describe the solution you'd like The base requirements are,

  1. Takes 2 sets of longitude, latitude as arguments, with the same with same options as R02
  2. Longitude, latitude set 1 is close to the location, same as in R02. Longitude, latitude set 2 is the “looking at” location
  3. These can be the same or different.

The options mentioned above are,

  1. Options for fields to include with an “all” option or individual list
  2. Option for radius, default being within 200 meters or less
  3. Option for pano, flat, or both
  4. Possible options: date filter, org key
  5. Geometry is always a field included

Describe alternatives you've considered NA

Additional context Maybe eliminate arguments being 2 sets of longitude, latitude, only have 1 longitude, latitude for looking at.

It may be useful to have the function exclude images that are too close to the looking at longitude, latitude, as if within 3 meters, as the returned photo may be too close to be useful. 10+ meters may be best

Rubix982 commented 3 years ago

@cbeddow The images be should be returned as URLS, right?

cbeddow commented 3 years ago

@Rubix982 no, we should return the full GeoJSON feature of the image. So we at first get a geojson feature collection from the tiles, and need to analyze the camera_angle of each feature to see if the image points towards the input lon,lat. The one that is the best candidate should then be returned as a feature. The user then can use the whole feature, for example plot it on a map or just print the image key, as they need.

cbeddow commented 3 years ago

@Rubix982 this javascript code shows how looking at can be calculated, maybe is partially useful:

function isLookingAt(imageFeature: any, lookatFeature: any): boolean {
    if (imageFeature.properties.pano) {
        return true;
    }

    // TODO ca < 0 or ca === -1?
    if (imageFeature.properties.ca < 0) {
        return false;
    }

    const bearing: number = Math.abs(turf.bearing(imageFeature, lookatFeature) - imageFeature.properties.ca) % 360;
    return 310 < bearing || bearing < 50;
}

function filterHitsByLookAt<T extends {_source: MapImage}>(hits: T[], lookat: {lng: number, lat: number}): T[] {
    const lookatFeature: any = turf.point([lookat.lng, lookat.lat]);
    return hits.filter(
        (image): boolean => {
            const coords = [image._source.l.lon, image._source.l.lat];
            const imageFeature = turf.point(coords, {'ca': image._source.ca});
            return isLookingAt(imageFeature, lookatFeature);
        },
    );
}
Rubix982 commented 3 years ago

Noted. Thanks for the code snippet!

Rubix982 commented 3 years ago

Self assigning.