2013-12-08 5 views
2

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

Спасибо, D.

ответ

1

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

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

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

Вот пример функции для чтения файла формы заполнены с маршрутами, он будет возвращать список 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 

 Смежные вопросы

  • Нет связанных вопросов^_^