Pasti ada sesuatu yang mencurigakan terjadi di sini dengan 10.0 sp2.
Saya dapat melemparkan tas geometri ke IRelationalOperator2, jika tidak tes ini akan mengatakan "tidak dapat melakukan casting", ditambah saya akan mendapatkan pengecualian referensi nol.
Namun, pada panggilan pertama ke IsNear saya mendapatkan pengecualian.
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
Inilah tesnya:
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");
}
Ini tes lain. Perhatikan bagaimana saya bisa melakukan tanpa pengecualian, tetapi dapatkan pengecualian InvalidCast saat memanggil 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");
}