8

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

2 Answers 2

18

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.

2

There is another way, if you set up a new Style File and save to the location of your shapefile with the symbology you want to use, the shapefile will automatically render the features in the same way as the style. This is a hangover from ArcView 3 which is still there at 10 but not sure how much longer.

Have Fun, CDB

2
  • this is the first I've head of this, sounds interesting. Can you provide more info? For example do the style files need to have the same filename as the shapefile they refer too? and do you use the Style Manager to build them or something else? Commented Dec 11, 2010 at 6:39
  • Yes they do and need to be stored in the same location, They only work when symbolising all features initally so I have used this as a method. Open Style Manager and create a new style in the data location called the same as the shapefile, then create a symbol called the shapefile name. lastly add the shapefile to ArcMap and the symbol you selected will automatically be rendered. Have Fun, CDB
    – CDBrown
    Commented Dec 12, 2010 at 23:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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