Как рисовать фигуры ESRI поверх выходных данных GMap.NET или с помощью моего графического объекта

У меня есть приложение C#, которое использует GMap.NET для отображения карт мира и других моих данных. У меня есть объект Graphics для рендеринга. Мне также нужно отобразить файлы форм ESRI в виде полупрозрачных фигур на моей карте. Как мне это представить? Доступные библиотеки выглядят так, как будто они втянуты в свой собственный элемент управления Windows. Кроме того, когда я смогу это отобразить, как мне точно синхронизировать карту и координаты формы?

Спасибо д.


person Jim    schedule 08.12.2013    source источник


Ответы (1)


GMap.Net не поддерживает прямое чтение шейп-файлов ESRI, но вы можете использовать стороннюю библиотеку, например MapTools. .Net-оболочка для библиотеки (ShapeLib).

Сначала вы должны прочитать файл формы с помощью библиотеки (MapTools) и выполнить цикл для каждой геометрии (точка, линия, многоугольник) и преобразовать проекцию геометрии с помощью Библиотека Proj4Net и добавьте каждую геометрию в соответствующий оверлей в GMapControl.

Вы можете скачать последнюю версию (MapTools) по этой ссылке

Вот пример функции для чтения шейп-файла, заполненного маршрутами, она вернет список GMapRoutes, затем вам нужно нарисовать их на карте.

Public  Function ReadRoutesFromShapefile(ByVal filename As String) As List(Of GMapRoute)

        Dim basePath As String = Path.GetDirectoryName(filename) & AscW(Path.DirectorySeparatorChar) & Path.GetFileNameWithoutExtension(filename)

        If Not File.Exists(basePath & ".prj") Then
            Throw New Exception("Could not find the projection file!")
        End If

        'Get info from WKT-File:
        Dim wkt As String = File.ReadAllText(basePath & ".prj")

        Dim gcs As ICoordinateSystem = TryCast(CoordinateSystemWktReader.Parse(wkt), ICoordinateSystem)
        Dim doTransformation = Not gcs.AuthorityCode = 4326

        Dim wgs84 As GeographicCoordinateSystem = GeographicCoordinateSystem.WGS84
        Dim ctfac As New CoordinateTransformationFactory()
        Dim trans As ICoordinateTransformation = ctfac.CreateFromCoordinateSystems(gcs, wgs84)

        'Open shape-file
        Dim shapeFile As IntPtr = ShapeLib.SHPOpen(basePath, "rb")

        Dim numOfRecords As Integer = 0

        'Check type and get number of entries
        Dim shapeType As ShapeLib.ShapeType = 0
        ShapeLib.SHPGetInfo(shapeFile, numOfRecords, shapeType, Nothing, Nothing)

        If Not shapeType.Equals(ShapeLib.ShapeType.PolyLine) Then
            Throw New Exception("The shape type is not polyline but " & shapeType)
        End If

        Dim lstRoutes As New List(Of GMapRoute)(numOfRecords)

        'Get info from shapefile and save data:
        For i As Integer = 0 To numOfRecords - 1
            'Add all GPS-Points:
            'Get pointer to object
            Dim ptrPolyline As IntPtr = ShapeLib.SHPReadObject(shapeFile, i)

            'Create actual object:
            Dim polyline As New ShapeLib.SHPObject()
            Marshal.PtrToStructure(ptrPolyline, polyline)

            If polyline.nParts = 1 Then
                'Get number of points and arrays of X and Y values:
                Dim numPoints As Integer = polyline.nVertices

                Dim lstpoints As New List(Of PointLatLng)(numPoints)

                Dim xCoord(numPoints - 1) As Double
                Dim yCoord(numPoints - 1) As Double

                'Fill the arrays:
                Marshal.Copy(polyline.padfX, xCoord, 0, numPoints)
                Marshal.Copy(polyline.padfY, yCoord, 0, numPoints)

                'Add all Points
                For j As Integer = 0 To numPoints - 1
                    Dim latitude As Double = 0.0R
                    Dim longitude As Double = 0.0R

                    If doTransformation Then
                        'Convert from original coordinate system to wgs84
                        Dim fromPoint() As Double = {xCoord(j), yCoord(j)}
                        Dim toPoint() As Double = trans.MathTransform.Transform(fromPoint)
                        'Get point from polyline
                        longitude = toPoint(0)
                        latitude = toPoint(1)
                    Else
                        longitude = xCoord(j)
                        latitude = yCoord(j)
                    End If

                    lstpoints.Add(New PointLatLng(latitude, longitude))
                Next j

                lstRoutes.Add(New GMapRoute(lstpoints, "Route" & (i + 1).ToString()))
            End If

            polyline = Nothing
            ShapeLib.SHPDestroyObject(ptrPolyline)
        Next i

        ShapeLib.SHPClose(shapeFile)

        Return lstRoutes
    End Function
person Ahmed GIS    schedule 02.11.2015