bilaldursun1 / nettopologysuite

Automatically exported from code.google.com/p/nettopologysuite
0 stars 0 forks source link

Geometry.Intersects throws NullReferenceException #105

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Create a shape file that contains multipolygon shape that consists of only 
one polygon which is rectangle.
2. Open the shape file specifying ReadStrictness to be 
ShapeFileReadStrictness.Lenient;
3. Try to search for intersections under a point where the point is one under 
which there is a multipolygon as described above:

"
...
            using (var p = _searchShp.ExecuteFeatureQuery(FeatureQueryExpression.Intersects(sharpMapPoint)))
            {
                var index = 0;

                while (p.Read())
                {
                   ...
                }
"

What is the expected output? What do you see instead?

p.Read() should return true and advances the cursor to the feature under the 
specified point. Instead null reference exception is thrown from "return 
RectangleIntersects<TCoordinate>.Intersects(g as IPolygon<TCoordinate>, this);" 
in Geometry.cs. The reason is that when g is Multipolygon with only one polygon 
which is rectangle, then g.IsRectangle is true but g cannot be casted to 
IPolygon and the cast returns null.

What version of the product are you using? On what operating system?

Assembly version is 2.11.0.0. OS is Windows 7.

Please provide any additional information below.

The fix should be to override IsRectangle in MultiPolygon to always return 
false.

Original issue reported on code.google.com by tarantul...@abv.bg on 25 Jan 2012 at 6:01

GoogleCodeExporter commented 9 years ago
I'd prefer this fix

In Geometry.Intersects(...) function modify the IsRectangle block to 

            // optimizations for rectangle arguments
            if (IsRectangle)
            {
                var testGeom = (this is IGeometryCollection<TCoordinate>)
                                    ? ((IGeometryCollection<TCoordinate>)this)[0] as IPolygon<TCoordinate>
                                    : this as IPolygon<TCoordinate>;

                return RectangleIntersects<TCoordinate>.Intersects(testGeom, g);
            }

Original comment by felix.ob...@netcologne.de on 25 Jan 2012 at 8:49

GoogleCodeExporter commented 9 years ago
Sounds good.

Original comment by tarantul...@abv.bg on 25 Jan 2012 at 3:46