Getting spatial data from MSSQL problem

Topics: Data Access, Algorithms
Jul 4, 2007 at 8:52 AM
Hello,
I am very new in GIS and I have got a problem with getting spatial data from MSSQL, I am using the newest version of SharpMap.dll (compiled from source code), can anyone help me with this problem ? Do I make something wrong with this code ?!

the code:

try
{
string ConnStr = "Data Source=KULKA;Initial Catalog=spatial_geo4;Integrated Security=True";

SharpMap.Layers.VectorLayer layer = new SharpMap.Layers.VectorLayer("World");
SharpMap.Data.Providers.MsSql dataSource = new SharpMap.Data.Providers.MsSql(ConnStr, "World", "the_geom", "oid");
// In debug mode I can see that dataSource Columns throws following exception: The method or operation is not implemented. at //SharpMap.Data.Providers.MsSql.get_Columns()
dataSource.DefinitionQuery = String.Empty;

layer.DataSource = dataSource;
layer.Style.Line = new Pen(Color.White);
layer.Style.Outline = new Pen(Color.Brown);
layer.Style.EnableOutline = true;
layer.Style.Fill = Brushes.Green;
layer.Enabled = true;

map = new SharpMap.Map(this.pictureBox1.Size);
map.Layers.Add(layer);

//map.ZoomToExtents(); this line throws an exception !!!

map.GetMap().Save("World.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
this.pictureBox1.Image = map.GetMap();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}

The exception thrown by map.ZoomToExtents()
"Specified cast is not valid."
at SharpMap.Data.Providers.MsSql.GetExtents()
at SharpMap.Layers.VectorLayer.get_Envelope()
at SharpMap.Map.GetExtents()
at SharpMap.Map.ZoomToExtents()
at Shape2Pgsql.Form1.button1_Click(Object sender, EventArgs e) in D:\Documents and Settings\Maciej\Pulpit\GIS\Shape2Pgsq\Shape2Pgsql\Form1.cs:line 338


Regards,
Maciej Wrzesniowski
Jul 4, 2007 at 3:11 PM
ITS WORKS ! : )

I have changed Provider to MsSqlSpatial and the column names (again) in data base from 'EnvelopeMinX' to 'thegeomEnvelopeMinX'

SharpMap.Data.Providers.MsSqlSpatial dataSource = new SharpMap.Data.Providers.MsSqlSpatial(ConnStr, "World", "the_geom", "oid");

Regards,
Maciej W.




Jul 4, 2007 at 3:13 PM
IT WORKS ! :)
Jul 8, 2007 at 11:50 AM
When trying the above, i get a compilation error stating that type 'MsSqlSpatiol' does not exist. Also tried the latest RC 0.9.2241. But still nothing.