This project is read-only.

Test a point is intersect the line?

Sep 19, 2011 at 11:36 AM

Dear all,

Is there a method to test a point intersect the line while moving the mouse on the map ,the point comes from the Event map.GeoMouseMove?

I want to get the feature when the mouse move over the layer on the map!

Is someone knows how,just give me an example or a tips ?

Thanks very much!

Sep 19, 2011 at 10:54 PM


No guarantee this is the best way of doing that, but this example might give you an idea.


using DotSpatial.Data;
using DotSpatial.Topology;


   private void Map_GeoMouseMove(object sender, GeoMouseArgs e)
            var map = map1;
            var mouse = Geometry.DefaultFactory.CreatePoint(map.PixelToProj(e.Location));
            if (map.Layers.SelectedLayer != null)
                var file = map1.Layers.SelectedLayer.DataSet as LineShapefile;
                if (file == nullreturn;
                foreach (var line in file.Features)
                    bool collision = line.IsWithinDistance(mouse, .1);
Sep 20, 2011 at 5:04 AM

Hi, mudnug, do you think the method below is better than your's, However,I use the method below sometimes can't catch the line feature,for example,if the line featue is a rectangle or other shape!

void map1_GeoMouseMove(object sender, GeoMouseArgs e)


   featurelayer = map1.Layers.SelectedLayer as FeatureLayer;

   FeatureSet featureset = featurelayer.DataSet as FeatureSet;

   foreach (IFeature feature in featureset.Features)


       if ( feature.Envelope.Intersects(e.GeographicLocation) )



Sep 20, 2011 at 5:47 PM

I tried your code with a polygon file and it seemed to work. Is the Envelope not calculated correctly in the case of a rectangle?

Sep 21, 2011 at 4:54 AM

The rectangle which may be contains more than one rectangle, I think that while the mouse move in a rectangle,the envelope just belongs to the biggest rectangle,so the other can't be figured out! 

Sep 21, 2011 at 4:07 PM

That sounds reasonable. For that case then, you would need to test more then the envelope.

Sep 23, 2011 at 11:34 AM


Can you give me some advice about moving features on the layer? I can move the features to where I want  in the map,But after moving them, I can't select them any more.

Can you give a tips or an example?

Thanks very much!

Sep 23, 2011 at 7:17 PM

I've responded to