VB.NET winforms and data

Nov 19, 2015 at 12:21 PM
Hi ! I've been trying to add data to my map for 3 days now and it still not working. I read, download sample, tried c# with no success... I now need your help.

I am able to add a shapefile layer. But as soon as I try to add a sqlserver2008 or a Datatable point, the map turn blank.

DataPoints :
Dim layFeux As SharpMap.Layers.VectorLayer = New SharpMap.Layers.VectorLayer("Feux")
layFeux.DataSource = New SharpMap.Data.Providers.DataTablePoint(mytable, "OBJECTID", "X", "Y")
layFeux.SRID = 32198 (or what ever value I put here)

Dim pps = SharpMap.Rendering.Symbolizer.PathPointSymbolizer.CreateSquare(New System.Drawing.Pen(System.Drawing.Color.Red, 2), New System.Drawing.SolidBrush(System.Drawing.Color.DodgerBlue), 20)
layFeux.Style.PointSymbolizer = pps


SQLServer2008 :
Dim myLayer As SharpMap.Layers.VectorLayer = New SharpMap.Layers.VectorLayer("DI")
Dim ConnStr As String = "Server=esrisde\esri_sde;Database=SDE;User Id=xxx;Password=yyy"
Dim d As SharpMap.Data.Providers.SqlServer2008 = New SharpMap.Data.Providers.SqlServer2008(ConnStr, "DI", "SHAPE", "OBJECTID", SharpMap.Data.Providers.SqlServerSpatialObjectType.Geometry)
Dim e As GeoAPI.Geometries.Envelope = d.GetExtents

myLayer.DataSource = d

The layer either exists in geography and geometry. Tried both (adjusting parameters of course). It always returning me the correct number of records and map extents (for geometry).

I really want this piece of code working.

Au secours !!!!!!!!!! Thanks :-)
Nov 19, 2015 at 12:52 PM
Ohhh... I got it work for the SQL geometry... :-) but I still have one question regarding layer CoordinateTransformation. If my sql geometry is 32198 and that I want to overlay my data with OSM, what will I have to do ??

Thanks again !
Nov 19, 2015 at 1:25 PM
Well, I guess I had to wrote it down to make everything working :-O. Still have a little issue with data table point but I'll work on it !!
Nov 19, 2015 at 5:43 PM
Edited Nov 19, 2015 at 7:21 PM
How Do I change my DI table to spReadFD that retreive the same info, but using a strored procedure ??
Nov 19, 2015 at 7:22 PM
Any help would be appreciated !! :-)
Nov 20, 2015 at 12:15 PM
If your stored procedure does not take any arguments all you need to do is replace the name of the table with the name of the stored procedure.
Nov 20, 2015 at 2:49 PM
Edited Nov 20, 2015 at 3:39 PM
Thanks for you help... Will I have to change the provider I'm using ?? Cause this won't work...

Dim ConnStr As String = "Server=esri-sql\esri_sde;Database=SIIF;Integrated Security=SSPI;Trusted_Connection=yes"
Dim d As SharpMap.Data.Providers.SqlServer2008 = New SharpMap.Data.Providers.SqlServer2008(ConnStr, "spLireAffichageDanger", "SHAPE", "OBJECTID", SharpMap.Data.Providers.SqlServerSpatialObjectType.Geometry)

Make it working would be really nice !!
Nov 20, 2015 at 6:50 PM
Is the procedure in dbo schema or someplace else?
Nov 20, 2015 at 6:54 PM
It is in the dbo schema with a grant access to public.
Nov 21, 2015 at 11:14 AM
Have you tried adding open and close brackets to indicate it is a stored procedure?
Try to configure logging and look for the SQL passed to the DB.
Nov 23, 2015 at 12:37 PM
Unfortunatly, adding brakets didn't help. I always have an error telling me Invalid object name spLireAffichageDanger even tough I know that the sp exists and run ok in sql. And for double check, I called the SP in my ,net project using a sql command.

.net results using as sql command (objectID field, shape and so on):
50 01 Matagami
25 02 La Sarre-Amos
48 03 Quévillon-Waswanipi
24 04 Rouyn-Noranda

SQL results :

50 01 Matagami 0xC67D00000104B6540000C05B2041D4E120C1E0........ 1
25 02 La Sarre-Amos 0xC67D000001040A000000407502BA063924C1A00F7AD... 2
48 03 Quévillon-Waswanipi 0xC67D000001040C0000004074243793B422C1....... 2

I've been able to walk around the problem by creating a temp sql geometry table poputated by another stored procedure (similar to splireAffichageDanger).

Thanks !
Nov 24, 2015 at 7:15 AM
Edited Nov 24, 2015 at 7:26 AM
It seems that
  • stored procedures are not called using SELECT ...; but simply pass the name of the procedure to call.
  • one has to set SqlCommand.CommandType = CommandType.StoredProcedure.
The current implementation does not do that.
Feel free to file an issue.
Dec 14, 2015 at 10:43 AM
Hi amdavid!

I've got the same basic problem:

How to load data from sqlserver??
You've solved your problem, could you pleas share your solution.

I'm doing the following:
 Dim connstr As String = "Server=DELL-4-2015\SQLEXPRESS12; Database=XYZ; User Id=USERNAME;Password=PASSWORD;"

        Dim vlay As New Layers.VectorLayer("PLZ")
              Dim d As New SharpMap.Data.Providers.SqlServer2008(connstr, "PLZGEometry", "geom", "PLZ_ID", SharpMap.Data.Providers.SqlServerSpatialObjectType.Geography, False, 4326)
        d.SRID = 4326 'I know this should be obsolete as it is already set

        MsgBox(d.GeometryColumn) 'Shows the right geometry column
        MsgBox(d.SRID) 'SHows the right SRID

        vlay.DataSource = d

        MsgBox(d.GetFeatureCount()) 'Shows the correct number of elements

        CoordTransWGS(vlay) 'uses a function to transform to web-mercator


But nothing is shown on the map.
I don't know where I am going wrong!

Dec 15, 2015 at 5:33 AM
Edited Dec 15, 2015 at 5:34 AM
Are you sure the viewport is correct?
Try calling MapBox1.Map.ZoomToExtents(); prior to calling MapBox1.Refresh();.