Highlight selected feature

Topics: SharpMap Project, Web Controls
Apr 7, 2008 at 3:54 AM
When I click a polygon on a map I would like it to highlight to a specific color.
Apr 9, 2008 at 2:41 AM
Edited Apr 9, 2008 at 2:45 AM

SharpMap.Data.FeatureDataSet ds = new SharpMap.Data.FeatureDataSet();
SharpMap.Layers.VectorLayer layer = (SharpMap.Layers.VectorLayer)map.Layers0; //layers0 is current display layer
layer.DataSource.Open();
layer.DataSource.ExecuteIntersectionQuery(WorldPos.GetBoundingBox(), ds); //because I wrote this code in event "MapImage_MouseMove" so use WorldPos
//if selected any object
if (ds.Tables0.Rows.Count > 0)
{
//create the selected layer
SharpMap.Layers.VectorLayer laySelected = new SharpMap.Layers.VectorLayer("Selection");
laySelected.DataSource = new SharpMap.Data.Providers.GeometryProvider(ds.Tables0);
laySelected.Style.Fill = new System.Drawing.SolidBrush(SystemColor.Hightlight);

map.Layers.Add(laySelected); //map is a gloabal variable which type is "Map"
}


//maybe help u.

Apr 18, 2008 at 2:15 AM
Hello rouser

Thanks for the reply. Your code will change the color of everything on a layer. I am looking for code to change only the color of a selected (clicked) polygon. For example: user clicks polygon number 2 amongst 3 polygons on the map. Only polygon 2 turns red. User then clicks polygon 1. Only polygon 1 turns red, the others revert back to their default color. In short: a simple feedback mechanism to show the user what he has just clicked.

Chris



rouser wrote:

SharpMap.Data.FeatureDataSet ds = new SharpMap.Data.FeatureDataSet();
SharpMap.Layers.VectorLayer layer = (SharpMap.Layers.VectorLayer)map.Layers0; //layers0 is current display layer
layer.DataSource.Open();
layer.DataSource.ExecuteIntersectionQuery(WorldPos.GetBoundingBox(), ds); //because I wrote this code in event "MapImage_MouseMove" so use WorldPos
//if selected any object
if (ds.Tables0.Rows.Count > 0)
{
//create the selected layer
SharpMap.Layers.VectorLayer laySelected = new SharpMap.Layers.VectorLayer("Selection");
laySelected.DataSource = new SharpMap.Data.Providers.GeometryProvider(ds.Tables0);
laySelected.Style.Fill = new System.Drawing.SolidBrush(SystemColor.Hightlight);

map.Layers.Add(laySelected); //map is a gloabal variable which type is "Map"
}


//maybe help u.



Developer
Apr 19, 2008 at 5:16 AM
hi mc OZ
You can use function follow to choose a geometry when you click mouse on map. After that You can add this geometry like as a layer of map with a pecific color or draw it in Paint method of Window form.
<code>
public SharpMap.Data.FeatureDataRow FindGeoNearPoint(SharpMap.Geometries.Point pos, SharpMap.Layers.VectorLayer layer,double amountGrow)
{
SharpMap.Geometries.BoundingBox bbox = pos.GetBoundingBox().Grow(amountGrow);
SharpMap.Data.FeatureDataSet ds = new SharpMap.Data.FeatureDataSet();
layer.DataSource.ExecuteIntersectionQuery(bbox, ds);
DataTable tbl = ds.Tables0 as SharpMap.Data.FeatureDataTable;
GisSharpBlog.NetTopologySuite.IO.WKTReader reader = new GisSharpBlog.NetTopologySuite.IO.WKTReader();
GeoAPI.Geometries.IGeometry point = reader.Read(pos.ToString());
if (tbl.Rows.Count == 0)
return null;

double distance = point.Distance(reader.Read((tbl.Rows0 as SharpMap.Data.FeatureDataRow).Geometry.ToString()));
SharpMap.Data.FeatureDataRow selectedFeature = tbl.Rows0 as SharpMap.Data.FeatureDataRow;

if (tbl.Rows.Count > 1)
for (int i = 1; i < tbl.Rows.Count; i++)
{
GeoAPI.Geometries.IGeometry line = reader.Read((tbl.Rowsi as SharpMap.Data.FeatureDataRow).Geometry.ToString());
if (point.Distance(line) < distance)
{
distance = point.Distance(line);
selectedFeature = tbl.Rowsi as SharpMap.Data.FeatureDataRow;
}
}
return selectedFeature;
}
</code>
pos: position click mouse on map
layer: layer click
amountGrow: area need grow surround pos. ( about 50 pixel)
Now You can draw geometry in datarow :
<code>
SharpMap.Data.FeatureDataRow rowSelected=FindGeoNearPoint( pointClick, layerSelected,50);
//create the selected layer
SharpMap.Layers.VectorLayer laySelected = new SharpMap.Layers.VectorLayer("Selection");
laySelected.DataSource = new SharpMap.Data.Providers.GeometryProvider(rowSelected.Geomertry);
laySelected.Style.Fill = new System.Drawing.SolidBrush(SystemColor.Hightlight);

map.Layers.Add(laySelected); //map is a gloabal variable which type is "Map"
</code>
Note:You need add preference : GeoAPI.dll and NetTopologySuite.dll
May be help you!
Apr 21, 2008 at 1:28 AM
trieuvy

Many thanks for your sample. I am eager to implement it but my knowledge of C is insufficient for me to translate it to VB. Would you be able to post a VB version of this?

Cheers
Chris



trieuvy wrote:
hi mc OZ
You can use function follow to choose a geometry when you click mouse on map. After that You can add this geometry like as a layer of map with a pecific color or draw it in Paint method of Window form.
<code>
public SharpMap.Data.FeatureDataRow FindGeoNearPoint(SharpMap.Geometries.Point pos, SharpMap.Layers.VectorLayer layer,double amountGrow)
{
SharpMap.Geometries.BoundingBox bbox = pos.GetBoundingBox().Grow(amountGrow);
SharpMap.Data.FeatureDataSet ds = new SharpMap.Data.FeatureDataSet();
layer.DataSource.ExecuteIntersectionQuery(bbox, ds);
DataTable tbl = ds.Tables0 as SharpMap.Data.FeatureDataTable;
GisSharpBlog.NetTopologySuite.IO.WKTReader reader = new GisSharpBlog.NetTopologySuite.IO.WKTReader();
GeoAPI.Geometries.IGeometry point = reader.Read(pos.ToString());
if (tbl.Rows.Count == 0)
return null;

double distance = point.Distance(reader.Read((tbl.Rows0 as SharpMap.Data.FeatureDataRow).Geometry.ToString()));
SharpMap.Data.FeatureDataRow selectedFeature = tbl.Rows0 as SharpMap.Data.FeatureDataRow;

if (tbl.Rows.Count > 1)
for (int i = 1; i < tbl.Rows.Count; i++)
{
GeoAPI.Geometries.IGeometry line = reader.Read((tbl.Rowsi as SharpMap.Data.FeatureDataRow).Geometry.ToString());
if (point.Distance(line) < distance)
{
distance = point.Distance(line);
selectedFeature = tbl.Rowsi as SharpMap.Data.FeatureDataRow;
}
}
return selectedFeature;
}
</code>
pos: position click mouse on map
layer: layer click
amountGrow: area need grow surround pos. ( about 50 pixel)
Now You can draw geometry in datarow :
<code>
SharpMap.Data.FeatureDataRow rowSelected=FindGeoNearPoint( pointClick, layerSelected,50);
//create the selected layer
SharpMap.Layers.VectorLayer laySelected = new SharpMap.Layers.VectorLayer("Selection");
laySelected.DataSource = new SharpMap.Data.Providers.GeometryProvider(rowSelected.Geomertry);
laySelected.Style.Fill = new System.Drawing.SolidBrush(SystemColor.Hightlight);

map.Layers.Add(laySelected); //map is a gloabal variable which type is "Map"
</code>
Note:You need add preference : GeoAPI.dll and NetTopologySuite.dll
May be help you!

Developer
Apr 21, 2008 at 2:31 AM
HI mc oz !
I think You can convert C# to VB.Net easyly.(Ex : You can have www.google.com helped.:D)
Developer
Apr 21, 2008 at 2:36 AM
Edited Apr 21, 2008 at 6:02 AM
Here is VB.NET's code:
_
Public Function FindGeoNearPoint(ByVal pos As SharpMap.Geometries.Point, ByVal layer As SharpMap.Layers.VectorLayer, ByVal amountGrow As Double) As SharpMap.Data.FeatureDataRow
Dim bbox As SharpMap.Geometries.BoundingBox = pos.GetBoundingBox().Grow(amountGrow)
Dim ds As New SharpMap.Data.FeatureDataSet()
layer.DataSource.ExecuteIntersectionQuery(bbox, ds)
Dim tbl As DataTable = TryCast(ds.Tables(0), SharpMap.Data.FeatureDataTable)
Dim reader As New GisSharpBlog.NetTopologySuite.IO.WKTReader()
Dim point As GeoAPI.Geometries.IGeometry = reader.Read(pos.ToString())
If tbl.Rows.Count = 0 Then
Return Nothing
End If

Dim distance As Double = point.Distance(reader.Read(TryCast(tbl.Rows(0), SharpMap.Data.FeatureDataRow).Geometry.ToString()))
Dim selectedFeature As SharpMap.Data.FeatureDataRow = TryCast(tbl.Rows(0), SharpMap.Data.FeatureDataRow)

If tbl.Rows.Count > 1 Then
For i As Integer = 1 To tbl.Rows.Count - 1
Dim line As GeoAPI.Geometries.IGeometry = reader.Read(TryCast(tbl.Rows(i), SharpMap.Data.FeatureDataRow).Geometry.ToString())
If point.Distance(line) < distance Then
distance = point.Distance(line)
selectedFeature = TryCast(tbl.Rows(i), SharpMap.Data.FeatureDataRow)
End If
Next
End If
Return selectedFeature
End Function
-
</code>
Apr 22, 2008 at 2:05 AM
Hi trieuvy

I get "Unable to cast object of type 'GisSharpBlog.NetTopologySuite.Geometries.Point' to type 'GeoAPI.Geometries.IGeometry'." at line

Dim point As GeoAPI.Geometries.IGeometry = reader.Read(pos.ToString())

Any ideas?

Thanks
Chris




trieuvy wrote:
Here is VB.NET's code:
_
Public Function FindGeoNearPoint(ByVal pos As SharpMap.Geometries.Point, ByVal layer As SharpMap.Layers.VectorLayer, ByVal amountGrow As Double) As SharpMap.Data.FeatureDataRow
Dim bbox As SharpMap.Geometries.BoundingBox = pos.GetBoundingBox().Grow(amountGrow)
Dim ds As New SharpMap.Data.FeatureDataSet()
layer.DataSource.ExecuteIntersectionQuery(bbox, ds)
Dim tbl As DataTable = TryCast(ds.Tables(0), SharpMap.Data.FeatureDataTable)
Dim reader As New GisSharpBlog.NetTopologySuite.IO.WKTReader()
Dim point As GeoAPI.Geometries.IGeometry = reader.Read(pos.ToString())
If tbl.Rows.Count = 0 Then
Return Nothing
End If

Dim distance As Double = point.Distance(reader.Read(TryCast(tbl.Rows(0), SharpMap.Data.FeatureDataRow).Geometry.ToString()))
Dim selectedFeature As SharpMap.Data.FeatureDataRow = TryCast(tbl.Rows(0), SharpMap.Data.FeatureDataRow)

If tbl.Rows.Count > 1 Then
For i As Integer = 1 To tbl.Rows.Count - 1
Dim line As GeoAPI.Geometries.IGeometry = reader.Read(TryCast(tbl.Rows(i), SharpMap.Data.FeatureDataRow).Geometry.ToString())
If point.Distance(line) < distance Then
distance = point.Distance(line)
selectedFeature = TryCast(tbl.Rows(i), SharpMap.Data.FeatureDataRow)
End If
Next
End If
Return selectedFeature
End Function
-
</code>

Developer
Apr 22, 2008 at 2:51 AM
Hi mc oz !
I use GeoAPI.dll 1.0.0.0 and NetTopologySuite.dll 1.7.2.19134.
In reader.Read(string WKT) method : return GeoAPI.Geometries.IGeometry type( reader as GisSharpBlog.NetTopologySuite.IO.WKTReader() ).
However, You can use TryCast in VB follow:
Dim point As GeoAPI.Geometries.IGeometry = TryCast(reader.Read(pos.ToString()),GeoAPI.Geometries.IGeometry )
May be help you.

Apr 22, 2008 at 5:06 AM
Hi trieuvy

Thanks for you reply. I swapped
Dim point As GeoAPI.Geometries.IGeometry = reader.Read(pos.ToString())
to
Dim point As GeoAPI.Geometries.IGeometry = TryCast(reader.Read(pos.ToString()),GeoAPI.Geometries.IGeometry )

the error now reads
"Unable to cast object of type 'GisSharpBlog.NetTopologySuite.Geometries.Polygon' to type 'GeoAPI.Geometries.IGeometry'."

I do not understand what you mean with
In reader.Read(string WKT) method : return GeoAPI.Geometries.IGeometry type( reader as GisSharpBlog.NetTopologySuite.IO.WKTReader() ).

Can we get the code to work if you send me GeoAPI.dll 1.0.0.0 and NetTopologySuite.dll 1.7.2.19134 ? I cannot find these older versions anywhere to download.

Cheers
Chris



trieuvy wrote:
Hi mc oz !
I use GeoAPI.dll 1.0.0.0 and NetTopologySuite.dll 1.7.2.19134.
In reader.Read(string WKT) method : return GeoAPI.Geometries.IGeometry type( reader as GisSharpBlog.NetTopologySuite.IO.WKTReader() ).
However, You can use TryCast in VB follow:
Dim point As GeoAPI.Geometries.IGeometry = TryCast(reader.Read(pos.ToString()),GeoAPI.Geometries.IGeometry )
May be help you.



Developer
Apr 23, 2008 at 7:10 AM
Hi chris !
you can download "NetTopologySuite 1.7.3 RC2 SRC" or "NetTopologySuite 1.7.3 RC2 bin" here that include GeoAPI 1.0.0 in SRC.
http://code.google.com/p/nettopologysuite/
Add preference to use my above segment code.
May be help you!
Apr 29, 2008 at 1:00 AM
Edited Apr 29, 2008 at 2:24 AM
Hi trieuvy

Thanks for your reply and sorry for my late feedback. The donwload file you mention only contains version 1.1.0.0 of GeoAPI.dll which I am already using. I therefore still have the same error that I reported in a previous post. I would very much appreciate it if you could have another try at resolving the error as I am not able to solve the problem and really need to get this working.

Thanks for your help
Chris



trieuvy wrote:
Hi chris !
you can download "NetTopologySuite 1.7.3 RC2 SRC" or "NetTopologySuite 1.7.3 RC2 bin" here that include GeoAPI 1.0.0 in SRC.
http://code.google.com/p/nettopologysuite/
Add preference to use my above segment code.
May be help you!

Developer
May 9, 2008 at 6:15 PM
hi chris!
I have been litle busy for one month. Sorry for my reply late.
You should use both GeoAPI.dll(1.0.0) and NetTopology.dll (1.7.3) together in above link for that segment code.
Remeber NetTopology 1.7.3, Don't use older version that you are using it.
:)
May 12, 2008 at 1:05 AM

trieuvy

Thanks for your reply. I have had to abandon this solution because I could not get it to work. Please see my post "Implementing NtsProvider with VB". Would be great if you could help me solve my problem.

Many thanks
Chris


trieuvy wrote:
hi chris!
I have been litle busy for one month. Sorry for my reply late.
You should use both GeoAPI.dll(1.0.0) and NetTopology.dll (1.7.3) together in above link for that segment code.
Remeber NetTopology 1.7.3, Don't use older version that you are using it.
:)



May 12, 2008 at 6:05 PM
Hi trieuvy
         In your code, the local 'layer' variable, as per my understanding, it is a newly created variable that is yet to be assigned with a datasource later after the calculation of feature data row. But it seems that in your code, you are actually calling

layer.DataSource.ExecuteIntersectionQuery(myBoundingBox, myDataSet);

        In that case, we are getting error that DataSource object is null, which is ofcourse the case because at this point, the layer is new and fresh and doesnot yet have any datasource. In my code, before calling this method, in my mouse click event method, I created a local layer variable and passed that as parameter to this function. That is resulting with this exception.
        If my use my global layer variable which is assigned with datasource from a shapefile, then this problem would not occur, but nothing seems to happen if we do so. The data table seems to have count as 0 because of which null is always returned. 
        How to overcome both the situations. Kindly reply at the earliest as I have to finish this project asap and already going late.

Regards
Parthiban R

Developer
May 13, 2008 at 5:22 PM
Hi Parthiban R
You use it as follow:
// Create a map global variable
SharpMap map=new SharpMap.Map(new Size(....));
map.Layers.Add()// add layer you need show here.
// Image img=map.GetMap()// show image on web or appliaction.
Note: In website, this global  map can be lost when page post back. You have to create  map again.
After that, You get layer that you need to show it's geometry when you click on map.
SharpMap.Layer.VecterLayer needLayer =map.GetLayerByName("layerName");// layerName is name of layer that you have added in to map and need to get geometry
Then, you call function:
SharpMap.Data.FeatureDataRow rowSelected=FindGeoNearPoint( pointClick, needLayer,100);
Show Geometry on map:
//create the selected layer
SharpMap.Layers.VectorLayer laySelected = new SharpMap.Layers.VectorLayer("Selection");
laySelected.DataSource = new SharpMap.Data.Providers.GeometryProvider(rowSelected.Geomertry);
laySelected.Style.Fill = new System.Drawing.SolidBrush(SystemColor.Hightlight);

map.Layers.Add(laySelected);
//GetMap() and show image here.
Good Project for you.
DTan
May 14, 2008 at 2:09 AM
Hi trieuvy
                Actually I have also tried supplying the current layer of the map being shown in application and that was returning null. I have also tried by first making use of GetLayerByName method  to get my layer and call the function but the result is same, that the function FindGeoNearPoint returning null. I am attaching my source code of Form1.cs here which contains the essential modules of my application built so far. Can you kindly look in to it and check where its going wrong? (I am using GeoAPI 1.1.0.0 and NetTopologySuite 1.7.3.16791)

using

System;

 

using

System.Collections.Generic;

 

using

System.ComponentModel;

 

using

System.Data;

 

using

System.Drawing;

 

using

System.Linq;

 

using

System.Text;

 

using

System.Windows.Forms;

 

using

System.IO;

 

using

GisSharpBlog.NetTopologySuite.IO;

 

using

GeoAPI;

 

 

 

 

namespace

MapTrial4

 

{

 

public partial class Form1 : Form

 

{

SharpMap.

Map myMap;

 

SharpMap.Layers.

VectorLayer myLayer;

 

SharpMap.Data.Providers.

ShapeFile myShapeFile;

 

 

public Form1()

 

{

InitializeComponent();

MyInitialization();

}

 

public void MyInitialization()

 

{

myMap =

new SharpMap.Map(mapImage1.Size);

 

myLayer =

new SharpMap.Layers.VectorLayer("My India Layer");

 

richTextBox1.AppendText(

"Welcome to my GIS tool for India");

 

 

}

 

/// <summary>

 

 

/// REQUIREMENT 1:

 

 

/// Make sure the software is shipped with bin and debug/release directories properly

 

 

/// as this method heavily relies on that structure. It assuemes the exe resides in bin folder

 

 

/// and then traverses back to get the shapefile directory

 

 

/// </summary>

 

 

/// <returns></returns>

 

 

private string GetShapeFilePath()

 

{

 

string FilePath;

 

 

//First creating a path till the project directory by reversing from current directory

 

 

DirectoryInfo directoryInfo = Directory.GetParent(Directory.GetCurrentDirectory());

 

directoryInfo = directoryInfo.Parent;

//removing 'debug' directory from path

 

FilePath = directoryInfo.FullName;

//removing 'bin' direcotry from path

 

 

 

//Now access the shape file directory and return its path

 

FilePath = FilePath +

@"\data\";

 

 

return FilePath;

 

}

 

private void myMapRefresh()

 

{

mapImage1.Map = myMap;

mapImage1.Refresh();

}

 

public SharpMap.Data.FeatureDataRow FindGeoNearPoint(SharpMap.Geometries.Point pos, SharpMap.Layers.VectorLayer layer, double amountGrow)

 

{

SharpMap.Geometries.

BoundingBox myBoundingBox = pos.GetBoundingBox();

 

SharpMap.Data.

FeatureDataSet myDataSet = new SharpMap.Data.FeatureDataSet();

 

layer.DataSource.Open();

layer.DataSource.ExecuteIntersectionQuery(myBoundingBox, myDataSet);

 

DataTable myDataTable = myDataSet.Tables[0] as SharpMap.Data.FeatureDataTable;

 

 

 

WKTReader myReader = new WKTReader();

 

GeoAPI.Geometries.

IGeometry point = myReader.Read(pos.ToString());

 

 

if (myDataTable.Rows.Count == 0)

 

 

return null;

 

 

double distance = point.Distance(myReader.Read((myDataTable.Rows[0] as SharpMap.Data.FeatureDataRow).Geometry.ToString()));

 

SharpMap.Data.

FeatureDataRow selectedFeature = myDataTable.Rows[0] as SharpMap.Data.FeatureDataRow;

 

 

if (myDataTable.Rows.Count > 1)

 

{

 

for (int i = 1; i < myDataTable.Rows.Count; i++)

 

{

GeoAPI.Geometries.

IGeometry line = myReader.Read((myDataTable.Rows[i] as SharpMap.Data.FeatureDataRow).Geometry.ToString());

 

 

if (point.Distance(line) < distance)

 

{

distance = point.Distance(line);

selectedFeature = myDataTable.Rows[i]

as SharpMap.Data.FeatureDataRow;

 

}

}

}

 

return selectedFeature;

 

}

 

 

 

 

private void buttonStart_Click(object sender, EventArgs e)

 

{

buttonStart.Enabled =

false;

 

richTextBox1.AppendText(

"\nLoading the GIS files of India..");

 

 

//Create shape map layer and add it to map box

 

 

string myShapeFilePath = GetShapeFilePath();

 

myShapeFile =

new SharpMap.Data.Providers.ShapeFile(myShapeFilePath + @"india_ds.shp");

 

myLayer.DataSource = myShapeFile;

myLayer.Style.Outline =

new Pen(Color.White, 1f);

 

myLayer.Style.EnableOutline =

true;

 

 

//SetGradientTheme();

 

myMap.Layers.Add(myLayer);

myMap.ZoomToExtents();

 

mapImage1.Map = myMap;

richTextBox1.AppendText(

"\nLoaded");

 

buttonStart.Enabled =

true;

 

 

}

 

private void buttonZoomIn_Click(object sender, EventArgs e)

 

{

mapImage1.ActiveTool = SharpMap.Forms.

MapImage.Tools.ZoomIn;

 

}

 

private void buttonZoomOut_Click(object sender, EventArgs e)

 

{

mapImage1.ActiveTool = SharpMap.Forms.

MapImage.Tools.ZoomOut;

 

}

 

private void buttonPan_Click(object sender, EventArgs e)

 

{

mapImage1.ActiveTool = SharpMap.Forms.

MapImage.Tools.Pan;

 

}

 

private void mapImage1_MouseMove(SharpMap.Geometries.Point WorldPos, MouseEventArgs ImagePos)

 

{

labelImageLocation.Text =

"Image Coordinates X: " + ImagePos.X + " Y: " + ImagePos.Y;

 

labelWorldLocation.Text =

"World Coordinates X: " + WorldPos.X + " Y: " + WorldPos.Y;

 

 

 

}

 

private void mapImage1_MouseClick(object sender, MouseEventArgs e)

 

{

SharpMap.Layers.

VectorLayer needLayer = (SharpMap.Layers.VectorLayer)myMap.GetLayerByName("My India Layer");

 

SharpMap.Data.

FeatureDataRow rowSelected = FindGeoNearPoint(new SharpMap.Geometries.Point(e.X, e.Y), needLayer, 100);

 

SharpMap.Layers.

VectorLayer laySelected = new SharpMap.Layers.VectorLayer("Selection");

 

 

if (rowSelected != null)

 

{

laySelected.DataSource =

new SharpMap.Data.Providers.GeometryProvider(rowSelected.Geometry);

 

laySelected.Style.Fill =

new System.Drawing.SolidBrush(SystemColors.Highlight);

 

myMap.Layers.Add(laySelected);

}

 

}

}

}

         May be it should have anything to do with the points I supply. May be I should convert them to world coordinates (ImageToWorld) before I call the function? Please throw some light on where its going wrong.




Developer
May 28, 2008 at 5:48 AM
Hi Parthi!
yes, you have to convert to world coordinates (ImageToWorld) before call function FindGoeNearPoint(worldPos, layer,7*30)
You should test in mouse down envent follow:

private void mapImage1_MouseDown(SharpMap.Geometries.Point WorldPos, MouseEventArgs ImagePos)

 

{

SharpMap.Layers.

VectorLayer needLayer = (SharpMap.Layers.VectorLayer)myMap.GetLayerByName("My India Layer");

 

SharpMap.Data.

FeatureDataRow rowSelected = FindGeoNearPoint(WorldPos, needLayer, 500);
...............

 }


Jun 29, 2008 at 8:37 PM

thnxx for your code it worked with me but  with geometry of type line string

but when i test it with geometry ""type of points"" not worked ??????!!!!!!!!!

trieuvy wrote:
hi mc OZ
You can use function follow to choose a geometry when you click mouse on map. After that You can add this geometry like as a layer of map with a pecific color or draw it in Paint method of Window form.
<code>
public SharpMap.Data.FeatureDataRow FindGeoNearPoint(SharpMap.Geometries.Point pos, SharpMap.Layers.VectorLayer layer,double amountGrow)
{
SharpMap.Geometries.BoundingBox bbox = pos.GetBoundingBox().Grow(amountGrow);
SharpMap.Data.FeatureDataSet ds = new SharpMap.Data.FeatureDataSet();
layer.DataSource.ExecuteIntersectionQuery(bbox, ds);
DataTable tbl = ds.Tables0 as SharpMap.Data.FeatureDataTable;
GisSharpBlog.NetTopologySuite.IO.WKTReader reader = new GisSharpBlog.NetTopologySuite.IO.WKTReader();
GeoAPI.Geometries.IGeometry point = reader.Read(pos.ToString());
if (tbl.Rows.Count == 0)
return null;

double distance = point.Distance(reader.Read((tbl.Rows0 as SharpMap.Data.FeatureDataRow).Geometry.ToString()));
SharpMap.Data.FeatureDataRow selectedFeature = tbl.Rows0 as SharpMap.Data.FeatureDataRow;

if (tbl.Rows.Count > 1)
for (int i = 1; i < tbl.Rows.Count; i++)
{
GeoAPI.Geometries.IGeometry line = reader.Read((tbl.Rowsi as SharpMap.Data.FeatureDataRow).Geometry.ToString());
if (point.Distance(line) < distance)
{
distance = point.Distance(line);
selectedFeature = tbl.Rowsi as SharpMap.Data.FeatureDataRow;
}
}
return selectedFeature;
}
</code>
pos: position click mouse on map
layer: layer click
amountGrow: area need grow surround pos. ( about 50 pixel)
Now You can draw geometry in datarow :
<code>
SharpMap.Data.FeatureDataRow rowSelected=FindGeoNearPoint( pointClick, layerSelected,50);
//create the selected layer
SharpMap.Layers.VectorLayer laySelected = new SharpMap.Layers.VectorLayer("Selection");
laySelected.DataSource = new SharpMap.Data.Providers.GeometryProvider(rowSelected.Geomertry);
laySelected.Style.Fill = new System.Drawing.SolidBrush(SystemColor.Hightlight);

map.Layers.Add(laySelected); //map is a gloabal variable which type is "Map"
</code>
Note:You need add preference : GeoAPI.dll and NetTopologySuite.dll
May be help you!



Jun 30, 2008 at 4:22 PM
Edited Jun 30, 2008 at 4:40 PM

hi.......trieuvy

PROBLEM 1:: i used ur highlighting polygon code inc#!
an error is occured-------
"Error 1 'SharpMap.Data.FeatureDataSet' does not contain a definition for 'Tables0' "

i hav added geoapi.dll nd net...dll as well!

bt  m not getting actually whr to put these codes ....

how to call that function plzz......HELP!

PROBLEM2:: n if m using checkboxes to show a layer of user's choice only...even then its a problem!!

i dnt know how to do that!!

Jun 30, 2008 at 7:01 PM

you can use it sharpmap.data.feature data set ds
featuredatatable=ds.tables[0];

neeti wrote:

hi.......trieuvy

PROBLEM 1:: i used ur highlighting polygon code inc#!
an error is occured-------
"Error 1 'SharpMap.Data.FeatureDataSet' does not contain a definition for 'Tables0' "

i hav added geoapi.dll nd net...dll as well!

bt  m not getting actually whr to put these codes ....

how to call that function plzz......HELP!

PROBLEM2:: n if m using checkboxes to show a layer of user's choice only...even then its a problem!!

i dnt know how to do that!!




Jun 30, 2008 at 7:26 PM
thanx....Samsen_only

it worked..........
another error.............Error 1 The name 'rowSelected' does not exist in the current context 
                                 Error 2 The name 'SystemColor' does not exist in the current context 
wat to do??
Jun 30, 2008 at 9:58 PM

Error 1 The name 'rowSelected' does not exist in the current context 

check if this row null or not what's value in it.

Error 2 The name 'SystemColor' does not exist in the current context 

use Color.anycolor you choose.



neeti wrote:
thanx....Samsen_only

it worked..........
another error.............Error 1 The name 'rowSelected' does not exist in the current context 
                                 Error 2 The name 'SystemColor' does not exist in the current context 
wat to do??


Jul 1, 2008 at 12:34 PM
Hi trieuvy,

I am facing a strange problem.

I am using the http://www.codeplex.com/SharpMap/WorkItem/View.aspx?WorkItemId=12687 clickFeature code to create a clickable ajaxMap. I tried integrating your polygon coloring code in this. As expected, I got the typecasting error for 

GeoAPI.Geometries.IGeometry point = (GeoAPI.Geometries.IGeometry)reader.Read(pos.ToString());

 

 

 

which I solved as follows:

GisSharpBlog.NetTopologySuite.IO.

WKTReader reader = new GisSharpBlog.NetTopologySuite.IO.WKTReader();

 

GisSharpBlog.NetTopologySuite.Geometries.

Geometry readpos = reader.Read(pos.ToString());

 

GeoAPI.Geometries.

IGeometry point = readpos as GeoAPI.Geometries.IGeometry;

 

 

...

Now when I build (code compiles perfectly) and run the code, the value of point remains null although the variable readpos is not null.
On investigating I found that the version of NetTopologySuite.dll that I was using was older, and referenced the latest one. But this is giving me compilation errors elsewhere for eg:

 

 

internal

static GisSharpBlog.NetTopologySuite.Geometries.Point ToNTSPoint(SharpMap.Geometries.Point point,

 

GisSharpBlog.NetTopologySuite.Geometries.

GeometryFactory factory)

 

{

 

return factory.CreatePoint(ToNTSCoordinate(point, factory));

 

}

 

 

Errors out as

Cannot implicitly convert type 'GeoAPI.Geometries.IPoint' to 'GisSharpBlog.NetTopologySuite.Geometries.Point'. An explicit conversion exists (are you missing a cast?)

 

 

Could you please help me??

Regards,

Pinging

Jul 1, 2008 at 8:15 PM
HI IF ANY BODY CAN HELP PLZ/////////

SharpMap.Data.FeatureDataRow rowSelected=FindGeoNearPoint( pointClick, layerSelected,50);

problem1:
Error 1 The name 'layerselected' does not exist in the current context 

 i hav tried it by changing to layselected also!!
even though its same!!

problem2:
plz help me!
wat is "pointClick"??
from where do i get its value??
CALLING OF the function is not clear!!

wid regards.........
Developer
Jul 2, 2008 at 4:00 AM
Hi every body!
I think that If you want to use my function "FindGeoNearPoint(pointClick, layerSelected,amountGrow)", You should read my above tutorial clearly before.
I 'll explain again:

pointClick : point that you click on map. This point have to convert to world point.
layerSelected: layer that you want query feature. Your  map  have a lot of layer, you must show to me How is layer you want query.
amountGrow: amount to grow bounding box that you want query. If  it's  small , algorithm  will run  faster . You can use about 200 pixel.

Jul 2, 2008 at 10:18 AM
hi.......treiuvy nd everybdy.....

thanx 4 all the help....
here is my project's code.....m new to c#.net......plz help....

MOTO OF MY PROJECT:
1- USER CAN SELECT /UNSELECT THE LAYERS TO VIEW BY HIS CHOICE USING CHECKBOXES.......
2-FOR "COUNTRIESLAYER".....HE CAN SELECT A PARTICULAR POLYGON AND SHOW THE INFORMATION ABOUT THE COUNTRY USIN A POP-UP!!


plz help me ............completing my project...last day of submission is monday......
m in need!!



<code>
using

System;

 

 

 

 

using

System.Collections.Generic;

 

 

 

 

using

System.ComponentModel;

 

 

 

 

using

System.Data;

 

 

 

 

using

System.Drawing;

 

 

 

 

using

System.Text;

 

 

 

 

using

System.Windows.Forms;

 

 

 

 

using

SharpMap;

 

 

 

 

using

GeoAPI.Geometries;

 

 

 

 

 

 

namespace

Map1

 

{

 

public partial class Form1 : Form

 

 

 

 

{

 

SharpMap.

Map myMap1;

 

 

 

//define dataname and source

 

 

 

 

 

public int a;

 

 

public int b;

 

 

const string data_name1 = "world countries";

 

 

const string data_path1 = @"I:\downloads\SharpMap-3316412\Branches\1.1experimental\WinFormSamples\GeoData\World\countries.shp";

 

 

const string data_name2 = "cities";

 

 

const string data_path2 = @"I:\downloads\SharpMap-3316412\Branches\1.1experimental\WinFormSamples\GeoData\World\cities.shp";

 

 

const string data_name3 = "rivers";

 

 

const string data_path3 = @"I:\downloads\SharpMap-3316412\Branches\1.1experimental\WinFormSamples\GeoData\World\rivers.shp";

 

 

const string data_path4 = @"I:\downloads\railroad\railroads.shp";

 

 

 

public Form1()

 

{

InitializeComponent();

 

 

 

//ADD the counties shape file to the map

 

 

 

 

 

//countries------

 

 

 

 

SharpMap.Layers.

VectorLayer countrieslayer = new SharpMap.Layers.VectorLayer(data_name1);

 

countrieslayer.DataSource =

new SharpMap.Data.Providers.ShapeFile(data_path1);

 

 

//cities--------

 

 

 

 

SharpMap.Layers.

VectorLayer citieslayer = new SharpMap.Layers.VectorLayer(data_name2);

 

citieslayer.DataSource =

new SharpMap.Data.Providers.ShapeFile(data_path2);

 

 

//river--------

 

 

 

 

SharpMap.Layers.

VectorLayer riverlayer = new SharpMap.Layers.VectorLayer(data_name3);

 

riverlayer.DataSource =

new SharpMap.Data.Providers.ShapeFile(data_path3);

 

 

 

 

//map is a gloabal variable which type is "Map"

 

 

 

 

 

//initialize the map

 

 

 

 

myMap1 =

new SharpMap.Map(new Size(400, 600));

 

myMap1.BackColor =

Color.Aqua;

 

myMap1.Layers.Add(countrieslayer);

myMap1.Layers.Add(riverlayer);

myMap1.Layers.Add(citieslayer);

 

 

//set a dash pattern

 

 

 

 

myMap1.ZoomToExtents();

 

//set color to green......

 

 

 

 

countrieslayer.Style.Fill =

new SolidBrush(Color.Bisque);

 

 

//set borders to color black

 

 

 

 

countrieslayer.Style.Outline = System.Drawing.

Pens.Black;

 

countrieslayer.Style.EnableOutline =

true;

 

riverlayer.Style.Line = System.Drawing.

Pens.White;

 

citieslayer.Style.Line = System.Drawing.

Pens.Wheat;

 

 

SharpMap.Data.

FeatureDataRow rowselected = FindGeoNearPoint(Mouse_Click(a,b), countrieslayer, 50);  / /HOW TO DEAL WID THS MOUSE CLICK

 

myMap1.Center =

new SharpMap.Geometries.Point(0, 0);

 

SharpMap.Layers.

VectorLayer laySelected = new SharpMap.Layers.VectorLayer("Selection");

 

laySelected.DataSource =

new SharpMap.Data.Providers.GeometryProvider(rowselected.Geometry);

 

laySelected.Style.Fill =

new System.Drawing.SolidBrush(SystemColors.Highlight);

 

myMap1.Layers.Add(laySelected);

 

 

}

 

 

 

private void worldCountriesToolStripMenuItem_Click(object sender, EventArgs e)

 

{

 

if (ofd.ShowDialog() == DialogResult.OK)

 

{

 

if (ofd.FileName == data_path1)

 

{

pictureBox1.Visible =

true;

 

pictureBox1.Image = myMap1.GetMap();

checkBox1.Visible =

true;

 

checkBox1.Checked =

true;

 

checkBox2.Visible =

true;

 

checkBox2.Checked =

true;

 

checkBox3.Visible =

true;

 

checkBox3.Checked =

true;

 

}

}

}

 

private void Form1_Load(object sender, EventArgs e)

 

{

 

if (checkBox2.Checked == false)

 

{

//wat do i write here.....so that a particular layer can be visible or not BY USER'S CHOICE.
}

}

 

 

private void Mouse_Click(object sender, MouseEventArgs e)

 

{

 

 

}

 

 

public SharpMap.Data.FeatureDataRow FindGeoNearPoint(SharpMap.Geometries.Point pos, SharpMap.Layers.VectorLayer layer, double amountGrow)

 

{

SharpMap.Geometries.

BoundingBox bbox = pos.GetBoundingBox().Grow(amountGrow);

 

SharpMap.Data.

FeatureDataSet ds = new SharpMap.Data.FeatureDataSet();

 

layer.DataSource.ExecuteIntersectionQuery(bbox, ds);

 

DataTable tbl = ds.Tables[0] as SharpMap.Data.FeatureDataTable;

 

GisSharpBlog.NetTopologySuite.IO.

WKTReader reader = new GisSharpBlog.NetTopologySuite.IO.WKTReader();

 

GeoAPI.Geometries.

IGeometry point = reader.Read(pos.ToString());

 

 

if (tbl.Rows.Count == 0)

 

 

return null;

 

 

 

double distance = point.Distance(reader.Read((tbl.Rows[0] as SharpMap.Data.FeatureDataRow).Geometry.ToString()));

 

SharpMap.Data.

FeatureDataRow selectedFeature = tbl.Rows[0] as SharpMap.Data.FeatureDataRow;

 

 

if (tbl.Rows.Count > 1)

 

 

for (int i = 1; i < tbl.Rows.Count; i++)

 

{

GeoAPI.Geometries.

IGeometry line = reader.Read((tbl.Rows[i] as SharpMap.Data.FeatureDataRow).Geometry.ToString());

 

 

if (point.Distance(line) < distance)

 

{

distance = point.Distance(line);

selectedFeature = tbl.Rows[i]

as SharpMap.Data.FeatureDataRow;

 

}

}

 

return selectedFeature;

 

}

 

  }

}

Jul 2, 2008 at 12:50 PM
Hi trieuy,

I have followed your tutorial, but am still getting the point as null. Anything for me please?

GeoAPI.Geometries.IGeometry point = reader.Read(pos.ToString());

Pinging
Jul 2, 2008 at 3:17 PM
Hi.Pringing...!!

can u plz help me...see my last post!!
Developer
Jul 3, 2008 at 4:48 AM
Hi Pinging !
May be, You use versions of Netopologysuite and GeoAPI aren't  compatibility.
I use GeoAPI.dll 1.0.0.0 and NetTopologySuite.dll 1.7.2.19134.
Developer
Jul 3, 2008 at 5:45 AM
Hi everybody. You can download dll here: http://www.codeplex.com/SharpMap/WorkItem/View.aspx?WorkItemId=17238
Jul 3, 2008 at 7:33 AM

 

 i hav declared......
<code>
public System.EventArgs ImageClickEventArgs;
<code>

and......
<code>
protected
void imgMap_Click(object sender,ImageClickEventArgs e)

 

{

 

//Center the map on the click-point

 

myMap1.Center = myMap1.ImageToWorld(

new System.Drawing.PointF(e.X, e.Y), myMap1);

 

 

//Zoom in 2x

 

myMap1.Zoom *= 0.5;

 

//Call function that renders the map and returns it to the client

 

myImage.Image = myMap.GetMap();

}

<code>
error:'Map1.Form1.ImageClickEventArgs' is a 'field' but is used like a 'type' 


plz help me in esolving the error
Jul 3, 2008 at 7:48 AM
Hi Neeti,

I think this is your solution:


 http://www.codeplex.com/SharpMap/WorkItem/View.aspx?WorkItemId=12687
Jul 3, 2008 at 9:52 AM
hi....Pinging....

thanx for considering!!
but...
actually i am using shape files as layers....

and unable to select/highlight...a particular country in world map....."countries.shp"

struggled alot....

plz suggest me smthng!!
Coordinator
Jul 3, 2008 at 10:20 AM


neeti wrote:

 

 i hav declared......
<code>
public System.EventArgs ImageClickEventArgs;
<code>

 

Why have you declared this? If you need to store a reference to some event args call the field something else.
Also with regard to using shapefiles vs another datasource, as a general rule, the approach to consuming the data is the same, just change the example code to use the provider/data of your choice. 
HTH jd

Jul 3, 2008 at 10:51 AM
Edited Jul 3, 2008 at 10:56 AM
Hi trieuvy,

I managed to typecast the relevant variables and finally got my code to compile using your dlls.

However, now I am getting the following runtime error on page load itself:

System.MissingMethodException: Method not found: 'Void SharpMap.Map.set_HasLegd(Boolean)'

I know the code that I am trying to integrate with yours used an earlier NetTopology.dll. But I do need to achieve this functionality.

Any clues / suggestions?

ANYBODY???
Jul 3, 2008 at 10:53 AM

Hey Neeti,

This is from another downloaded code which uses a function createcheckboxes as per layers.

createCheckboxes(ajaxMap.Map.Layers);

Basically you create a map with layers and use the following function:

private

void createCheckboxes(System.Collections.Generic.List<SharpMap.Layers.ILayer> LayerList)

 

{

 

Int32 i = 0;

 

 

foreach (SharpMap.Layers.ILayer myLayer in LayerList)

 

{

CheckBox chk =

new CheckBox();

 

chk.ID =

"chk" + i.ToString();

 

chk.Checked =

true;

 

 

if (myLayer.GetType() == typeof(SharpMap.Layers.LabelLayer))

 

setLabel(chk, (myLayer

as SharpMap.Layers.LabelLayer));

 

 

if (myLayer.GetType() == typeof(SharpMap.Layers.LayerGroup))

 

{

chk.Attributes.Add(

"OnClick", "SharpMap_HiddenLayers(ajaxMapObj);togLayerGroup(this, '" + chk.ID.Substring(3) + "');");

 

pnlLayers.Controls.Add(chk);

HtmlImage exCol =

new HtmlImage();

 

exCol.ID =

"img" + i.ToString();

 

exCol.Src =

"images/minus.gif";

 

exCol.Style.Add(

"cursor", "hand");

 

exCol.Attributes.Add(

"onclick", "expandIt('" + chk.ID.Substring(3) + "');");

 

pnlLayers.Controls.Add(exCol);

Label myLabel =

new Label();

 

myLabel.Text =

" " + myLayer.LayerName;

 

pnlLayers.Controls.Add(myLabel);

}

 

else

 

 

 

{

chk.Attributes.Add(

"OnClick", "SharpMap_HiddenLayers(ajaxMapObj);");

 

chk.Text = myLayer.LayerName;

pnlLayers.Controls.Add(chk);

 

if (myLayer.GetType() == typeof(SharpMap.Layers.VectorLayer))

 

pnlLayers.Controls.Add(LegendDiv(myLayer));

}

pnlLayers.Controls.Add(

new LiteralControl("<br>"));

 

 

if (myLayer.GetType() == typeof(SharpMap.Layers.LayerGroup))

 

recursiveCheck(pnlLayers, myLayer, i, chk.ID.ToString());

i += 1;

}

}

I havent tried it, see if it works for u...

Jul 3, 2008 at 11:37 AM
Hello

Sorry for repeated posts:

I managed to get the code working with an earlier dll of NetTopology.

However, my polygon is still not getting highlighted.

Here is the highlighting code:

SharpMap.Layers.

VectorLayer layToQuery = ajaxMap.Map.Layers[1] as SharpMap.Layers.VectorLayer;

 

SharpMap.Data.

FeatureDataRow rowSelected = MapHelper.FindGeoNearPoint(pointClick, layToQuery, 30);

 

SharpMap.Layers.

VectorLayer laySelected = new SharpMap.Layers.VectorLayer("Selection");

 

laySelected.DataSource =

new SharpMap.Data.Providers.GeometryProvider(rowSelected.Geometry);

 

laySelected.Style.Fill =

new System.Drawing.SolidBrush(System.Drawing.Color.Yellow);

 

laySelected.Enabled =

true;

 

laySelected.Style.Enabled =

true;

 

 

ajaxMap.Map.Layers.Add(laySelected);

 

 

 

ajaxMap.Map.Zoom = curzoom;

ajaxMap.Map.Center.X = pntx;

ajaxMap.Map.Center.Y = pnty;

 

ajaxMap.ResponseFormat =

"maphandler.ashx?MAP=SimpleWorld&Width=[WIDTH]&Height=[HEIGHT]&Zoom=[ZOOM]&X=[X]&Y=[Y]";

 



Any ideas?
Developer
Jul 8, 2008 at 8:25 AM
Hi Pinging
Your code is true. But i can't find pointClick. You can show your pointClick
1) You have to convert point click to world point for FindGeoNearPoint method.
2) You should test with larger amountGrow : 100

SharpMap.Data.

FeatureDataRow rowSelected = MapHelper.FindGeoNearPoint(pointClick, layToQuery, 100);


Jul 9, 2008 at 6:32 AM
I am so sorry,
here is the declaration:
Point pointClick = ajaxMap.Map.ImageToWorld(new System.Drawing.PointF((float)pntx, (float)pnty));
Jul 9, 2008 at 6:38 AM
Hello trieuvy,

Thank you for the support.

I tried with larger values of amountGrow, upto 500, but am still unable to get the code working.

Regards,
Developer
Jul 10, 2008 at 3:22 AM
hi Pinging !
You should debug to show rowSelected.Geometry either != null or ==null .
if it is !=null. May be you set centerX and centerY is wrong.
In ur code. May be You have to set

ajaxMap.Map.Center.X = pointClick.X;//  it also have  to converted to worldmap.

ajaxMap.Map.Center.Y = pointClick.Y

1) If coordinating of pntx and pnty in ur code is world  coord. You use it in both MapHelper.FindGeoNearPoint(new SharpMap.Geometry.Point(pntx,pnty),.......) and AjaxMap.Map.Center=new SharpMap.Geometry.Point(pntx,pnty);

2) If coordinating of pntx and pnty is map coord. You convert to worldmap: Sharmap.Geometry.Point pointClick = ajaxMap.Map.ImageToWorld(new System.Drawing.PointF((float)pntx, (float)pnty));

After that you use it in both MapHelper.FindGeoNearPoint( pointClick,.........) and AjaxMap.Map.Center=pointClick.

May be help you.


Nov 30, 2008 at 6:37 AM
Hi trieuvy,
I used your FindGeoNearPoint() function in my application but when I click on map nothing happens, no changes on map. This is the code in picturebox MouseDown event. I also put these codes in MouseClick but nothing changed :

Private Sub imgMap_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles imgMap.MouseDown
        Dim rowSelected As SharpMap.Data.FeatureDataRow
        rowSelected = FindGeoNearPoint(myMap.ImageToWorld(e.Location), myMap.Layers(0), 50)
        Dim laySelected = New SharpMap.Layers.VectorLayer("Selection")
        laySelected.DataSource = New SharpMap.Data.Providers.GeometryProvider(rowSelected.Geometry)
        laySelected.Style.Fill = Brushes.Blue
        myMap.Layers.Add(laySelected)
        myMap.GetMap()
    End Sub

Could you please help me ? ...


Thanks
Oct 28, 2009 at 8:18 PM

 

Hi Trieuvy,

Thanks for the below code -

<code>
public SharpMap.Data.FeatureDataRow FindGeoNearPoint(SharpMap.Geometries.Point pos, SharpMap.Layers.VectorLayer layer,double amountGrow)
{
SharpMap.Geometries.BoundingBox bbox = pos.GetBoundingBox().Grow(amountGrow);
SharpMap.Data.FeatureDataSet ds = new SharpMap.Data.FeatureDataSet();
layer.DataSource.ExecuteIntersectionQuery(bbox, ds);
DataTable tbl = ds.Tables0 as SharpMap.Data.FeatureDataTable;
GisSharpBlog.NetTopologySuite.IO.WKTReader reader = new GisSharpBlog.NetTopologySuite.IO.WKTReader();
GeoAPI.Geometries.IGeometry point = reader.Read(pos.ToString());
if (tbl.Rows.Count == 0)
return null;

double distance = point.Distance(reader.Read((tbl.Rows0 as SharpMap.Data.FeatureDataRow).Geometry.ToString()));
SharpMap.Data.FeatureDataRow selectedFeature = tbl.Rows0 as SharpMap.Data.FeatureDataRow;

if (tbl.Rows.Count > 1)
for (int i = 1; i < tbl.Rows.Count; i++)
{
GeoAPI.Geometries.IGeometry line = reader.Read((tbl.Rowsi as SharpMap.Data.FeatureDataRow).Geometry.ToString());
if (point.Distance(line) < distance)
{
distance = point.Distance(line);
selectedFeature = tbl.Rowsi as SharpMap.Data.FeatureDataRow;
}
}
return selectedFeature;
}
</code>
pos: position click mouse on map
layer: layer click
amountGrow: area need grow surround pos. ( about 50 pixel)
Now You can draw geometry in datarow :
<code>
SharpMap.Data.FeatureDataRow rowSelected=FindGeoNearPoint( pointClick, layerSelected,50);
//create the selected layer
SharpMap.Layers.VectorLayer laySelected = new SharpMap.Layers.VectorLayer("Selection");
laySelected.DataSource = new SharpMap.Data.Providers.GeometryProvider(rowSelected.Geomertry);
laySelected.Style.Fill = new System.Drawing.SolidBrush(SystemColor.Hightlight);

map.Layers.Add(laySelected); //map is a gloabal variable which type is "Map"
</code>

I have used this code and this is working fine.But instead of one point geometry and another polygon,I wan't to do the intersection between 2 polygon layers.

My goal is the user will click on a polygon and the point features included in that polygon will be selected.

Till now I am only able to select the polygon which the user selects with the above code.Now how am I suppose to select the points lying inside the polygon.

 

Please help.

Thanks in advance,

Regards, Sayan 

 

Oct 28, 2009 at 8:22 PM

Hi Trieuvy,

Forgot to tell that I have all layers in postgis database.

Regards, Sayan