How to display shapefiles in a web application from sql server 2008 using SharpMap

Topics: Developer Forum, User Forum
Dec 21, 2010 at 1:27 PM

Hi all, I've been trying to display shapefiles in my web application using sharpmap but i keep getting  errors, I was able to correct all except for this one..

Invalid object name 'ST.FilterQuery#dbo#Premier_Towers_Area#GEOCOLUMN'.

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: Invalid object name 'ST.FilterQuery#dbo#Premier_Towers_Area#GEOCOLUMN'.

Source Error:

Line 294:                {
Line 295: conn.Open();
Line 296: using (SqlDataReader dr = command.ExecuteReader())
Line 297: {
Line 298: while (dr.Read())


Source File: D:\SharpMap-78963\Trunk\SharpMap\Data\Providers\MsSqlSpatial.cs    Line: 296

Stack Trace:

[SqlException (0x80131904): Invalid object name 'ST.FilterQuery#dbo#Premier_Towers_Area#GEOCOLUMN'.]
System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) +1951450
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +4849003
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +194
System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +2394
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.ExecuteReader() +89
SharpMap.Data.Providers.MsSqlSpatial.GetGeometriesInView(BoundingBox bbox) in D:\SharpMap-78963\Trunk\SharpMap\Data\Providers\MsSqlSpatial.cs:296
SharpMap.Layers.VectorLayer.Render(Graphics g, Map map) in D:\SharpMap-78963\Trunk\SharpMap\Layers\VectorLayer.cs:282
SharpMap.Map.RenderMap(Graphics g) in D:\SharpMap-78963\Trunk\SharpMap\Map\Map.cs:207
SharpMap.Map.GetMap() in D:\SharpMap-78963\Trunk\SharpMap\Map\Map.cs:162
Sqlversion._Default.Page_Load(Object sender, EventArgs e) in C:\Users\Kwame\Documents\Visual Studio 2008\Projects\Sqlversion\Sqlversion\Default.aspx.cs:43
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

Please I need help urgently..

Dec 21, 2010 at 1:31 PM

These are the codes I'm using...

 

namespace Sqlversion
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            SharpMap.Map myMap = new SharpMap.Map(new Size(400, 300));
            myMap.Size = new System.Drawing.Size(300, 200); //Set output size

            myMap.MinimumZoom = 100; //Minimum zoom allowed
            myMap.BackColor = Color.White; //Set background
            myMap.Center = new SharpMap.Geometries.Point(3100000, 1100000); //Set center of map

            string ConnStr = "Data Source=KWAME-PC;Initial Catalog=spatial; User ID=webapp;Password=webapp;";
            SharpMap.Layers.VectorLayer myLayer = new SharpMap.Layers.VectorLayer("GEOTABLE");
            myLayer.DataSource = new SharpMap.Data.Providers.MsSqlSpatial(ConnStr, "Premier_Towers_Area", "GEOCOLUMN", "oid");
            myLayer.MaxVisible = 40000;
            myMap.Layers.Add(myLayer);
            System.Drawing.Image imgMap = myMap.GetMap();

          
        }
    }
}

Dec 21, 2010 at 3:21 PM

I'm using mssql 2008 and the sqlspatialtools to export my shapefiles into my database...

Aug 19, 2011 at 3:44 AM

Hi, did you solve it ? Thanks a lot!

Dec 12, 2011 at 12:09 PM

Hi!

Check your uploadad shape file format.

- Your geometry column is a geometry type column not a geography,

- all the records are valid geometry //UPDATE your_table_name SET geom = geom.MakeValid()

- do you have boundary columns? e.g.: envelope_MinX... If yo do not, the sharpmap cannot render the layer

 

A had the same problem, and  I used the MsSql.cs CreateDatabase(string shapeFile) method to upload shapefiles to Sql Server and used MsSql class ro render vector layer instead of MsSqlSpatial. It solved the problem. But it makes an image type column from the geometry.

It will be good for sharpmap, but if you would like to make spatial query-s, you have to convert it to geometry type.