ExecuteIntersectionQuery with one point

Topics: SharpMap Project, SharpMap v2.0
Oct 2, 2012 at 2:12 PM

Hello,

I try to use the ExecuteIntersectionQuery method with a point as parameter.

I use it with a shape file containing altitudes (contour lines). The problem is that it returns a table with a lot of values like if the bounding box of the point was very big. I was waiting for 1 or 2 values at each time to obtain the altitude of the mouse clicked point.

Any idea what is wrong ?

Here is the sample of code:

 

private void mapBox1_MouseUp(GeoPoint worldPos, MouseEventArgs imagePos) {

Collection<IGeometry> geometry = new Collection<IGeometry>();

	VectorLayer layerPoints = new VectorLayer(String.Empty);

	var gf = new GeometryFactory();

	var p = mapBox1.Map.ImageToWorld(imagePos.Location);

	Envelope bounding2 = new Envelope(p);

	FeatureDataSet ds1 = new FeatureDataSet();
	vlay.ExecuteIntersectionQuery(bounding2, ds1);

	dataGridView2.DataSource = ds1.Tables[0];
}

 

 

Thanks for your help and for the project !!!!

Coordinator
Oct 2, 2012 at 2:17 PM

What version of the code are you using?
There were an error in the code that were fixed in revision 99336 of the code.

Oct 2, 2012 at 2:40 PM

I just downloaded yesterday from the download page link SharpMap-0.9-AnyCPU-Trunk-2012.04.17

Coordinator
Oct 2, 2012 at 2:41 PM

OK, there will be a new version released as binaries soon where the fix is included.
Or you download the source yourself and build it.

That should solve your problem.

Oct 2, 2012 at 2:43 PM

No sorry in fact I downloaded the sharpmap-99878 and build it myself.

Oct 2, 2012 at 3:01 PM

Here is the result on a screen shot:

http://i48.tinypic.com/s48itt.png

I got a list of 10 altitudes for the red point clicked in the middle.

Thanks for your help

Coordinator
Oct 2, 2012 at 4:18 PM

You are absolutely sure that there is only one point on the spot? Add a LabelLayer displaying any property of the puntal layer. If your result is unreadable, you have more than one point on that spot

Hth FObermaier

Oct 3, 2012 at 7:49 AM

Sorry I don't understand what to do with "LabelLayer" but here the code corresponding to the screenShot:

 
private void mapBox1_MouseUp(GeoPoint worldPos, MouseEventArgs imagePos)
        {
            Collection geometry = new Collection();
            VectorLayer layerPoints = new VectorLayer(String.Empty);
            var gf = new GeometryFactory();

            var p = mapBox1.Map.ImageToWorld(imagePos.Location);
            geometry.Add(gf.CreatePoint(new GeoPoint(p.X, p.Y)));
            var provider = new GeometryProvider(geometry);
            layerPoints.DataSource = provider;
            mapBox1.Map.Layers.Add(layerPoints);
            mapBox1.Refresh();
            
            Envelope bounding2 = new Envelope(p);
            FeatureDataSet ds1 = new FeatureDataSet();
            vlay.ExecuteIntersectionQuery(bounding2, ds1);            
            dataGridView2.DataSource = ds1.Tables[0];
	}

Thank you

Coordinator
Oct 4, 2012 at 6:03 AM

Sorry I misinterpreted the code you posted above.

A couple of months ago, we used to use SharpMap's own geometry model, which was not capabale of doing true intersection query (unless some database backend provided that service) but instead only checked whether the bounding boxes did intersect. That is an easy check :).

Now that we use GeoAPI/NTS geometries this limitation is no longer in place, however, to provide backwards compatiblilty, you need to set the ShapeFile providers DoTrueIntersectionQuery if you are quering against bounding boxes and don't want the old behaviour. This applies if your contour lines are actually lines and no polygons. If you have closed polygons, you must make sure that the polygon that covers the altitude of e.g. 40 does not cover the area of any other polygon (I hope that makes sense).

Hth FObermaier

 

 

 

Oct 4, 2012 at 8:00 AM

Hi,

Thank you it seems to be working now !

I plan increase the size of the enveloppe I create around the clicked point until I cross 1 or 2 contour lines, and then get the average altitude.

Thanks a lot and congratulation for the project.

Coordinator
Oct 4, 2012 at 8:51 AM

MapBox control already has query support.

  • set ActiveTool to MapTools.Query[Window]
  • set QueryGrowFactor to some positive value.
  • handle MapQueried events

Hth FObermaier