Getting Started in VB.net

Topics: General Topics
May 11, 2014 at 1:04 AM
I have used nuget to download and install Sharpmap into vb.net

My attempt to create a map with some data amounts to this
    Dim Map As New Map(PictureBox1.Size)
    Dim vly As VectorLayer = New VectorLayer("NAME_GOES_HERE", New SharpMap.Data.Providers.SqlServer2008(sConnString, "SBSTOPCD", "SHAPE", "OBJECTID", SharpMap.Data.Providers.SqlServerSpatialObjectType.Geography, False, 4326))
    vly.Style.EnableOutline = True
    vly.Style.Outline = Pens.Black
    vly.Style.Fill = Brushes.Red
    Dim i As Integer = vly.SRID
    Map.Layers.Add(vly)
    Map.ZoomToExtents()
    Map.BackColor = Color.White
    Try
        PictureBox1.Image = Map.GetMap()
    Catch e As Exception
        MsgBox(e.Message)
    End Try
it fails with : {"A .NET Framework error occurred during execution of user-defined routine or aggregate "geography":
System.FormatException: 24201: Latitude values must be between -90 and 90 degrees"

Does Sharmap work with geography data?
Are there any guides to working with Sharpmap in VB.net? Sharpmap looks great but an absence of documentation renders it mauch harder to use than it probably needs to be.
How do you install the Sharpmap zip file, can they go into any directory?
Coordinator
May 12, 2014 at 11:25 AM
Dim p as SharpMap.Data.Providers.SqlServer2008(
    sConnString, "SBSTOPCD", "SHAPE", "OBJECTID", 
    SharpMap.Data.Providers.SqlServerSpatialObjectType.Geography, False, 4326))

Dim e As GeoAPI.Geometries.Envelope = p.GetExtents()
What is the value of e?
Do you have other layers in the map?
Have you tried setting MaximumExtents and EnforceMaximumExtents?
May 12, 2014 at 11:41 PM
Thanks FObermaier

There are no other layers, this is the first time I have used the tool so I am just loading one layer and will experiment from there.

The GetExtents() method doesn't with the Geography type, however if I run a query in SQL Server
SELECT min(SHAPE.Lat), Max(SHAPE.Lat), Min(SHAPE.Long), Max( SHAPE.Long)
FROM [NewTest3].[dbo].[SBSTOPCD]

MinX MaxX MinY MaxY
-34.25896 -28.89525 113.82805 118.88087
Coordinator
May 13, 2014 at 7:03 AM
Edited May 13, 2014 at 7:04 AM
Try
Map.ZoomToBox(New GeoAPI.Geometries.Envelope(-34.25896, -28.89525, 113.82805, 118.88087))
May 13, 2014 at 10:41 AM
No, sorry it still returns the same error.
Coordinator
May 13, 2014 at 12:11 PM
Edited May 13, 2014 at 12:12 PM
Have you tried p.MakeValid = True?
Could you post the full stack trace?
May 15, 2014 at 8:18 AM
Sorry for the delay, here is the stack
{"A .NET Framework error occurred during execution of user-defined routine or aggregate "geography":
System.FormatException: 24201: Latitude values must be between -90 and 90 degrees.
System.FormatException:
at Microsoft.SqlServer.Types.GeographyValidator.ValidatePoint(Double x, Double y, Nullable1 z, Nullable1 m)
at Microsoft.SqlServer.Types.Validator.BeginFigure(Double x, Double y, Nullable1 z, Nullable1 m)
at Microsoft.SqlServer.Types.ForwardingGeoDataSink.BeginFigure(Double x, Double y, Nullable1 z, Nullable1 m)
at Microsoft.SqlServer.Types.CoordinateReversingGeoDataSink.BeginFigure(Double x, Double y, Nullable1 z, Nullable1 m)
at Microsoft.SqlServer.Types.WellKnownTextReader.ParseLineStringText()
at Microsoft.SqlServer.Types.WellKnownTextReader.ParsePolygonText()
at Microsoft.SqlServer.Types.WellKnownTextReader.ParseTaggedText(OpenGisType type)
at Microsoft.SqlServer.Types.WellKnownTextReader.Read(OpenGisType type, Int32 srid)
at Microsoft.SqlServer.Types.SqlGeography.GeographyFromText(OpenGisType type, SqlChars taggedText, Int32 srid)
."}
I was wondering if the geography data is reading te coordinates in a Lat, Long fashion rather than a Long(X), Lat(Y) fashion?

Cheers

David
Coordinator
May 15, 2014 at 9:43 AM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.