Skip to main content

How to: Manually Load Cartesian Data to a Geo Map Using Predefined Coordinate Converters

  • 2 minutes to read

To load a Cartesian map shapefile to a Map Control, do the following

View Example

<Window
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:BuildInCoordinateConverters"
        xmlns:dxm="http://schemas.devexpress.com/winfx/2008/xaml/map" 
        x:Class="BuildInCoordinateConverters.MainWindow"
        Title="MainWindow" MinHeight="350" MinWidth="525">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="Auto"/>
            </Grid.ColumnDefinitions>
            <ComboBox Name="lbMapData" Grid.Column="0" SelectedIndex="0">
                <ComboBox.ItemTemplate>
                    <DataTemplate>
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Text="File Uri:" Margin="2,2,2,2"/>
                            <TextBlock Text="{Binding FileUri}" Margin="2,2,10,2"/>
                            <TextBlock Text="Coordinate Converter:" Margin="10,2,2,2"/>
                            <TextBlock Text="{Binding CoordinateSystem.CoordinateConverter}" Margin="2,2,2,2"/>
                        </StackPanel>
                    </DataTemplate>
                </ComboBox.ItemTemplate>

                <!--region #Albers-->
                <local:MapData FileUri="Shapefiles/Albers/switzerland.shp">
                    <local:MapData.CoordinateSystem>
                        <dxm:CartesianSourceCoordinateSystem>
                            <dxm:CartesianSourceCoordinateSystem.CoordinateConverter>
                                <dxm:AlbersEqualAreaConicCartesianToGeoConverter StandardParallelN="60.0" StandardParallelS="20.0"
                                                             Ellipsoid="{x:Static dxm:Ellipsoid.GRS80}"
                                                             ProjectionCenter="40,-96"/>
                            </dxm:CartesianSourceCoordinateSystem.CoordinateConverter>
                        </dxm:CartesianSourceCoordinateSystem>
                    </local:MapData.CoordinateSystem>
                </local:MapData>
                <!--endregion #Albers-->
                <!--region #Lambert-->
                <local:MapData FileUri="Shapefiles/Lambert/Belize.shp">
                    <local:MapData.CoordinateSystem>
                        <dxm:CartesianSourceCoordinateSystem>
                            <dxm:CartesianSourceCoordinateSystem.CoordinateConverter>
                                <dxm:LambertConformalConicCartesianToGeoConverter StandardParallelN="60" StandardParallelS="20"
                                                                              ProjectionCenter="40,-96"
                                                                              Ellipsoid="{x:Static dxm:Ellipsoid.GRS80}">
                                </dxm:LambertConformalConicCartesianToGeoConverter>
                            </dxm:CartesianSourceCoordinateSystem.CoordinateConverter>
                        </dxm:CartesianSourceCoordinateSystem>
                    </local:MapData.CoordinateSystem>
                </local:MapData>
                <!--endregion #Lambert-->
                <!--region #TransverseMercator-->
                <local:MapData FileUri="Shapefiles/TransverseMercator/israel.shp">
                    <local:MapData.CoordinateSystem>
                        <dxm:CartesianSourceCoordinateSystem>
                            <dxm:CartesianSourceCoordinateSystem.CoordinateConverter>
                                <dxm:TransverseMercatorCartesianToGeoConverter Ellipsoid="{x:Static dxm:Ellipsoid.WGS84}"
                                                                           ProjectionCenter="0,33" ScaleFactor="0.9996"
                                                                           FalseNorthing="0" FalseEasting="500000">
                                </dxm:TransverseMercatorCartesianToGeoConverter>
                            </dxm:CartesianSourceCoordinateSystem.CoordinateConverter>
                        </dxm:CartesianSourceCoordinateSystem>
                    </local:MapData.CoordinateSystem>
                </local:MapData>
                <!--endregion #TransverseMercator-->
                <!--region #UTM-->
                <local:MapData FileUri="Shapefiles/TransverseMercator/israel.shp">
                    <local:MapData.CoordinateSystem>
                        <dxm:CartesianSourceCoordinateSystem>
                            <dxm:CartesianSourceCoordinateSystem.CoordinateConverter>
                                <dxm:UTMCartesianToGeoConverter UtmZone="36" Hemisphere="Northern"/>
                            </dxm:CartesianSourceCoordinateSystem.CoordinateConverter>
                        </dxm:CartesianSourceCoordinateSystem>
                    </local:MapData.CoordinateSystem>
                </local:MapData>
                <!--endregion #UTM-->
                <!--region #MercatorAuxiliary-->
                <local:MapData FileUri="Shapefiles/MercatorAux/montenegro.shp">
                    <local:MapData.CoordinateSystem>
                        <dxm:CartesianSourceCoordinateSystem>
                            <dxm:CartesianSourceCoordinateSystem.CoordinateConverter>
                                <dxm:MercatorAuxiliarySphereCartesianToGeoConverter Ellipsoid="{x:Static dxm:Ellipsoid.WGS84}"
                                                                                SphereType="0" ProjectionCenter="0,0"/>
                            </dxm:CartesianSourceCoordinateSystem.CoordinateConverter>
                        </dxm:CartesianSourceCoordinateSystem>
                    </local:MapData.CoordinateSystem>
                </local:MapData>
                <!--endregion #MercatorAuxiliary-->
            </ComboBox>
            <Button Grid.Column="1" Content="Locate Loaded Data" Click="Button_Click"/>
        </Grid>
        <dxm:MapControl Grid.Row="1" Name="map">
            <dxm:ImageTilesLayer>
                <dxm:ImageTilesLayer.DataProvider>
                    <dxm:BingMapDataProvider BingKey="YourBingKey"/>
                </dxm:ImageTilesLayer.DataProvider>
            </dxm:ImageTilesLayer>
            <dxm:VectorLayer ShapeFill="#40FF8800">
                <dxm:ShapefileDataAdapter 
                    SourceCoordinateSystem="{Binding Path=SelectedValue.CoordinateSystem, ElementName=lbMapData}" 
                    FileUri="{Binding Path=SelectedValue.FileUri, ElementName=lbMapData}"/>
            </dxm:VectorLayer>
        </dxm:MapControl>
    </Grid>
</Window>