Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calculate real world width of a clipped image #227

Open
TimThaler opened this issue Feb 8, 2024 · 0 comments
Open

Calculate real world width of a clipped image #227

TimThaler opened this issue Feb 8, 2024 · 0 comments

Comments

@TimThaler
Copy link

TimThaler commented Feb 8, 2024

The objective is that, for a given extent i want to construct a squared, fixed size, image and calculate its real world width. The first part is done thanks to the suggested solution for this.
After downloading the tiles each one is clipped to fit in a previously defined image with a fixed pixel height and width(e.g. 3000 pixel). After that it is drawn with a graphics object to its correct location.
The clipping part was implemented following the exmaple.

Without clipping. when i used all available tiles to construct the image, the real world image width was calculated the following way:

  • grabbing the top left coordinate of the top left tile
  • grabbing the top right coordinate of the top right tile
  • using the haversine formular to calculate the distance between the two coordinates

This was working ok for our use case, since we never had points further apart than 1 kilometer.

Now i am stuck calculating the width of the clipped image.

Initially i tried: realWorldWidth = UnitsPerPixel * imageWidthInPixel
This was way of (and also way wrong).I noticed that the value for UnitesPerPixel is equal for all latitudes.
( By the way: the TileSource is using a standard WebMercator projection and has 0.0746455 UnitsPerPixel at Zoomlevel 21.)
I read that the WebMercator projection distorts distances as you move away from the equator.
To take this into account i found a scaling factor of cosh(latitude) to get:

realWorldWidth = UnitsPerPixel * imageWidthInPixel * cosh(latitude)
Which is better but still wrong.

I could use the Haversine-approach, calculated it on the not-clipped version, break it down for a single pixel and then multiply it by the resulting
image size. This feels utterly complex.

Is there a clean and correct way to calculate the width of a cropped image?

@TimThaler TimThaler changed the title Calculated read world image width of clipped image Calculate real world width of a clipped image Feb 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant