Extending a selected MapExtent by X meters

Hi there,

I have difficulties extending a MapExtent by a number of meters and i hope i can find a good solution here.

My use case is to select a rectangle on the map. From the rectangle i get a MapExtent. This MapExtent should be increased by x meters which is a given input by the user.

I have the following problem when doing this:
How to get an approximately correct pixel result when converting from meters to pixels? e. g. How many pixel on the current map (with zoom and scale + scale unit regarded) are approximately one meter.

My first approach was to use the AxMap.CurrentScale because the Ax.MapUnits is set to meters. Then i calculated how many pixels are equivalent to one meter: 1 / (Map.CurrentScale / 96). 96 is the number for pixels per logical inch as it is stated that this is used for the scale in the documentation:
https://www.mapwindow.org/documentation/mapwingis4.9/group__map__extents.html#ga3746cb2f2d816f7ae6b910679b142301 . However the results i am getting from this calculation doesn’t seem to be right, but i have no idea why. I wanted to multiply the given meters by the pixel per meters and then i add the result to the corner points of the rectangle.

Maybe someone knows easier approaches to this use case, i’m kind of new to MapWinGis and haven’t used other GIS softwares before.

Thanks in advance

Hello @tilomi, and welcome.

  1. I’m guessing that you are handling the SelectBoxFinal event, which is why you have extents in pixels.

  2. You can use the AxMap1.PixelToProj method to convert your corners into map coordinates.

  3. If your units are already in meters, then you adjust your resulting corner coordinates by x meters in each direction, and set your map extents something like:

     Extents ext = new Extents();
     ext.SetBounds(left - 10, bottom - 10, 0.0, right + 10, top + 10, 0.0);
     AxMap1.Extents = ext;
  4. If your map units are not already (or cannot be assumed to be) in meters, then you can use the Utils.ConvertDistance method to convert from your known meters value to the equivalent distance in map units, and extend your bounds accordingly.

Hope that helps.

Hi Jerry,

Thanks for the tips. The Map was already in meter units and the code you provided did the trick for me.

Best regards