How to colorize objects by non digital values

2 posts, 0 answers
  1. Nikolai
    Nikolai avatar
    13 posts
    Member since:
    Oct 2010

    Posted 08 Aug 2012 Link to this post

    У меня имеется shp-файл, содержащий полилинии. Необходимо раскрасить полилинии в зависимости от их кодов, которые прописаны в dbf-файле. Код линии не является числом. Можно ли выполнить раскраску без заложения функции отображающей значение поля в число?

    I have some shape file with polylines. I have to draw polylines by codes which are not numbers. Can I do this without coding field values by digits?
  2. Andrey
    Andrey avatar
    1681 posts

    Posted 10 Aug 2012 Link to this post

    Hi Nikolai,

    Yes, you can colorize polylines using the dbf-field which is not numeric. You can use the PreviewReadCompleted event for this purpose. The sample code is below.
    <telerik:RadMap x:Name="radMap" Center="40,-100" ZoomLevel="7">
            <telerik:OpenStreetMapProvider />
        <telerik:InformationLayer x:Name="informationLayer">
                <telerik:MapShapeReader Source="polylines" PreviewReadCompleted="OnPreviewReadCompleted" />

    private void OnPreviewReadCompleted(object sender, PreviewReadShapesCompletedEventArgs eventArgs)
        if (eventArgs.Error != null)
            foreach (object item in eventArgs.Items)
                var polyLine = item as MapPolyline;
                if (polyLine != null)
                    string code = (string)polyLine.ExtendedData.GetValue("CODE");
                    this.SetPolylineColor(polyLine, code);
    private void SetPolylineColor(MapPolyline polyLine, string code)
        Color color = Colors.Blue;
        switch (code)
            case "RED":
                color = Colors.Red;
            case "YELLOW":
                color = Colors.Yellow;
        polyLine.Stroke = new SolidColorBrush(color);
        polyLine.StrokeThickness = 3;

    All the best,
    Andrey Murzov
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Back to Top