Back to Devexpress

MapItemsLayerBase.ExportToKml(String) Method

windowsforms-devexpress-dot-xtramap-dot-mapitemslayerbase-dot-exporttokml-x28-system-dot-string-x29.md

latest5.3 KB
Original Source

MapItemsLayerBase.ExportToKml(String) Method

SECURITY-RELATED CONSIDERATIONS

Using file paths sourced from untrusted input may expose unauthorized files or allow unintended file access. Always validate and normalize all external paths to prevent path manipulation.

Exports data from this vector layer to the specified KML file.

Namespace : DevExpress.XtraMap

Assembly : DevExpress.XtraMap.v25.2.dll

NuGet Package : DevExpress.Win.Map

Declaration

csharp
public void ExportToKml(
    string filePath
)
vb
Public Sub ExportToKml(
    filePath As String
)

Parameters

NameTypeDescription
filePathString

A String object specifying the file path used to save vector items.

|

Example

This example shows how to export the map vector layer items to the .SVG , .KML , and .SHP file formats.

The following API members are used:

MemberDescription
MapItemsLayerBase.ExportToSvgExports data from this vector layer to the specified stream using the defined parameters.
SvgExportOptionsThe options to be applied when exporting the vector layer to the SVG file format.
MapItemsLayerBase.ExportToKmlExports data from this vector layer to the specified stream using the KML file format.
MapItemsLayerBase.ExportToShpExports this vector layer data to the specified shapefile.
ShpExportOptionsThe options to be applied when exporting the vector layer to a shapefile.
XtraSaveFileDialogA dialog that allows a user to save a file. Supports DevExpress Skins.
csharp
VectorItemsLayer layer { get { return mapControl.Layers[0] as VectorItemsLayer; } }
//...
private void exportButton_Click(object sender, EventArgs e) {
    XtraSaveFileDialog xtraSaveFileDialog = new XtraSaveFileDialog() {
        Title = "Export...",
        FileName = "Map",
        Filter = "SVG Image|*.svg|KML File|*.kml|Shapefile|*.shp"
    };
    xtraSaveFileDialog.ShowDialog();
    if(xtraSaveFileDialog.FileName != string.Empty) {
        switch(xtraSaveFileDialog.FilterIndex) {                    
            case 1:
                layer.ExportToSvg(xtraSaveFileDialog.FileName, 1, new SvgExportOptions() {
                    CoordinateSystem = new GeoMapCoordinateSystem(),
                    InitialMapSize = mapControl.Size
                });
                break;
            case 2:
                layer.ExportToKml(xtraSaveFileDialog.FileName);
                break;
            case 3:
                layer.ExportToShp(xtraSaveFileDialog.FileName, new ShpExportOptions {
                    ExportToDbf = true,
                    ShapeType = ShapeType.Polygon
                });
                break;
            default:
                break;
        }
    }
}
vb
Private ReadOnly Property layer As VectorItemsLayer
        Get
            Return CType(mapControl.Layers(0),VectorItemsLayer)
        End Get
End Property
'...
Private Sub exportButton_Click(ByVal sender As Object, ByVal e As EventArgs)
    Dim xtraSaveFileDialog As XtraSaveFileDialog = New XtraSaveFileDialog() With {
        .Title = "Export...",
        .FileName = "Map",
        .Filter = "SVG Image|*.svg|KML File|*.kml|Shapefile|*.shp"
    }
    xtraSaveFileDialog.ShowDialog()
    If xtraSaveFileDialog.FileName <> String.Empty Then
        Select Case xtraSaveFileDialog.FilterIndex
            Case 1
                layer.ExportToSvg(xtraSaveFileDialog.FileName, 1, New SvgExportOptions() With {
                    .CoordinateSystem = New GeoMapCoordinateSystem(),
                    .InitialMapSize = mapControl.Size
                })
            Case 2
                layer.ExportToKml(xtraSaveFileDialog.FileName)
            Case 3
                layer.ExportToShp(xtraSaveFileDialog.FileName, New ShpExportOptions With {
                    .ExportToDbf = True,
                    .ShapeType = ShapeType.Polygon
                })
            Case Else
        End Select
    End If
End Sub

See Also

MapItemsLayerBase Class

MapItemsLayerBase Members

DevExpress.XtraMap Namespace