1

I am using ArcObjects 10.2 to generate grid index features programmatically. I can get the correct output using the built in GUI geoprocessing tools, and with ArcPy. Furthermore, when I copy the python snippet from the result history of running the geoprocessing tool from ArcObjects, the resulting geometry is what I expect.

However, when run directly from ArcObjects, what I expect to be an array of grid features are all stacked on top of each other. How can I get the output to be an array of grid features over the input feature, just like with running the tool in the GUI?

Relevant code:

// Get the map from the map document
IMap map = mxDoc.ActiveView.FocusMap;
IActiveView activeView = map as IActiveView;
IEnvelope extent = activeView.Extent;

string outputFeatures = "in_memory\\" + lyrName;

// Set the parameters for the grid index feature tool
string polygonWidth = "32.5 Inches";
string polygonHeight = "19.2 Inches";
double scale = activeView.ScreenDisplay.DisplayTransformation.ScaleRatio;
string startingPageNumber = "1";
string originCoord = extent.XMin + " " + extent.YMin;


var geoprocessingTool = new ESRI.ArcGIS.CartographyTools.GridIndexFeatures();
geoprocessingTool.in_features = inputFeatures.Name;
geoprocessingTool.intersect_feature = "INTERSECTFEATURE";
geoprocessingTool.out_feature_class = outputFeatures;
geoprocessingTool.use_page_unit = "USEPAGEUNIT";
geoprocessingTool.scale = Convert.ToInt32(scale);
geoprocessingTool.polygon_width = polygonWidth;
geoprocessingTool.polygon_height = polygonHeight;
geoprocessingTool.number_rows = 6;
geoprocessingTool.number_columns = 5; 
geoprocessingTool.starting_page_number = Convert.ToInt32(startingPageNumber);
geoprocessingTool.origin_coord = originCoord;

ExecuteGeoprocessingTool(geoprocessingTool);

To be clear, the grid index features that get create and stacked on top of each other are all created in the center of the extent.

1 Answer 1

0

Turns out the reason the grids were all stacked was a function call I made later on. I had initially designed this function to work with a single grid and center it over the current extent. When refactoring to create as many grids as it needed, a bit of code was still running later on that moved and centered the grids. The above code does work just fine.

Since its not clear in the documentation, as long as the scale and page units are set, the number of rows and columns can be left undefined and the geoprocessing tool will automatically work out how many it needs.

Not the answer you're looking for? Browse other questions tagged or ask your own question.