Welcome to MapForums!

Register, sign in, or use Facebook Connect above to join in and participate in the forum.

When you are signed in, this message, the ads in this row, and the red-underlined link ads all go away.

 Subscribe to receive our newsletter. Subscribe Unsubscribe

## how to calculate Lat/Longs for the corners of a rectangle?

This is a discussion on how to calculate Lat/Longs for the corners of a rectangle? within the MapPoint Desktop Discussion forums, part of the Map Forums category; Hi, I am a newbie of MapPoint development. Here is what I want to do: After I create a rectangle ...

1. Senior Member Black Belt
Join Date
Jul 2002
Posts
5,137

## how to calculate Lat/Longs for the corners of a rectangle?

Hi,

I am a newbie of MapPoint development. Here is what I want to do:

After I create a rectangle by using the drawing toolbar(geoAutoShape/geoShapeRectangle), I need to know the latitude/longitudes for its four corner. Is it possible to do it?

I already have a method to get a pair of Lat/Long from a location object. Is it possible to calculate those four locations based on center location and width/length?

I am using Microsoft C# to write my code.

Thanks a lot.

Linda Chen

2. How about if you just select an area with you mouse by holding the left button and draging (you know how it makes a box on the screen so you can zoom in)

Here is a post I made long ago on how to get the four corners of that selected area.

http://www.mp2kmag.com/mappoint/disc...pic.asp?t=3327

Problem is a "geoShapeRectangle" does not have a Vertices property. There might be a way to do it but I'm drawing a blank right now? Sorry but I do not have a sample in C# I'm sure you are used to converting VB samples in C# right?

Hope this helps you...

3. Senior Member Black Belt
Join Date
Nov 2004
Location
Belgium
Posts
2,433
Hi John,

I just needed something similar So I first experimented with your code in C# and drop it as whell here

Code:
```            MapPoint.SelectedArea sa = MP.ActiveMap.SelectedArea;
Location&#91;&#93; loc = new Location&#91;5&#93;;

loc&#91;0&#93; = MP.ActiveMap.XYToLocation&#40;sa.Left, sa.Top&#41;;
loc&#91;1&#93; = MP.ActiveMap.XYToLocation&#40;sa.Left + sa.Width, sa.Top&#41;;
loc&#91;2&#93; = MP.ActiveMap.XYToLocation&#40;sa.Left + sa.Width, sa.Top + sa.Height&#41;;
loc&#91;3&#93; = MP.ActiveMap.XYToLocation&#40;sa.Left, sa.Top + sa.Height&#41;;
loc&#91;4&#93; = loc&#91;0&#93;;

//MP.ActiveMap.Shapes.AddPolyline&#40;loc&#41;;

int PPCount = 0;
foreach &#40;MapPoint.DataSet ds in MP.ActiveMap.DataSets&#41; &#123;
MapPoint.Recordset rs = ds.QueryPolygon&#40;loc&#41;;
rs.MoveFirst&#40;&#41;;
while &#40;!rs.EOF&#41; &#123;
PPCount++;
rs.MoveNext&#40;&#41;;
&#125;
&#125;
Console.WriteLine&#40;"Record count " + Convert.ToString&#40;PPCount&#41;&#41;;```

#### Thread Information

##### Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•