About Map Grids


In this topic


Overview

The Carto library contains a rich set of map grid objects for displaying index and geographic reference grids on a map. A map grid can be a grid of geographic or projected coordinates, or a reference grid like those found in street maps. Map grids are part of the layout of a map and are only visible in layout view.
By reviewing the ArcMap object model diagram (OMD), you can see that all the available standard grid classes in ArcGISCustomOverlayGrid, Graticule, IndexGrid, and MeasuredGrid are subtypes of the MapGrid abstract class. The existing map grids also implement IGraphicsComposite . This interface can be used programmatically to access graphic elements that compose the displayed map grid.
 

To get to a map grid programmatically, navigate to the P ageLayout coclass, and then use the IGraphicsContainer interface’s findFrame method to get to the Map’s MapFrame. The MapFrame coclass has an IMapGrids interface from which you can get to all the map grids for that data frame.
 
IMapGrid provides access to the methods and properties common to all types of map grids. When you create a new map grid, you have to populate the properties of the grid that IMapGrid exposes. After doing this, you can populate the properties exposed by interfaces specific to the grid type, then add the grid to a data frame.
 
 
 
Index grids
An index grid is a map grid that divides the map into the specified number of columns and rows.
IIndexGrid gives you access to the functionality common to all index grids. Using the XLabel and the YLabel properties, you can set or get the label for each column and index in the grid.
 
 
Measured grid
A measured grid is a map grid with grid lines on a coordinate system specified using the IProjectedGrid interface.
 
The IProjectedGrid interface holds the spatial reference information associated with a measured grid. If you want to create a measured grid in the same projection as the data frame it is in, you can use the data frame’s IMap.getSpatialReference() property and
set the Spatial reference property using IProjectedGrid.setSpatialReferenceByRef() method.
 
A measured grid divides the map into a grid of units in a coordinate system of your choice. The grid can be in a projected coordinate system or in a geographic coordinate system. A measured grid in a geographic coordinate system is equivalent to a graticule. A measured grid can be in the same spatial reference system as the data frame or in a different one. To create a measured grid with a different projection, first create an instance of a coclass that inherits from SpatialReference. You can then set the IProjectedGrid.setSpatialReferenceByRef() method of the grid with the ISpatialReference interface of this object.

Custom overlay grids
A custom overlay grid is a map grid with grid lines read from a feature. The ICustomOverlayGrid interface gives you access to the feature class that the grid lines are read from through the ICustomOverlayGrid.getDataSource() method. It also lets you specify which field in this feature class will label the grid using the ICustomOverlayGrid.getLabelField() method.

Map grid borders
The map grid border coclasses determine how the outline of a map grid is drawn. Using the IMapGridBorder interface, you can find the width of the map grid border. Using the getDisplayName() method, you can report the type of the border object to which the IMapGridBorder interface is pointing. The table below lists the strings reported by this property for the two border types.
 
 
When you create a new map grid border, you do not use the IMapGridBorder interface; as all the properties exposed by this interface are read-only. A simple map grid border is drawn using a line symbol specified with the ISimpleMapGridBorder interface.
 
 
 
Calibrated map grid borders
The CalibratedMapGridBorder coclass encapsulates the functionality required to draw a map grid outline composed of a graduated band.
 
You can use the ICalibratedMapGridBorder interface to set or retrieve the properties of a calibrated map grid border, such as the foreground and background color of the pattern, the interval of the pattern, the background color of the band, and the width of the border. If you want the pattern to alternate in two bands across the width of the border, set the Alternating property to True. Setting this property to False will produce a border with a single band of the pattern.
 
The interval of the pattern on the band is in points and page units. If you want to compute your border intervals in map units, you can use a DisplayTransformation to convert your interval from map units to page units. You can convert these units to points, noting that there are 72 points to an inch.
 
 
 
Grid labels
A grid label object is associated with every map grid object and provides the functionality required to draw labels around the map grid.
 
The table below lists the strings returned for the various label types.
 
 
 
The interfaces returned for each of the label types are listed in the table below.
 
 
DMS grid labels
A DMS grid label labels the map grid using degrees, minutes, and seconds. You can use the DMSGridLabel coclass to label graticules.
 
IDMSGridLabel provides access to the font, color, and format information required to create a DMS grid label. The setLabelType() method can be set using the esriDMSGridLabelType enumeration, which is listed below. You can use a standard label to create a DMS label with the degrees, minutes, and seconds on the same line. A stacked label has the minutes stacked over the seconds, with both in smaller font size.
 
 
 
 
Formatted grid labels
The FormattedGridLabel coclass uses any of the coclasses that inherit from the NumberFormat abstract class to create the grid labels.
 

 
 
Mixed font grid labels
A mixed font grid label uses two fonts to display the label. It also uses a number format to format the label string. Use the MixedFontGridLabel coclass to label map grids in two fonts and in the format specified using the IFormattedGridLabel interface.
 
The IMixedFontGridLabel.setNumGroupedDigits(n) determines how the two fonts are applied to the label string. The last n digits of the label—where n is the NumberOfDigits—are displayed in the secondary font and color. The remaining digits display in the primary font and color. The primary font and color are set using IGridLabel.setFont and IGridLabel.setColor. The secondary font and color are set using MixedFontGridLabel.setSecondaryFont and MixedFontGridLabel.setSecondaryColor.
 
 
 
Index grid tab styles
 
The index grid tab style coclasses provide the means to label an index grid. You can create an index grid tab style label using a coclass that inherits from IndexGridTabStyle. Button tab style labels are rectangular buttons, each the width of the grid cell that it borders. Continuous tab style labels form a continuous band around the map grid. Rounded tab style labels are rounded rectangles; each one is the width of the grid cell it borders.
 
 
 
A background tab style labels the index grid using square, round, or rounded-square boxes. These boxes are centered outside the grid cells they border. Use IBackgroundTabStyle to determine the shape of the boxes.
 
 
 
 
For more information on working with Map Grids, see How to interact with Map Grids and How to interact with Map Grid labels.

Creating a subtype of MapGrid

A custom map grid must implement IMapGrid . You also need to implement IClone and either IPersist  and IPersistStream or IPersistVariant (depending on your development environment), as grids must be capable of cloning and persisted. See the following illustration:
The MapGrid abstract class represents a grid of reference points or lines over a map. Refer to this abstract class as the starting point for any custom map grid class.

Design issues for a custom grid class

Before you start coding your custom grid class, ask yourself if the functionality you require is similar to that available in any of the standard ArcGIS grid classes.
  • If you want to use one of the standard grids but change the way one or two methods or properties work, contain an instance of the required class within your custom class. Delegate all property and method calls to the contained object and adapt as required to change the way the method works. For example, if you require an IndexGrid that has extra labels, you can contain an instance of IndexGrid in your class and delegate member calls to this class. On a call to Draw, after calling the contained IndexGrid's Draw, you can add your extra labeling as required.
You may want to base your custom map grid on a preexisting map grid class by using containment.
  • If you want to add functionality to a grid, you can use containment to hold an instance of a preexisting grid class in your custom grid class. Add one or more interfaces that provide access to the new functionality. This design is similar to the approach taken in this example.
  • If your grid requirements are significantly different from standard grids, you may want to create a new kind of map grid. In this case, you must write most of the behavior, but you can save time by implementing only the interfaces required for a basic grid to function—that is, those listed previously for the MapGrid abstract class.


See Also:

IMapGrid Interface: Java Documentation
How to create Map Grids
How to create Map Grid labels




Development licensingDeployment licensing
ArcGIS for Desktop BasicArcGIS for Desktop Basic
ArcGIS for Desktop StandardArcGIS for Desktop Standard
ArcGIS for Desktop AdvancedArcGIS for Desktop Advanced
Engine Developer KitEngine