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

New function to get the center of a tile #34

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

jenningsanderson
Copy link

Have written this helper function a few times now, perhaps it's helpful to others to include here?

@batpad ?

@honjo2
Copy link

honjo2 commented Sep 22, 2017

function tileToCenterPoint(tile) {
    var bbox = tileToBBOX([tile[0]+.5, tile[1]+.5, tile[2]]);

    return {type: 'Point',
        coordinates: [
            bbox[0],
            bbox[3]
        ]
    };
}

@jenningsanderson
Copy link
Author

jenningsanderson commented Sep 22, 2017

@honjo2 Wow.

So the latitudes are slightly different between these two versions of the script, I imagine that your version is actually more true given that my version simply averages the min/max.

@bhousel
Copy link

bhousel commented Sep 22, 2017

I have to admit - I would never have thought to try it that way. 👏

@jenningsanderson
Copy link
Author

Tile:

02001021130033300

Bbox:

 {"type":"Polygon","coordinates":[[[-166.212158203125,65.18648824110723],[-166.212158203125,65.18764086352971],[-166.20941162109375,65.18764086352971],[-166.20941162109375,65.18648824110723],[-166.212158203125,65.18648824110723]]]}

Original Way (avg. min/max):

{"type":"Point","coordinates":[-166.21078491210938,65.18706455231847]}

New way (tile x,y + 0.5):

{"type":"Point","coordinates":[-166.21078491210938,65.18706455858751]}

FeatureCollection of the three...

{"type":"FeatureCollection", "features" : [
  {"type":"Feature", "properties":{"type":"bbox"},"geometry":
  {"type":"Polygon","coordinates":[[[-166.212158203125,65.18648824110723],[-166.212158203125,65.18764086352971],[-166.20941162109375,65.18764086352971],[-166.20941162109375,65.18648824110723],[-166.212158203125,65.18648824110723]]]}},
  {"type":"Feature", "properties":{"type":"avg min/max"},"geometry":
  {"type":"Point","coordinates":[-166.21078491210938,65.18706455231847]}},
  {"type":"Feature", "properties":{"type":"tile x,y +0.5"},"geometry":
  {"type":"Point","coordinates":[-166.21078491210938,65.18706455858751]}}
]}

Loading ^ into QGIS, I'm inclined to say that averaging the min/max is actually slightly more accurate when considering the center of a tile as a point on the ground.... though a tile itself should never really be considered a square on the ground... so whichever computation is faster (likely @honjo2 ) seems like the 🥇

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

Successfully merging this pull request may close these issues.

3 participants