6

I have a certain geographic region defined by the bottom left and top right coordinates. How can I divide this region into areas of 20x20km. I mean in practial the shape of the earth is not flat it's round. The bounding box is just an approximation. It's not even rectangular in actual sense. It's just an assumption. Lets say the bottomleft coordinate is given by x1,y1 and the topright coordinate is given by x2,y2, the length of x1 to x2 at y1 is different than that of the length between x1 to x2 at y2. How can I overcome this issue

Actually, I have to create a spatial meshgrid for this region using matlab's meshgrid function. So that the grids are of area 20x20km.

meshgrid(x1:deltaY:x2,y1:deltaX:y2)

As you can see I can have only one deltaX and one deltaY. I want to choose deltaX and deltaY such that the increments create grid of size 20x20km. However this deltaX and deltaY are supposed to vary based upon the location. Any suggestions?

I mean lets say deltaX=del1. Then distance between points (x1,y1) to (x1,y1+del1) is 20km. BUt when I measure the distance between points (x2,y1) to (x2, y1_del1) the distance is < 20km. The meshgrid function above does creates mesh. But the distances are not consistent. Any ideas how to overcome this issue?

For finding point p(1,0)

deg = km2deg(20)

deg =

    0.1799

>> reckon(25,-120,0.1799,-18)

ans =

   25.1711 -120.0614

Function to calculate distance between two points

function [ distance ] = calculateDistance( latitude1,longitude1,latitude2,longitude2 )
radius = 6371;
dLat = degtorad(latitude2-latitude1);
dLon = degtorad(longitude2-longitude1);
a = sin(dLat/2) * sin(dLat/2) + cos(degtorad(latitude1)) * cos(degtorad(latitude2)) * sin(dLon/2) * sin(dLon/2);
c = 2 * atan2(sqrt(a), sqrt(1-a));
distance = radius * c;
end

Referring to whuber's suggestions

syms p(1,1).lat p(1,1).lon
solve ( calculateDistance(p(0,1).lat,p(0,1).lon,p(1,1).lat,p(1,1).lon), calculateDistance(p(1,0).lat,p(1,0).lon,p(1,1).lat,p(1,1).lon))
PolyGeo
  • 65,136
  • 29
  • 109
  • 338
rajan sthapit
  • 763
  • 3
  • 10
  • 18

1 Answers1

6

This can be accomplished in the same way we would lay out a grid of squares in the plane:

  1. Lay off a baseline in any direction. Mark it off in equal increments (of 20 km). Call these points p(0,0), p(0,1), ..., p(0,n), in order. It does not have to be geodesically straight, but it should be close to straight.

  2. Starting with the first marked point p(0,0), choose a direction beta not parallel to the baseline (perhaps perpendicular to the baseline, for instance). Move 20 km in that direction and stop. Call this point p(1,0).

  3. Begin with the first two points on the baseline, p(0,0) and p(0,1). There will be two locations that are 20 km from each of p(0,1) and p(1,0): these are the intersections of circles of radius 20 km centered at p(0,1) and p(1,0). One of these points, by construction, is p(0,0). Define p(1,1) to be the other point.

    Iteratively determine p(1,j), j = 2, ..., n, in this fashion.

  4. Repeating steps 2 and 3, iteratively determine as many rows as desired, using the most recent row p(i,0), p(i,1), ..., p(i,n) as the baseline and keeping beta constant (at least approximately).

Retain only those grid points falling within one's region of interest.

The earth's curvature begins having a pronounced effect on grids more than a thousand kilometers on a side (or so). To illustrate this, here is a grid with 400 km spacing constructed to cover the conterminous United States.

GeoGrid

This is a Mercator projection. The baseline of the grid is the bottom row of points, starting at (lat, lon) = (25, -120) and proceeding along the geodesic oriented 89.5 degrees east of north. The angle 'beta' is 18 degrees west of north: that determines the orientation of the left side of the grid.

(There's a limit to how far one can go with this approach: eventually such grids will wrap around the globe and return to cover the same areas. They will never match up unless they are extremely large (and effectively create a cube, octahedron, or prism).)


Note that apart from the aforementioned exceptions, it is impossible to create a grid of congruent squares (or any other shape) on the sphere (or any ellipsoid). This is because the congruencies would generate a discrete subgroup of the group of rotations of space and those subgroups correspond to the five Platonic solids, prisms, and pyramids. So, something has to give: if you want the grid cells to have equal areas or equal angles, the lengths of their sides must vary; if you want the side lengths to be the same, then the areas and angles must vary. This is why the cell shapes appear so distorted and non-square in the figure: such distortion is unavoidable.

whuber
  • 69,783
  • 15
  • 186
  • 281
  • Hi Whuber, Thanks for the explanation. However, I tried what you have showed here before. My question is how come the point p(1,1) is at distance 20km from each of the points p(0,1) and p(1,0). I tried with the base row as you said with a distance of 20km. Then I tried to get the next row. But point p(1,1) is not at a distance of 20km. I mean lets say for the base row I define delta_lon so that point p(0,0) and point (0,1) have same lat but lon different by delta_lon which makes it 20km. Now if I use the same delta_lon in the next row, the distance is not equal to 20km – rajan sthapit Jun 04 '12 at 17:49
  • My question is how can I get the point p(1,1). I mean as you said the point is the intersection of the circles at point p(1,0) and p(0,1). How can I get that in matlab. Are there any specific functions. Also how did you get the angle beta. I mean I tried in the same longitude as point p(0,0) to get the point p(1,0) at a distance of 20km. I need some more details – rajan sthapit Jun 04 '12 at 17:55
  • Rajan, As you point out, the crux of the matter is finding p(1,1) given p(1,0), p(0,1), and p(0,0). You can solve this numerically: that is, solve the simultaneous (nonlinear) equations distance(p(1,0), p(0,0)) = 20 km = distance(p(0,1), p(0,0)) and remove the solution equal to (or extremely close to) p(0,0). This requires (a) solving simultaneous nonlinear equations and (b) finding distances on the sphere or ellipsoid. – whuber Jun 04 '12 at 18:51
  • Hi Whuber, Thanks I will try that. But my other question is how you found out beta. Can I choose any beta I want. I mean in my case for finding point p(1,0) at a distance of 20km from point(0,0), can I use the direction of the same longitude as point(0,0) has. I mean how come you got 18 degrees west of north in your case. Did you follow a specific procedure? – rajan sthapit Jun 04 '12 at 18:57
  • Yes, you can choose (almost) any beta you want, and you can even vary it from one row to the next. I used -18 degrees in order to obtain a grid that is approximately symmetric around its middle, but starting with -0.5 (which is 90 degrees less than the baseline direction) would be a natural point of departure. Beta is just the azimuth from the start of one row to the start of the next, so it determines the degree to which points in successive rows appear staggered relative to one another. – whuber Jun 04 '12 at 18:59
  • I should mention that it can help to provide starting values for nonlinear solvers. To obtain them, I find the direction from p(0,0) to p(0,1), then starting at p(1,0), move in that direction for 20 km. That in general will be quite close to the correct answer, so a nonlinear solver should converge quickly to it. (This way you don't have to obtain two solutions and throw one away.) This method works provided grid spacings aren't huge and you're not close to a pole. – whuber Jun 04 '12 at 19:02
  • Thanks for the info. But I am pretty confused how can I use the degrees -18 in your case to get a distance of 20km. I am used to using decimal numbers like lat1,lon1,lat2,lon2 to get the distance. I am pretty much confused how to use the direction to find a distance. Can you give me an example in matlab? – rajan sthapit Jun 04 '12 at 19:14
  • I'm sorry, I cannot provide Matlab examples: I don't have access to it. But all that's going on is when you choose a starting point (e.g., p(0,0)), a direction (e.g., 18 degrees west of north), and a distance (e.g., 20 km), you have thereby determined a unique destination, here p(1,0). It's no different on an ellipsoid than in the plane. The Matlab function is reckon. – whuber Jun 04 '12 at 19:19
  • 1
    Whuber, I have made some changes in the question itself. Could you suggest me if it is the right way to go? I am pretty confused how to exactly use the http://www.mathworks.com/help/toolbox/symbolic/solve.html and http://www.mathworks.com/help/toolbox/map/ref/distance.html. In the distance function, I cannot actually get the equations to pass the solve function. So I thought that I should write my own distance function. – rajan sthapit Jun 04 '12 at 20:10
  • Also I have further issues. When I used calculateDistance( latitude1,longitude1,latitude2,longitude2 ), with latitude2 and longitude2 to be of point(1,1) defining sysm latitude2 and longitude2 and solve,it says that atan2 doesn't accept input of type of sym – rajan sthapit Jun 04 '12 at 20:26
  • Well, at this point we have a valid solution--as you can see from my illustration--and all your issues appear to be with Matlab, not with GIS. They are best asked on StackOverflow rather than here. – whuber Jun 04 '12 at 20:28
  • Sure I will move it to stackoverflow – rajan sthapit Jun 04 '12 at 20:30
  • But about finding the point p(1,0) is it correct? I mean the one that I have mentioned in the question. I just want to be sure that I have done it correctly. Thanks – rajan sthapit Jun 04 '12 at 20:35
  • Yep, it's close: on the WGS84 spheroid I get(25.171698, -120.061307). The distance between the location you find, at (25.1711, -120.0614), and the starting point at (25, -120) is 19,939.9 m, which is 0.3% too low. That's about the error to be expected when using a spherical model instead of a more accurate ellipsoid. Also, for more info on computing distance, search this site for Haversine. – whuber Jun 04 '12 at 20:46
  • I managed to get the points. However, the points in a row, they are not same. I mean when I solve the nonlinear equations to get points p(1,1) for a whole row, there is a difference of 1 degree between the point at the start of the row and the point at the end. Is it normal? – rajan sthapit Jun 05 '12 at 14:02
  • Rajan, if you don't get a grid of points as in my illustration, then there is a problem in your implementation. In fact, if you're generating a 20 km square grid and it does not cover a large area, it should be very close to a regular array with little apparent curvature in the rows or columns. If you do get a grid of points, then you're probably ok. As a double-check, compute distances between points and their neighbors to verify they always equal 20 km. – whuber Jun 05 '12 at 14:24
  • Wuhber, Can I get your email, I want to send you some screenshots of the data – rajan sthapit Jun 05 '12 at 21:25