How to create a theme in SharpMap for the data that are added from SQL server 2008??

Jan 8, 2010 at 2:29 PM

Hi.  Im tying to create a theme with SharpMap for some data that i added from sql server 2008

i've used this code :

 private SharpMap.Map InitializeMap(System.Drawing.Size outputsize)
  {
  SharpMap.Map map = new SharpMap.Map(outputsize);
  string ConnStr = @"Server=OFFICE\SPATIALSERVER;Database=TOWNS;Trusted_Connection=True";
  SharpMap.Layers.VectorLayer layTOWN = new SharpMap.Layers.VectorLayer("TOWN");
  layTOWN.DataSource = new SharpMap.Data.Providers.SqlServer2008(ConnStr, "dbo.TOWNS_POLY", "geom","ID");
  layTOWN.MaxVisible = 4000000;
  layTOWN.Style.Fill = new SolidBrush(Color.CornflowerBlue);
  layTOWN.Style.Outline = System.Drawing.Pens.Black;
  layTOWN.Style.EnableOutline = true;
  layTOWN.Style.Line.StartCap = System.Drawing.Drawing2D.LineCap.ArrowAnchor;
  layTOWN.Style.Line.EndCap = System.Drawing.Drawing2D.LineCap.Round;
  map.Layers.Add(layTOWN);

  SharpMap.Rendering.Thematics.CustomTheme myTheme = new SharpMap.Rendering.Thematics.CustomTheme(GetTOWNStyle);
  layTOWN.Theme = myTheme;  


  return map;
  }
  private SharpMap.Styles.VectorStyle GetTOWNStyle(SharpMap.Data.FeatureDataRow row)
  {
  SharpMap.Styles.VectorStyle style = new SharpMap.Styles.VectorStyle();
  switch (row["TOWN"].ToString().ToLower())
  {
  case "BOSTON": 
  style.Fill = Brushes.Green;
  return style;
  case "BARNSTABLE":
  style.Fill = Brushes.Blue;
  style.Outline = Pens.Red;
  return style;
  case "ESSEX": 
  style.Fill = Brushes.Red;
  return style;
  default:
  break;
  }
   
  if (row["ISLAND"].ToString().StartsWith("1"))
  {
  style.Fill = Brushes.Yellow;
  return style;
  }
   
  if (row.Geometry.GetType() == typeof(SharpMap.Geometries.MultiPolygon) &&
  (row.Geometry as SharpMap.Geometries.MultiPolygon).Area < 300000 ||
  row.Geometry.GetType() == typeof(SharpMap.Geometries.Polygon) &&
  (row.Geometry as SharpMap.Geometries.Polygon).Area < 300000)
  {
  style.Fill = Brushes.Cyan;
  return style;
  }
  else
  return null;
  }

 ---

 

In fact this code works well when i  added data with postGIS but when I use sql server 2008 it doesn't work and this is what i tells:

"Could not find method 'Get_WKB' for type 'Microsoft.SqlServer.Types.SqlGeometry' in assembly 'Microsoft.SqlServer.Types' "

Can any body help me with this????

I'm a beginner in sharpmap and i wanted to know if it is a way to create a theme for the data that are added from ms sql server 2008.

 

Coordinator
Jan 8, 2010 at 2:57 PM

Hello gentiqirjazi,

look for .Get_WKB() in SqlServer2008.cs and replace that with .STAsBinary().

If you did not change anything in the provider, it should be somewhere
around line 545.

Note: In the GetTOWNStyle function you switch for lowercase townnames
but the branches are all uppercase.

Hth

FObermaier

Jan 8, 2010 at 3:16 PM

Hello FObermaier

It tells the same thing again

"Could not find method 'Get_WKB' for type 'Microsoft.SqlServer.Types.SqlGeometry' in assembly 'Microsoft.SqlServer.Types' "

I changed every thing you tell me but it is the same

Thank you.

Coordinator
Jan 8, 2010 at 5:38 PM

If your app is not in the same solution as sharpmap, you might need to update your references.
Otherwise try rebuild all. Since there is only one occurence of .Get_WKB() in SqlServer2008.cs,
you cannot get this error if all went well.

Are you using the latest revision from the repository?

Hth FObermaier

Jan 9, 2010 at 12:13 PM

hello fobermaier

I'm using SharpMap 0.9

Could it be it ??

SQL server works with all versions of sharp map or only whith v2.0??

Thanks.

Coordinator
Jan 9, 2010 at 1:11 PM

It should work with either version of sharpmap. I suppose there is something wrong with the way you setup your project.

BTW, do you compile sharpmap yourself or do you use the released binaries. It is strongly suggested to compile sharpmap
locally.

Hth FObermaier

 

Jan 9, 2010 at 1:42 PM

Coul you be more specific please,,

You are saying that i have to modify the souce codes that i've download from sharpmap or just that to create my own project and not the demo form that comes with the download because:

I' ve created a folder with all sharp map components (which I have download from this wesite) and created a web project with this folder. I didn't use the demoform(i've just use just the SharpMap folder in the downloaded folder)

It work very good with PostGIS

And with sql server works good when I open it without creating themes. The problem consist in theme creation.

 

PS:

The downloaded folder(from SharpMap website) contains this folders:

DemoWebSite

DemoWinForm

ExternalReferences

SharpMap

SharpMap.AltRenderers.VS2008

SharpMap.Extensions

SharpMap.Presentation.AspNet

SharpMap.Presentation.AspNet.Demo

SharpMap.Presentation.AspNet.WmsServer

SharpMap.UI

UnitTest

WinFormSamples

 

I used for my project SharpMap and Sharpmap.Extensions

 

Coordinator
Jan 9, 2010 at 5:22 PM

hi gentigirjazi, the folder structure you detailed above is from v2 and is incompatible with 0.9.

You need the code from the trunk  @ codeplex not googlecode.

 

hth jd

Coordinator
Jan 10, 2010 at 12:28 PM

The structure you posted is from 1.1experimental branch (not from v2). That branch does not contain SqlServer2008.cs, so the question arises where you took it from.

In case you took it from the patches section, you may find more than one occurence of .Get_WKB() which you certainly have to change as well.

Hth FObermaier

Coordinator
Jan 10, 2010 at 12:39 PM

good catch fobermaier ;)

Jan 11, 2010 at 3:30 PM

Hi This is my error

Could not find method 'Get_WKB' for type 'Microsoft.SqlServer.Types.SqlGeometry' in assembly 'Microsoft.SqlServer.Types'

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

 

Exception Details: System.Data.SqlClient.SqlException: Could not find method 'Get_WKB' for type 'Microsoft.SqlServer.Types.SqlGeometry' in assembly 'Microsoft.SqlServer.Types'

 

Source Error:

 

Line 111: private void CreateMap()

Line 112: {

Line 113: System.Drawing.Image img = myMap.GetMap();

Line 114: string imgID = SharpMap.Web.Caching.InsertIntoCache(1, img);

Line 115: imgMap.ImageUrl = "getmap.aspx?ID=" + HttpUtility.UrlEncode(imgID);

 

 

Source File: c:\Documents and Settings\Administrator.EC012287AF3A40B\Desktop\SHar\Trunk\SharpMap\Default.aspx.cs Line: 113

 

Stack Trace:

 

[SqlException (0x80131904): Could not find method 'Get_WKB' for type 'Microsoft.SqlServer.Types.SqlGeometry' in assembly 'Microsoft.SqlServer.Types']

System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) +1948826

System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +4844747

System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +194

System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +2392

System.Data.SqlClient.SqlDataReader.ConsumeMetaData() +33

System.Data.SqlClient.SqlDataReader.get_MetaData() +83

System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +297

System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) +954

System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) +162

System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) +32

System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method) +141

System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior) +12

System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior) +10

System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +130

System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +287

System.Data.Common.DbDataAdapter.Fill(DataSet dataSet) +94

SharpMap.Data.Providers.SqlServer2008.ExecuteIntersectionQuery(BoundingBox bbox, FeatureDataSet ds) in C:\Users\GENTI\Documents\sharpmap-62005\Trunk\SharpMap\Data\Providers\SqlServer2008.cs:557

SharpMap.Layers.VectorLayer.Render(Graphics g, Map map) in C:\Users\GENTI\Documents\sharpmap-62005\Trunk\SharpMap\Layers\VectorLayer.cs:214

SharpMap.Map.GetMap() in C:\Users\GENTI\Documents\sharpmap-62005\Trunk\SharpMap\Map\Map.cs:171

_Default.CreateMap() in c:\Documents and Settings\Administrator.EC012287AF3A40B\Desktop\SHar\Trunk\SharpMap\Default.aspx.cs:113

_Default.Page_Load(Object sender, EventArgs e) in c:\Documents and Settings\Administrator.EC012287AF3A40B\Desktop\SHar\Trunk\SharpMap\Default.aspx.cs:31

System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14

System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35

System.Web.UI.Control.OnLoad(EventArgs e) +99

System.Web.UI.Control.LoadRecursive() +50

System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627

 

Coordinator
Jan 11, 2010 at 3:38 PM

Hi gentigirjazi that is an error in the code.. it should be STAsBinary(). It is corrected in the trunk.. get latest and try again.. hth jd

Jan 12, 2010 at 1:52 PM

I downloaded the code that has STAsBinary(). but the problem still remain.

 

Jan 12, 2010 at 1:53 PM

BTW  How could I create a filter in sharp map when im using SQL Server 2008 data?????

 

Coordinator
Jan 12, 2010 at 2:28 PM

provider.DefinitionQuery = "color ='red'"

hth jd

Jan 12, 2010 at 2:34 PM

Culd you be more specific please

I have some difficulties in understanding that.

 

Thank you

Jan 12, 2010 at 3:35 PM

Finally with the newer version  that i downloaded the ERROR: Could not find method 'Get_WKB' for type 'Microsoft.SqlServer.Types.SqlGeometry' in assembly 'Microsoft.SqlServer.Types' DIDN'T HAPPENED AGAIN

THANKS

but ....................I've another problem coul you help me with that :

 

Object reference not set to an instance of an object.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

 

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

 

Source Error:

 

Line 307: {

Line 308: case "SharpMap.Geometries.Polygon":

Line 309: if (style.EnableOutline)

Line 310: VectorRenderer.DrawPolygon(g, (Polygon) feature, style.Fill, style.Outline, _ClippingEnabled,

Line 311: map);

 

 

Source File: C:\Documents and Settings\Administrator.EC012287AF3A40B\Desktop\genti\Trunk\SharpMap\Layers\VectorLayer.cs Line: 309

 

Stack Trace:

 

[NullReferenceException: Object reference not set to an instance of an object.]

SharpMap.Layers.VectorLayer.RenderGeometry(Graphics g, Map map, Geometry feature, VectorStyle style) in C:\Documents and Settings\Administrator.EC012287AF3A40B\Desktop\genti\Trunk\SharpMap\Layers\VectorLayer.cs:309

SharpMap.Layers.VectorLayer.Render(Graphics g, Map map) in C:\Documents and Settings\Administrator.EC012287AF3A40B\Desktop\genti\Trunk\SharpMap\Layers\VectorLayer.cs:255

SharpMap.Map.GetMap() in C:\Documents and Settings\Administrator.EC012287AF3A40B\Desktop\genti\Trunk\SharpMap\Map\Map.cs:171

_Default.CreateMap() in c:\Documents and Settings\Administrator.EC012287AF3A40B\Desktop\genti\Trunk\SharpMap\Default.aspx.cs:111

_Default.Page_Load(Object sender, EventArgs e) in c:\Documents and Settings\Administrator.EC012287AF3A40B\Desktop\genti\Trunk\SharpMap\Default.aspx.cs:32

System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14

System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35

System.Web.UI.Control.OnLoad(EventArgs e) +99

System.Web.UI.Control.LoadRecursive() +50

System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627

 

THANK YOU

 

Jan 12, 2010 at 4:48 PM

I finally reached my scope i ended and it went all right

This last error was just a stupid error maded by me.

 

THANK YOU VERY MUCH FOR YOUR CONSULTINGS AND HELP