January 23, 2010

Enhanced Stylization - Line Styles

The cartographic stylization engine in Topobase provides far better line stylization than AutoCAD can provide. For example, instead of just a single line with a pattern, thickness and color, you can have multiple lines of various thicknesses, with various embellishments and different joining and capping options. So, if you forgo fidelity when exporting data to a .dwg, you can take advantage of some excellent capabilities for line symbolization.

It is assumed that you have added layers using enhanced stylization, or set up the layer templates as described in Annotation Layers to automatically use enhanced stylization.

Start with a couple of standard line styles, one for a gas pipeline and one for a railway. These are standard linestyles that can be found in acad.lin, the AutoCAD line pattern definition file. They are named GAS_LINE and TRACKS respectively. Each has been given a little line thickness and a color. To be clear, what is shown in the image to the right are not AutoCAD lines, but rather linear features that have been symbolized to look like AutoCAD lines. There are discrepancies; for example, AutoCAD would not thicken the 'GAS' text when a polyline is given a width.

To put some context to these explorations, let's vary one thing at a time, starting with the geometry for the gas line. Let's say you wanted two parallel lines to run unbroken along each side of the linestring. If you open the pipeline layer file with a text editor you will see something like this (after formatting):

The <Geometry> element for the paths are a bunch of M (move to) and L (line to) operations as described in Enhanced Stylization - Flow Direction, with the added caveat that lower case L means the target coordinates are relative to the current location.

The first <Path> element, the complicated one, draws the 'GAS' text and the second <Path> element draws the lines between the text. As I said, this is only an approximation to the linetype in the acad.lin file, so the 'GAS' text is drawn with a whole lot of little segments, and not an embedded shape like in the AutoCAD line style.

The symbolization basically draws a line from 0,0 to 5,0 (the second <Path> element) and then draws a few lines that look like the word 'GAS' within a bounding box of approximately 6.0,-0.5 to 8.6667,0.5 (the first <Path> element), and then repeats the whole process at 9.5 unit intervals (the <Repeat> value). So to draw parallel lines above and below the 'GAS' text, one would have to offset them more than 0.5 units, say 0.7 units, and to make them look continuous they would need to be 9.5 units long, so that the repetition by the next symbolization will join with the first.

Thus, we modify the second <Path> <Geometry> element to be two lines:

<Geometry>M 0,0.7 L 9.5,0.7 M 0,-0.7 L 9.5,-0.7</Geometry>

which gives the result shown to the right.

If you're not happy with the font of the 'GAS' text either (really, who uses STANDARD text anymore), you can replace the drawn text with a real piece of text. The <Text> element has a lot of options. You will need a <Content> element with the word 'GAS' in it and a <FontName> element with a valid font name like 'Swiss 721 Black BT'. The available font names can be obtained from the list shown in the Windows Control Panel by double-clicking the Fonts icon.

Beyond that, to emulate the existing style we will need a <Height> element to set the height to 1.0, and <PositionX> and <PositionY> elements to set the position. The default horizontal alignment mode is Center and the default vertical alignment mode is Halfline, so the necessary position coordinates are 7.33335,0.0 (in the middle of the bounding box of the original text). To set the font color to be the same as the line color, add a <TextColor&gt element with a value of %LINECOLOR% so that setting the line color also sets the text color.

If the 'GAS' text repeats too often, the repeat interval can be extended, say to 20, but then the path elements for the (parallel) lines and probably the position elements for the text would also need to be altered.

Turning now to the railway line style, if we wanted to have the symbolization look more like train tracks, we could also change the single central line to a double parallel line as above. Opening the railway layer file you find symbolization like this:

The first <Path> element draws the railway ties 2.5 units to left and right, while the second <Path> element draws the central line (actually in two segments, but this is redundant). So, let's change the central line to be two parallel lines offset by 1.9. Then the second path <Geometry> element becomes:

<Geometry>M 0,1.9 L 3.0,1.9 M 0,-1.9 L 3,-1.9</Geometry>

which gives the results on the right.

Although it's possible to increase the line thickness so that the railway ties look like railway ties, this would also thicken the railway rails. To get thick railway ties without thick rails one can change the geometry of the first path to outline the ties as rectangles with a thickness of 0.6:

<Geometry>M 1.2,0 l 0,2.5 l 0.6,0 l 0,-5 l -0.6,0 Z</Geometry>

The result is shown to the right.

To fill the outline though, a few more tricks are required. First, a <FillColor> element must be added to the path for the railway ties, so the final <Path> element is as follows:

Finally, in order to be able to set the parameter from the Style and Label Editor user interface, the <ParameterOverrides> element needs to have an additional <Override> element to set the fill color for the linestyle:

At this point you can click on the Expression builder for the FillColor parameter and create an expression to stylize the fill color value of the ties. For example you might want to theme the ties based on material.
The expression shown on the right would provide that. The LOOKUP function has a first parameter of the attribute to use (TIE) and a second parameter of the default (0xFFFF0000) color. Note that the color format is 0x to indicate a hexadecimal value followed by two hexadecimal characters for each of alpha, red, green and blue values. So, in this example, the first FF indicates a fully opaque alpha, and the second FF is full red, and the following two pairs of zeros indicate no green or blue, so the color is red like the outline lines. The rest of the parameters to LOOKUP are index and value pairs. In this case, if the TIE attribute is 'Concrete' then use 0xFF00FF00 (full alpha, no red, full green and no blue), and if it is 'Wood' then use 0xFF0000FF (full alpha, no red or green and full blue) - green for concrete and blue for wood. By setting the alpha values to smaller values (e.g. 77) you can get transparent fills. The point symbol in the images in this post has a value of CC for alpha.

This is the symbolization for wood ties:

The resulting layer files are available for download, in case they might be useful as an example.

AUTODESK DOES NOT GUARANTEE THAT YOU WILL BE ABLE TO SUCCESSFULLY DOWNLOAD OR IMPLEMENT ANY SAMPLE CODE. SAMPLE CODE IS SUBJECT TO CHANGE WITHOUT NOTICE TO YOU.
AUTODESK PROVIDES SAMPLE CODE "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED, INCLUDING WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE. IN NO EVENT SHALL AUTODESK OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS
OF DATA, OR LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, THAT MAY OCCUR AS A RESULT OF IMPLEMENTING OR USING ANY SAMPLE CODE, EVEN IF AUTODESK OR ITS SUPPLIERS
HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.

TrackBack

Comments

Tried the RR and it looks very good. There are small "breaks" at I think where a rail line bends slightly that don't appear when using the standard Autocad tracks symbology. Thanks for the sample display model.

I need to create a line style with a arrow head at the end and a Circle at the beginning with some shapes in between the end points getting repeated(i.e. not the arrow and the circle). This is needed to differentiate certain set of sewers from the rest.

o---------x---------x----------x-------->

Is it possible to specify a block and align it with the direction of the line in the above specification?

It's possible to use a block in a line style with AngleControl equal to FromGeometry, but I think you want a different symbolization at the start and end points - which would require a point feature to be symbolized separately.

This is very interesting. Would it be possible to create an enhanced style for power line conductors that would use phase letter attributes to make the line look like multi-lines in parallel with each other, colored red for A phase blue for B phase and green for C phase and center some text with the associated circuit designation.

So for a three phase conductor on C7 circuit it would be three parallel lines, red blue green, with the text C7 centered along its length.

If it was two phases only two parallel line colors would display with the circuit text centered along its length and only one colored line if it were single phase.