Wednesday, May 23, 2007

At some point between the release of ArcMap 8.0 and now, automated MXD creation/editing became much easier with ArcMap. Previously, a stand-alone application had to open up a session of ArcMap and then control it remotely through a poorly documented and buggy automation-like process. This wasn't true automation in the MS Office sense, but it was very similar. Unfortunately, it was very complicated to do properly and suffered from inexplicable speed problems - drawing a simple 8 point polygon on a map could take up to 20 minutes!

But now thanks to the IMapDocument interface, it's very easy to create a standalone application that can create a new MXD file or alter an existing one. Pretty much any object an ArcMap document can be accessed - data layers, page layout, graphic elements - you name it. It's still not true automation since you're not actually opening an ArcMap session, but if you really needed to, you could launch your MXD document once the stand-alone program does its job.

How easy is it? Here's a very simple sample that draws a big square on an existing MXD document and then saves it with a different name. From this starting point, you could also add layers, text and whatever crazy stuff you'd want on a map.

Private Sub AddRectangle()'Adds a graphic element to the layoutDim pPageLayout As IPageLayoutDim pContainer As IGraphicsContainerDim pGraphicElement As IElementDim pEnvelope As IEnvelope'Specify where to put the rectangle (on the page layout)pPageLayout = m_pDoc.PageLayout pContainer = pPageLayout'Create a rectangle

Links

About Me

I'm Ben Slater, GIS Data Manager at Wetland Studies and Solutions, Inc., an environmental consulting firm in Northern Virginia. I received a B.A. in Geography from Virginia Tech in 1995 and worked as a GIS research assistant at Harvard
Forest from 1995 to 1999. There, I assisted in various academic studies, mostly centered around historic land use changes and their effects on the current environment. After that, I relocated to Northern Virginia (my point of origin) and worked at the Prince William County GIS department for 6 months. In January 2000, I began working as the sole GIS Analyst at Wetland Studies, then a small firm of about 20 people. Today, WSSI employs about 100 people, has 7 full time GIS employees, and has acquired Thunderbird Archeology. My work here consists of developing in-house applications (mostly centered around automated map-production), production cartography, database development and maintenence, intranet development, and whatever else needs doing.