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

Given latitude and longitude, how to find in what country those coordinates are? #233

Open
clzola opened this issue Jan 17, 2025 · 1 comment
Labels

Comments

@clzola
Copy link

clzola commented Jan 17, 2025

This is more of a question as I need help to figure out...

So as ti title says:

Given latitude and longitude, how to find in what country those coordinates are?

I have geojson file with country borders. Each country is represented with either Polygon or MultiPolygon. If I understand correctly, those coordinates that are inside geojson file are longitude and latitude in EPSG:4236 CRS. Because of that I cannot just check relation between Point (longitude, latitude) and Polygon because it might give error because operation/methods from this library and JTS does not take into account curvature of earth.

So my idea is first to convert all geometries from EPSG:4326 to Google Mercator, and then convert given longitude and latitude, and finally perform contains and intersect operations?

Am I on the right way? Or can I directly use geometries without transformation from one CRS to another (I am willing to tolerate some error, like some near border cases)?

Also for the optimization purposes, I would build quad tree and boundary box checks...

@dsmiley
Copy link
Contributor

dsmiley commented Jan 19, 2025

Most libraries don't take into consideration curvature of the earth in a direct sense, but if the polygons have sufficient detail and if the data isn't too close to the poles (where some projections lose accuracy), then this is a moot point. Also keep in mind that some polygons were plotted/authored in one projection but the gets re-projected to another afterwards and then the polygon could become technically invalid according to the 2 dimensional rules that JTS and most 2D systems expect. Basically a line that didn't intersect another vertex will after re-projection. But again, with sufficient detail, it won't happen. Another problem that can happen is that you think/hope regional polygons don't overlap but they may actually slightly on the edges if there were re-projection / translations.

So in summary, I wouldn't worry about it but if you see polygon errors, you may need more detail.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants