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

Converting Lat/Lng to X/Y position on tile #58

Open
lukezirngibl opened this issue Aug 23, 2022 · 11 comments
Open

Converting Lat/Lng to X/Y position on tile #58

lukezirngibl opened this issue Aug 23, 2022 · 11 comments

Comments

@lukezirngibl
Copy link

I am trying to project a Lat/Lng pin onto the 3D printed tile. Given the topright & bottomleft coordinates.. How would you suggest mapping any given latlng to XY position on the print?

@ChHarding
Copy link
Owner

ChHarding commented Aug 23, 2022 via email

@lukezirngibl
Copy link
Author

lukezirngibl commented Aug 26, 2022

Hey Chris,

Thanks for the speedy response. The goal is to project a pin onto the tile (not integrate into the model). My current approach is as follows:

My touchterrain coordinates are:

const trlat = 47.851128701997794
const trlon = 10.846901928710908
const bllat = 45.79197038566249
const bllon = 5.514870678710881

My logfile does indeed show the EPSG:32632

I first converted both my TR and BL coordinates into UTM. Since they lie in different UTM Zones (31 & 32), I projected the BL to Zone 32. This yielded:

BL - UTM = [229133.28260624083, 5076843.084432984]
TR - UTM = [638164.1, 5301405.3]

My test target pin LatLng is:

const target = {
  lat: 47.366935,
  lng: 8.543069,
}

Converted to UTM is: [465500.1, 5246042.8]

And now i simply map that coordinate to my computed UTM coordinate space:

const convert = (latlng: LatLng) => { ... converts to correct UTM zone (32) }  

// map proportions are 16:9

const WIDTH = 1600
const HEIGHT = 900

const bottomLeftUTM = convert(bottomLeft)
const topRightUTM = convert(topRight)

const UTM_X_ZERO = bottomLeftUTM[0]
const UTM_Y_ZERO = bottomLeftUTM[1]

const UTM_WIDTH = topRightUTM[0] - bottomLeftUTM[0]
const UTM_HEIGHT = topRightUTM[1] - bottomLeftUTM[1]

const getXY = (latlng: LatLng): Coordinates => {
  const targetUTM = convert(latlng)
  return {
    x: ((targetUTM[0] - UTM_X_ZERO) / UTM_WIDTH) * WIDTH,
    y: ((targetUTM[1] - UTM_Y_ZERO) / UTM_HEIGHT) * HEIGHT,
  }
}

This gives me: {x: 924.5926999821821, y: 678.1182828367208} for the pin...

But its still about 1 cm off when projected onto the physical tile! Is simply converting UTM not enough? Is there some sort of distortion happening when you generate the STL? I'm not quite sure what you mean by "use proportions and your true mm size".

FYI - The map is 1.2m wide (6 tiles wide, 4 tiles high). 16:9 proportions.

Thank you for your help!

@lukezirngibl
Copy link
Author

To give you a sense of it, here is a screenshot (right now i'm just doing the projection in pixel space).

Red = actual
Black = expected

Screen Shot 2022-08-26 at 09 15 18

@ChHarding
Copy link
Owner

ChHarding commented Aug 26, 2022 via email

@lukezirngibl
Copy link
Author

lukezirngibl commented Aug 27, 2022

Just using the "correction factor" doesn't seem to do it since the distortion doesn't appear to be linear. For the single point it's OK, but for others, its equally inaccurate.

Here is my log file:

Log for creating 6 x 4 3D model tile(s) from switzerland-16-9.tif 
 
started: 09:43:52.647827 
source raster upper left corner (x/y):  229110.0 5305650.0 
source raster cells size 30.0 m  (7769, 13815) 
projection: WGS 84 / UTM zone 32N 
z-scale: 1.3 
basethickness: 15 
fileformat: STLb 
tile_centered: False 
no_bottom: False 
no_normals: True 
ignore_leq: None 
lower_leq: None 
importedGPX: None 
Warning: Given outline polygon will be ignored when using local raster file! 
undefined GDAL value: None 
tile_width: 200 
tile_height: 112.4719507781397 
source raster width 414450.0 m, cell size: 30.0 m, elev. min/max is 40.0 4809.0 m 
source raster 3D print resolution would be 0.08686210640608034 mm 
re-sampling switzerland-16-9.tif :
  (13815, 7769) 0.08686210640608034 mm  30.0 m  40.0 - 4809.0 m to 
  (5999, 3374) 0.20003333888981498 mm  69.075 m  51.31341 - 4796.6377 m 
after resampling, requested print res was adjusted from 0.2 to 0.20003333888981498 to ensure correct model dimensions 
Cropping for nice fit of 6 (width) x 4 (height) tiles, removing: 5 columns, 2 rows 
 cropped (5999, 3374) to (5994, 3372) 
 cropping changed physical size from 200 mm x 168.72812135355892 mm 
 to 199.83330555092516 mm x 168.62810468411402 mm 
map scale is 1 : 345317.4375 
Cells per tile (x/y) 999 x 843 
using single-core only 

I suppose the real question is: Why does the computed UTM coordinate space not have the same proportions as the tiles?

Could it be that the cropping is changing the actual TR / BL? Therefore shifting the entire system by a few millimeters. And could subdividing the print (into 24 tiles) somehow compound the issue?

@ChHarding
Copy link
Owner

ChHarding commented Aug 29, 2022 via email

@ChHarding
Copy link
Owner

ChHarding commented Aug 30, 2022 via email

@ChHarding
Copy link
Owner

ChHarding commented Aug 30, 2022 via email

@lukezirngibl
Copy link
Author

We used your approach from: #34 to generate the geotiff (yeah, from Earth Engine)

OK - so i like this idea of converting to your cell coordinates. How do I convert from UTM coord to cell coord? Or how do you go from:

source raster upper left corner (x/y): 229110.0 5305650.0

to

source raster cells size 30.0 m (7769, 13815)

End goal is to project a dot onto the model. So I think LatLng -> Cell position would make most sense

@ChHarding
Copy link
Owner

ChHarding commented Aug 31, 2022 via email

@ChHarding
Copy link
Owner

ChHarding commented Oct 11, 2022 via email

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

2 participants