Il y a certainement quelque chose de louche ici avec 10.0 sp2.
Je peux lancer un sac de géométrie sur IRelationalOperator2, sinon ce test dirait "incapable de lancer", plus j'obtiendrais une exception de référence nulle.
Cependant, lors du premier appel à IsNear, je reçois l'exception.
System.InvalidCastException occurred
Message=Unable to cast COM object of type 'ESRI.ArcGIS.Geometry.GeometryBagClass' to interface type 'ESRI.ArcGIS.Geometry.IRelationalOperator2'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{839F5C7E-ED5F-4B3F-8F97-C0A9CC4817EE}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).
Source=ESRI.ArcGIS.Geometry
Voici le test:
private void GBTest(IPoint pnt)
{
// this line does not fail
var relop = new GeometryBagClass() as IRelationalOperator2;
if (relop == null)
Debug.Print("unable to cast"); // this doesn't print out
var coll = relop as IGeometryCollection;
coll.AddGeometry(pnt);
//((ISpatialIndex)coll).AllowIndexing = true;
//((ISpatialIndex)coll).Invalidate();
var pnt2 = ((IClone)pnt).Clone() as IPoint;
((ITransform2D)pnt2).Move(100.0, 100.0);
if (relop.IsNear(pnt2, 1000.0)) // exception here
Debug.Print("test 1 fail");
if (!relop.IsNear(pnt2, 10.0))
Debug.Print("test 2 fail");
}
Voici un autre test. Remarquez comment je peux caster sans exception, mais obtenez une exception InvalidCast lors de l'appel à IsNear.
private void GBTest(IPoint pnt)
{
var coll = new GeometryBagClass();
((IGeometry)coll).SpatialReference = pnt.SpatialReference;
coll.AddGeometry(pnt);
coll.GeometriesChanged();
var relop = (IRelationalOperator2)coll; // would expect the exception here
var pnt2 = ((IClone)pnt).Clone() as IPoint;
((ITransform2D)pnt2).Move(100.0, 100.0);
if (relop.IsNear(pnt2, 1000.0)) // exception here
Debug.Print("test 1 fail");
if (!relop.IsNear(pnt2, 10.0))
Debug.Print("test 2 fail");
}