Null Exception Error With NTS Provider

Topics: Data Access, Algorithms, SharpMap v0.9 / v1.x
Dec 26, 2007 at 12:05 PM
Hello
I ahve been working with nts provide to get the data on click from shape file.
All is working fine with shapefile A.shp.
Problem is when i change the shape file refernece of datasource from File A.shp to B.shp i get a System.nullRefernce Exception.
But i file use the same file B.shp without the nts provider and in the ExecuteIntersectionQuery method instead of passing the point as argument i am passing the boundingbox then i get the output but they r multiple in no.
Pls Help me
Code is

public static string Punto(SharpMap.Geometries.Point punto)
{
//System.Web.UI.Page.CreateHtmlTextWriterFromType(Response.write("<script type='text/javascript'>alert('hel')</script>");
SharpMap.Map map = new SharpMap.Map(new System.Drawing.Size(10, 10));

//Set up the countries layer
SharpMap.Layers.VectorLayer layCities = new SharpMap.Layers.VectorLayer("Cities");
//Set the datasource to a shapefile in the App_data folder
layCities.DataSource = new SharpMap.Data.Providers.ShapeFile(HttpContext.Current.Server.MapPath(@"~\App_data\PlotsHT.shp"), true);

//layer nts buffer
NtsProvider nts = new NtsProvider(layCities.DataSource, delegate(List<GisSharpBlog.NetTopologySuite.Features.Feature> features)
{
foreach (GisSharpBlog.NetTopologySuite.Features.Feature feature in features)
feature.Geometry = feature.Geometry.Buffer(0.5);
});
SharpMap.Layers.VectorLayer layNts = new SharpMap.Layers.VectorLayer("Buffers");
layNts.DataSource = nts;
layNts.Style.Fill = new System.Drawing.SolidBrush(System.Drawing.Color.LightBlue);

map.Layers.Add(layNts);
//
map.Layers.Add(layCities);

//SharpMap.Geometries.Point ClickPnt = new SharpMap.Geometries.Point(Convert.ToDouble(Request.QueryString"pntx".ToString()), Convert.ToDouble(Request.QueryString"pnty".ToString()));
SharpMap.Data.FeatureDataSet ds = new SharpMap.Data.FeatureDataSet();
//Execute click-query on first layer in layers collection
//SharpMap.Geometries.BoundingBox bx = new SharpMap.Geometries.BoundingBox(Convert.ToDouble(Request.QueryString"pntx".ToString()), Convert.ToDouble(Request.QueryString"pnty".ToString()), Convert.ToDouble(Request.QueryString"pntx".ToString()) + 1, Convert.ToDouble(Request.QueryString"pnty".ToString()) + 1);
SharpMap.Geometries.BoundingBox bx = punto.GetBoundingBox();
(map.Layers0 as SharpMap.Layers.VectorLayer).DataSource.Open();
(map.Layers0 as SharpMap.Layers.VectorLayer).DataSource.ExecuteIntersectionQuery(punto, ds);

(map.Layers0 as SharpMap.Layers.VectorLayer).DataSource.Close();
StringBuilder str = new StringBuilder();
if (ds.Tables.Count > 0) {
string mapno;
int wardno;

DataTable dt = ds.Tables0;
foreach (DataRow r in dt.Rows) {
str.Append(r"objectid".ToString()) ;


}

}

return (str.ToString());
}

}

Regards
Nishant Jain
Mar 16, 2008 at 10:54 PM
have u solve it ? i have the same problem and cant figure out how to solve it
Mar 20, 2008 at 2:13 AM

Problem is when i change the shape file refernece of datasource from File A.shp to B.shp i get a System.nullRefernce Exception.
But i file use the same file B.shp without the nts provider and in the ExecuteIntersectionQuery method instead of passing the point as argument i am passing the boundingbox then i get the output but they r multiple in no.


You get a null reference on what exactly? What does the callstack look like?