1

I have a map in Mercator projection. I know coordinates of corners. I want to render uniformly distributed dots to map.

for (float latDeg = startLatDeg; latDeg <= endLatDeg; latDeg += stepLatDeg){
        for (float lonDeg = startLonDeg; lonDeg <= endLonDeg; lonDeg += stepLonDeg){
            Pixel px = mercator->GetPixels(lonDeg, latDeg);
            map[px.x][px.y] = dot;
        }
    }

where start and end values are corners of map.

This code works for longitude, obviously, since it is uniform and non-distorted. How can I achieve uniformity in latitude? I know, that I cannot use fixed step, but somekind recalculate it based on last latitude. But I dont know how.

1

It seems to me that, if you want a pattern of evenly spaced points in any map projection, the easiest way is to build your regular grid directly in that projection. This will also be faster, because you only need to transform the coordinates of two points.

Pixel start = mercator->GetPixels(startLonDeg, startLatDeg);
Pixel end = mercator->GetPixels(endLonDeg, endLatDeg);
for (float laty = start.y; laty <= end.y; laty += stepLat){
        for (float lonx = start.x ; lonx <= end.x; lonx += stepLon){

            map[lonx][laty] = dot;
        }
    }
  • The problem with this approach is map zooming / moving, since the points are not attached to GPS but to pixels. So with every movement / zoom, final points may end up elsewhere. – Martin Perry Aug 16 '17 at 14:18
  • 1
    my idea was to have the points in the values of the coordinate system (mercator) not the pixel position on the screen screen, but apparently I did not completely understand your syntax. Could you please specify the WebGIS API that you are using ? – radouxju Aug 16 '17 at 14:52
  • I am not using any API, I am writing it as a part of my program. – Martin Perry Aug 16 '17 at 15:29
  • So mercator->GetPixels must be converting the lat/lon values either to mercator then to pixel coords or directly to pixel coords. @radouxju is suggesting that GetPixels takes Mercator coordinate values and converts them to pixel coords. – mkennedy Aug 16 '17 at 22:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.