StringBuilder tSB = new StringBuilder();
IFeatureClass tFeatureClass = (IFeatureClass)this._InDataset;
IGeoDataset tGeodataset=(IGeoDataset)this._InDataset;
IFeatureIndex2 tFeatureIndex = new FeatureIndexClass();
ESRI.ArcGIS.esriSystem.ITrackCancel tTrackCancel=new CancelTracker();
IIndexQuery tIndexQuery = tFeatureIndex as IIndexQuery;
IIndexQuery2 tIndexQuery2 = (IIndexQuery2)tIndexQuery;
tFeatureIndex.FeatureClass = tFeatureClass;
tFeatureIndex.set_OutputSpatialReference(tFeatureClass.OIDFieldName, tGeodataset.SpatialReference);
tFeatureIndex.Index(tTrackCancel, tGeodataset.Extent);//tGeodataset.Extent
int iDex = tFeatureClass.FindField(this._FieldName);
for (int i = 0; i < _Rows; i++)
{
for (int j = 0; j < _Cols; j++)
{
double[] pX = null;
double[] pY = null;
getPolygon(i, j, ref pX, ref pY);
IPoint tPoint = new PointClass();
tPoint.X = pX[0] + (pX[3] - pX[0]) / 2;
tPoint.Y = pY[0] + (pY[0] - pY[3]) / 2;
int oid= tIndexQuery2.WithinFeature(tPoint);
if (oid>-1)
{
IFeature tFeature = tFeatureClass.GetFeature(oid);
object o = tFeature.get_Value(iDex);
if (o != null && o.ToString().Trim() != "")
{
tSB.Append(o.ToString() + " ");
}
else
{
tSB.Append("-9999" + " ");
}
}
else
{
tSB.Append("-9999" + " ");
}
}
}
return tSB;
}
利用IFeatureIndex2 和 IIndexQuery2来作空间检索,比用IFeatureCursor tFeatureCursor= tFeatureClass.Search(null, true);然后遍历IFeature快一些。