# Extending a selected MapExtent by X meters

**URL:** <https://mapwindow.discourse.group/t/extending-a-selected-mapextent-by-x-meters/693>\
**Category:** MapWinGIS\
**Created:** [August 10, 2020, 8:15am UTC](https://mapwindow.discourse.group/t/extending-a-selected-mapextent-by-x-meters/693 "2020-08-10T08:15:13Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![tilomi](https://avatars.discourse-cdn.com/v4/letter/t/8dc957/32.png) [@tilomi](https://mapwindow.discourse.group/u/tilomi)\
**Post date:** [August 10, 2020, 8:15am UTC](https://mapwindow.discourse.group/t/extending-a-selected-mapextent-by-x-meters/693/1 "2020-08-10T08:15:13Z")

</div>

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](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

---

<div class="post-metadata">

**Author:** ![jerryfaust](https://yyz2.discourse-cdn.com/free1/user_avatar/mapwindow.discourse.group/jerryfaust/32/378_2.png) [@jerryfaust](https://mapwindow.discourse.group/u/jerryfaust)\
**Post date:** [August 11, 2020, 5:16am UTC](https://mapwindow.discourse.group/t/extending-a-selected-mapextent-by-x-meters/693/2 "2020-08-11T05:16:10Z")

</div>

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](https://www.mapwindow.org/documentation/mapwingis4.9/group __map__ coordinates.html#ga7f9ea56b66c63f474bb996f28da6fd1e) 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:

4. If your map units are not already (or cannot be assumed to be) in meters, then you can use the [Utils.ConvertDistance](https://www.mapwindow.org/documentation/mapwingis4.9/class_utils.html#aab171ff12d2bd62958bf4ee3af3f430d) method to convert from your known meters value to the equivalent distance in map units, and extend your bounds accordingly.

Hope that helps.  
Jerry.

---

<div class="post-metadata">

**Author:** ![tilomi](https://avatars.discourse-cdn.com/v4/letter/t/8dc957/32.png) [@tilomi](https://mapwindow.discourse.group/u/tilomi)\
**Post date:** [August 11, 2020, 9:59am UTC](https://mapwindow.discourse.group/t/extending-a-selected-mapextent-by-x-meters/693/3 "2020-08-11T09:59:02Z")

</div>

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  
Tilo

---

<div class="post-metadata">

**Author:** ![pmeems](https://yyz2.discourse-cdn.com/free1/user_avatar/mapwindow.discourse.group/pmeems/32/9_2.png) [@pmeems](https://mapwindow.discourse.group/u/pmeems)\
**Post date:** [January 5, 2022, 3:09pm UTC](https://mapwindow.discourse.group/t/extending-a-selected-mapextent-by-x-meters/693/4 "2022-01-05T15:09:07Z")

</div>

Closed on January 5, 2022, 3:09pm UTC


