How to load data from dbf file and display on mouse click

Topics: Data Access, General Topics, SharpMap Project, SharpMap v0.9 / v1.x, SharpMap v2.0, Web Controls
Jan 28, 2011 at 5:07 AM
I got shp files and associated dbf (dBASE 5.0) files containing data.
In my web application I need to load these details and display query info on a mouse click of the map.

My web application is ASP.net/C# based
My files are sets like abc.shp, abc.dbf, abc.shx

1. How can I load the data to MyLayer?

SharpMap.Layers.VectorLayer layer1 = new SharpMap.Layers.VectorLayer("MyLayer");
string connStr = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=" + @"~\SharpMapTest\App_Data" + ";Extended Properties=dBASE 5.0";
layer1.DataSource = new SharpMap.Data.Providers.//... (what's next here?)

or

If I load the shp like below, how can I get the data from the associated dbf?

layer1.DataSource = new SharpMap.Data.Providers.ShapeFile(Server.MapPath(@"~\App_data\abc.shp"), true);

2. How to display data on a mouse click?

I am using asp:ImageButton (called imgMap as in the example)  to display the map.

Current Code:
 

protected void imgMap_Click(object sender, ImageClickEventArgs e)
{
  //Set center of the map to where the client clicked
        ((SharpMap.Map)Session["myMap"]).Center = SharpMap.Utilities.Transform.MapToWorld(new System.Drawing.Point(e.X, e.Y), ((SharpMap.Map)Session["myMap"]));
  //Set zoom value if any of the zoom tools were selected
  if (rblMapTools.SelectedValue == "0") //Zoom in
            ((SharpMap.Map)Session["myMap"]).Zoom = ((SharpMap.Map)Session["myMap"]).Zoom * 0.5;
        else if (rblMapTools.SelectedValue == "1") //Zoom out
            ((SharpMap.Map)Session["myMap"]).Zoom = ((SharpMap.Map)Session["myMap"]).Zoom * 2;
        else if (rblMapTools.SelectedValue == "3") //Query
{
//What's the code here???
}
        //Save the new map's zoom and center in the viewstate
        ViewState.Add("mapCenter", ((SharpMap.Map)Session["myMap"]).Center);
        ViewState.Add("mapZoom", ((SharpMap.Map)Session["myMap"]).Zoom);
  //Create the map
  CreateMap();
}

Coordinator
Jan 28, 2011 at 8:45 AM

Hello Chinthaka,

  1. To add a layer to the map, you must use the ShapeFile provider.
    To query for data in the associated dbase file, you must perform ExecuteIntersectionQuery(..., ...) on the ShapeFile Provider.
    If you want to change appearance of your layer based on attribute data, you must apply a Theme to your layer.
  2. I cannot help you with this, but I'm sure others can.

Hth FObermaier