How can I get a pixel from a tile?

37 Views Asked by At

If I have a real world coordinate and the x16 tile images from tileserver-gl how can i get the exact pixel for that coordinate?

I mean, if i have the lat and the lon i can get a tile image but then how can i get the exact pixel from the image?

My images are 256x256 in x16.

Thanks :)

I have tried to modify this code to get the pixel from coordinates but I didnt get it.

public static string GetTileForCoordinates(double lat, double lon) {

        int xtile = (int)Math.Floor((lon + 180) / 360 * (1 << 16));
        int ytile = (int)Math.Floor((1 - Math.Log(Math.Tan(ToRadians(lat)) + 1 / Math.Cos(ToRadians(lat))) / Math.PI) / 2 * (1 << 16));

        if (xtile < 0)
            xtile = 0;
        if (xtile >= (1 << 16))
            xtile = ((1 << 16) - 1);
        if (ytile < 0)
            ytile = 0;
        if (ytile >= (1 << 16))
            ytile = ((1 << 16) - 1);

        return $"{xtile}_{ytile}";

}

0

There are 0 best solutions below