nonta1234 / terraining-heightmap-generator

Terraining - Online heightmap generator for "Cities: Skylines".
MIT License
28 stars 4 forks source link

longitude and latitude coordinates of the 4 corners #5

Closed Daylen69 closed 3 months ago

Daylen69 commented 6 months ago

Hi !

For a map size of 57.344 km, what is the zoom level of the downloaded map image ?

Would it be possible to know the longitude and latitude coordinates of the 4 corners of the 'green zone' (playable zone) ?

nonta1234 commented 6 months ago

For a map size of 57.344 km, what is the zoom level of the downloaded map image ?

The MapBox API does not specify a zoom level if the grid angle is 0 degrees when capturing still images. Just get the map extent. When acquiring still images using the Mapbox API, the zoom level can only be specified to the second decimal place, so if the grid angle is other than 0 degrees, the zoom level with the least deviation is calculated and requested. Therefore, it changes depending on the size of the map and the latitude and longitude.

Would it be possible to know the longitude and latitude coordinates of the 4 corners of the 'green zone' (playable zone) ?

It is possible to obtain the latitude and longitude of the corner of the playable zone. However, strictly speaking there is a very small discrepancy between the grid and the heightmap. This is by design of Mapbox GL JS and Web Mercator.

Which do you think should be displayed?

Daylen69 commented 6 months ago

I think we should display the one that is closest to the heightmap.

The idea is to delineate the area using these 4 points in order to obtain a map with a desired zoom level. For instance, with Universal Maps Downloader, by entering the coordinates of the 4 points that define the playable area, we could obtain a zoom level 16 map detailed enough to be displayed with the Image Overlay Mod in Cities: Skylines 2.

Do you understand ? My English is very average

nonta1234 commented 6 months ago

I understood. But Universal Maps Downloader doesn't take map rotation into account, so I have to think about it.

Daylen69 commented 6 months ago

I talked about Universal maps downloader just as an example because I used it to obtain a map and I needed the coordinates of the 4 corners of the area (I can't be precise so I have an offset at every time)

benmarten commented 5 months ago

I'd welcome this feature too.

I tried manually calculating the bounding box via:

const turf = require('@turf/turf')

const centerPoint = [-111.63, 35.19]
const sideLength = 57.344
const center = turf.point(centerPoint)
const box = turf.bbox(
  turf.buffer(center, sideLength / 2, { units: 'kilometers' })
)

const result = {
  type: 'Feature',
  properties: {},
  geometry: {
    type: 'Polygon',
    coordinates: [
      [
        [box[0], box[1]],
        [box[0], box[3]],
        [box[2], box[3]],
        [box[2], box[1]],
      ],
    ],
  },
}

console.log(JSON.stringify(result, null, 2))

Which works, but doesn't seem to give the same coordinates as shown on your tool. Any ideas?

benmarten commented 5 months ago

I've digged into the code, and it looks like the 4 values are already calculated when downloading the IMG:

Screenshot 2024-03-27 at 1 32 56 PM

Here, we could probably also add an option to make a separate image query for each tile....

benmarten commented 5 months ago

I've hacked a PR, that allows for downloading of 6x6 high-res tile images: https://github.com/nonta1234/terraining-heightmap-generator/pull/10#issue-2211965748

EDIT: Pushed a fix, seems to work now. It also logs the 4 coords to console.

nonta1234 commented 5 months ago

Hi!

The function to get the extent is as follows.

https://github.com/nonta1234/terraining-heightmap-generator/blob/d09987f25f7f5d952448b1c7d0d5bac32e0da3dd/src/composables/useMapbox.ts#L9-L46

The buffer function may not return a perfect circle, because web Mercator is not conformal. Therefore, after converting to pixel coordinates, use the Pythagorean theorem to calculate the length of the side that is expected to have the least deviation. Also, originally the distance on the map increases towards the poles, but for convenience, the boundaries are acquired so that the latitude and longitude of the center is the center of the extent.

Therefore, if you want to split this extent, I recommend separating on a pixel basis.

nonta1234 commented 3 months ago

v1.4.0