Convert Latitude and Longitude values to a custom sized grid

橙三吉。 提交于 2021-02-18 17:13:13

问题


I am making a java program that classifies a set of lat/lng coordinates to a specific rectangle of a custom size, so in effect, map the surface of the earth into a custom grid and be able to identify what rectangle/ polygon a point lies in.

The way to do this I am looking into is by using a map projection (possibly Mercator).

For example, assuming I want to classify a long/lat into 'squares' of 100m x 100m,

44.727549, 10.419704 and 44.727572, 10.420460 would classify to area X

and

44.732496, 10.528092 and 44.732999, 10.529465 would classify to area Y as they are within 100m apart. (this assumes they lie within the same boundary of course)

Im not too worried about distortion as I will not need to display the map, but I do need to be able to tell what polygon a set of coordinates belong to.

Is this possible? Any suggestions welcome. Thanks.

Edit

Omitting projection of the poles is also an acceptable loss


回答1:


Here is my final solution (in PHP), creates a bin for every square 100m :

function get_static_pointer_table_id($lat, $lng)
{
    $earth_circumference = 40000; // km

    $lat_bin = round($lat / 0.0009);
    $lng_length = $earth_circumference * cos(deg2rad($lat));
    $number_of_bins_on_lng = $lng_length * 10;
    $lng_bin = round($number_of_bins_on_lng * $lng / 360);
    //the 'bin' unique identifier
    return $lat_bin . "_" . $lng_bin;

}



回答2:


If I understand correctly, you are looking for

  1. a way to divide the surface of the earth into approximately 100m x 100m squares
  2. a way to find the square in which a point lies

Question 1 is mission impossible with squares but much less so with polygons. A very simple way to create the polygons would to use the coordinates themselves. If each polygon is 0.0009° in latitude and longitude, you will have approximately square 100m x 100m grid on the equator, put the slices will become very thin close to the poles.

Question 2 depends on the approximation used to solve the challenge outlined above. If you use the very simple method above, then placing each coordinate into a bin is just a division by 0.0009 (and rounding down to the closest integer).

So, first you will have to decide what you can compromise. Is it important to have equal area in the polygons, equal longitudinal distance, equal latitude distance, etc.? Is it important to have four corners in the polygon? Is it important to have similar or almost similar polygons close to the poles and close to the equator? Once you know the limitations set by your application, choosing the projection becomes easier.




回答3:


What you are trying to do here is a projection onto a flat surface of an ellipsoid. So as long as your points are close together, and, well, you don't mind getting the answer slightly wrong you can assume that your projection plane intersects in the centre of your collection of points, and, each degree of lat and lon are a constant number of metres. Then the problem is a simple planar calculation.

This is wrong, of course. I would actually recommend that you look into map projections, pick one that makes sense, and go for that. Remember that you can move the centre of the projection to the centre to your set of points which will reduce distortion.

I suspect that PROJ.4 might help you in terms of libraries. There also must be a good Java one but that is not my speciality.

Finally you can could assume that the earth is a sphere and do your calculations on the sphere. Or, if you really want to get it right you can pick a standard earth ellipsoid and do the calculations on that.



来源:https://stackoverflow.com/questions/24210963/convert-latitude-and-longitude-values-to-a-custom-sized-grid

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!