I just added a shapefile subroutine to my GIS software and I am getting some frustrating behavior. I am positive this is a user error, but I cannot for the life of me sort this out. Here’s the code for the subroutine, it’s called with a simple button push.
Public Sub Shape()
AxMap1.Projection = tkMapProjection.PROJECTION_GOOGLE_MERCATOR
AxMap1.GrabProjectionFromData = False
Dim gs As GlobalSettings = New GlobalSettings()
gs.AllowProjectionMismatch = True
gs.ReprojectLayersOnAdding = True
Dim utils As New Utils()
Dim sf As New MapWinGIS.Shapefile
Dim filename As String = projectDirectory + "flintshp.shp"
If Not sf.Open(filename, Nothing) Then
MessageBox.Show("Failed to open shapefile: " + sf.ErrorMsg(sf.LastErrorCode))
Else
With sf.DefaultDrawingOptions
.Visible = True
.FillColor = utils.ColorByName(tkMapColor.Red)
.PointSize = 10
.SetDefaultPointSymbol(tkDefaultPointSymbol.dpsStar)
End With
Dim handle As Integer = AxMap1.AddLayer(sf, True)
AxMap1.ZoomToLayer(handle)
End If
End Sub
If I execute the subroutine as written, The points are drawn on the chart exactly where they are supposed to be. BUT they are small and a random color every time. It’s like it disregards the sf.default drawing options settings I adjust inside the WITH block. If I comment out the top few lines of code:
AxMap1.Projection = tkMapProjection.PROJECTION_GOOGLE_MERCATOR
AxMap1.GrabProjectionFromData = False
Dim gs As GlobalSettings = New GlobalSettings()
gs.AllowProjectionMismatch = True
gs.ReprojectLayersOnAdding = True
Then the settings I configure inside of the sf.default drawing options are used, but the shapefile points are (while in the correct orientation from each other) placed somewhere way off the chart area. so something to do with the projection I presume. The chart is a geotiff based off of google Mercator if that helps… This is a small feature on what has become a fairly complex piece of software. Any insight would be really appreciated as I am just now getting in to shapefiles and the many features and possibilities that these filetypes offer.