Tuesday, 5 January 2016

arcgis engine - Control the colors of a shapefile


I have a Shapefile with road data. Sometimes the roads are blue, sometimes they are green. I didn't used to mind, but now I'm tiling everything so I need to control the colors.


I'm loading it with this command in ArcEngine:


mapControl.AddShapeFile(fileDir, fileName);


How can I control the colors so they are the same everytime?


I'm using ArcEngine 10 C# with VS2010



Answer



Shapefiles don't have any sort of symbology attached.


Since you're working with ESRI tools, why not wrap them in a layer package? Here's how.


From the link: "When users add a layer file to their maps, it will draw exactly as it was saved as long as they can get access to the data referenced by the layer."


Just be careful to use relative paths, and keep them the same. (The .lyr augments the shapefile; it doesn't replace it.)


Edit to add: you'll also be using the AddLayerFromFile method, rather than AddShapeFile.


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...