Kesinlikle burada 10.0 sp2 ile balık oluyor bir şey var.
Bir geometri torbasını IRelationalOperator2'ye atabilirim, aksi takdirde bu test "yayınlayamıyor" diyebilir, ayrıca boş bir referans istisnası alırdım.
Ancak, ilk IsNear çağrısında istisna alıyorum.
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
İşte 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");
}
İşte başka bir test. Ben istisnasız nasıl döküm dikkat edin, ancak IsNear çağırırken bir InvalidCast istisna olsun.
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");
}