This project has moved and is read-only. For the latest updates, please go here.

To filter Data + SharpMap + MsSqlSpatial

Topics: General Topics
Jan 23, 2007 at 5:42 PM
When I execute this code, it's return me a green square

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Npgsql;
using SharpMap.Data.Providers;
using SharpMap.Layers;
using SharpMap.Geometries;

namespace Mapa
public partial class Form1 : Form
SharpMap.Data.Providers.MsSqlSpatial shp;
SharpMap.Map map;
public Form1()

private void btnMapa_Click(object sender, EventArgs e)
shp = new SharpMap.Data.Providers.MsSqlSpatial("Data Source=IBRA\\SQLEXPRESS;Initial Catalog=Shp;Integrated Security=True", "Mapas", "the_geom", "oid");
shp.GeometryExpression = "ST.MakeEnvelope(673017.490, 7181298.377, 673117.490, 7181398.377,-1)";
pictureBox1.Image = map.GetMap();

private void CriaMapa()
map = new SharpMap.Map(pictureBox1.Size);
SharpMap.Layers.VectorLayer layer = new SharpMap.Layers.VectorLayer("preview layer");
layer.DataSource = shp;
layer.Style.Line = new Pen(Color.Blue);
layer.Style.Outline = new Pen(Color.Black);
layer.Style.EnableOutline = true;
layer.Style.Fill = Brushes.Green;

If somebody has some sample, I thank

Ibraim Mansur
Jan 23, 2007 at 6:56 PM
Hi Ibraim,

Please try to run your sample without this line:
>> shp.GeometryExpression = "ST.MakeEnvelope(673017.490, 7181298.377, 673117.490, 7181398.377,-1)";

Jan 23, 2007 at 7:13 PM
Without this line it´s return the whole map.
I need to filter through these coordinates
Jan 23, 2007 at 7:22 PM

Okay, then use:

myMap..ZoomToBox(new SharpMap.Geometries.BoundingBox(10, 10, 100, 100));

Jan 24, 2007 at 10:49 AM
I'm trying to do something very similar to the OP - ie. trying to filter the data returned by MsSqlSpatial. I found that if I use, for example:

map.ZoomToBox(new SharpMap.Geometries.BoundingBox(311667.753574452, 168321.2111899, 312732.700916047, 168900.648377004));

Even though the image is actually produced and saved by my Web application, and it shows the correct area (in beautiful quality, I might add!), I get a timeout error from the actual webpage. Ie.

"Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding."

The stacktrace shows:

"SqlException (0x80131904): Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.
System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) +857242
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +734854
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +188
System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +1838
System.Data.SqlClient.SqlDataReader.ConsumeMetaData() +31
System.Data.SqlClient.SqlDataReader.get_MetaData() +62
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) +886
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) +132
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) +32
System.Data.SqlClient.SqlCommand.ExecuteScalar() +137
SharpMap.Data.Providers.MsSqlSpatial.GetExtents() +220
SharpMap.Layers.VectorLayer.get_Envelope() +43
SharpMap.Map.GetExtents() +76
SharpMapTest.Test.Page_Load(Object sender, EventArgs e) +1242
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +15
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +34
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +47
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1061"

Now this is weird as the image is produced and saved to the temporary directory in around a second or so, yet the application appears to be still working and times out.

If I remove the MsSqlSpatial layer from the application, ie. leaving just layers from SHP files, there is no problem and it doesn't timeout.

Any ideas as to what's going on here?