I'm wondering if there's a way to get the longitude/latitude coordinates from the center of a data frame? The problem I'm faced with is this: I want to set a bookmark and have ArcMap tell me the coordinates of the center of that bookmark. (Without using a mouse. This all needs to be automated.) This is akin to hovering one's mouse over the center of a map and reciting the long./lat. numbers that are shown at the bottom of the ArcMap window.

I'm pretty "green" when it comes to VBA programming in ArcMap 10.0. At first I thought I could utilize the "Info" tool, but now I'm guessing that I need to get the use the IEnvelope interface to calculate the center of the map, then grab the coordinates from that. Any ideas?


I would recommend using the IActiveView.Extent property. You can cast an IMap to an IActiveView and vice versa. http://resources.arcgis.com/en/help/arcobjects-net/componenthelp/index.html#//001200000199000000

The Extent property will return an IEnvelope that has an X and Y Max and Min that you can use to calculate the center if you would like.

To get the IActiveView instance you can use the IApplication.Document property and cast the Document to an IMxDocument. You can then get an IActiveView using IMxDocument.ActiveView property. http://help.arcgis.com/en/sdk/10.0/arcobjects_net/componenthelp/index.html#//004900000054000000

Some code-

Dim mxDocument As ESRI.ArcGIS.ArcMapUI.IMxDocument = CType(application.Document, ESRI.ArcGIS.ArcMapUI.IMxDocument) ' Explicit Cast
Dim activeView As ESRI.ArcGIS.Carto.IActiveView = mxDocument.ActiveView
Dim currentExtent As IEnvelope = activeView.Extent
//TODO::  Get Max/Min X and Y from currentExtent and calculate the center point.

Here is a gis.stackexchange post that describes taking a map x,y and converting it to a lat, long. Extracting lat/long from screen when using British National Grid projection in ArcGIS Desktop?

In particular, follow these steps-

I'm not that familiar the the British National Grid, but it appears that a datum transformation is required when projecting to WGS84.

So, use ISpatialReferenceFactory.CreateGeoTransformation to create the appropriate datum transformation, and ISpatialReferenceFactory.CreateGeographicCoordinateSystem to create the target (WGS84) spatial reference.

Finally, cast the point into IGeometry5 and call ProjectEx, passing the target spatial reference and the geotransformation. IPoint.X and IPoint.Y should then represent longitude and latitude of the point where the user clicked.

  • Thanks, Darlene. I think what you're describing can be found here: support.esri.com/fr/knowledgebase/techarticles/detail/23078 That code will return the center position of the map document, but the next step should be to find whichever longitude and latitude coordinates correspond to that point in the map's contents. So this gets me halfway there! – Drew Aug 8 '13 at 13:42
  • Would it be practical to try this? 1) Get the center of the display (using the code above). 2) Draw a point at those x/y coordinates. 3) Get the lat/long of the point. 4) Delete the point. 5) Re-project the map using the derived lat/long. – Drew Aug 8 '13 at 13:53
  • This stack exchange post describes how to convert a map point to a lat/long. It is similar to what you proposed. I don't think you need to draw and delete the point; I would expect you to be able to work with the point in memory. gis.stackexchange.com/questions/7114/… – Darlene Aug 8 '13 at 13:58
  • That uses a mouse click event, and I mentioned in my first post that we're trying to automate this process, not use a mouse. – Drew Aug 8 '13 at 14:10
  • Right, you can ignore the part that talks about a mouse click event. You will get your IPoint from calculating the center point of your IEnvelope. Then you can use your IPoint as described in the post I linked to that states to use IGeometry5.ProjectEx(targetSpatialRef, geoTransformation). – Darlene Aug 8 '13 at 14:21

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.