利用IFeatureIndex2 和 IIndexQuery2提高空间查询效率
http://www.cnblogs.com/cglNet/archive/2012/03/12/2391645.html
1 StringBuilder tSB = new StringBuilder(); 2 3 IFeatureClass tFeatureClass = (IFeatureClass)this._InDataset; 4 5 6 7 IGeoDataset tGeodataset=(IGeoDataset)this._InDataset; 8 9 10 11 IFeatureIndex2 tFeatureIndex = new FeatureIndexClass(); 12 13 ESRI.ArcGIS.esriSystem.ITrackCancel tTrackCancel=new CancelTracker(); 14 15 IIndexQuery tIndexQuery = tFeatureIndex as IIndexQuery; 16 17 IIndexQuery2 tIndexQuery2 = (IIndexQuery2)tIndexQuery; 18 19 tFeatureIndex.FeatureClass = tFeatureClass; 20 21 tFeatureIndex.set_OutputSpatialReference(tFeatureClass.OIDFieldName, tGeodataset.SpatialReference); 22 23 tFeatureIndex.Index(tTrackCancel, tGeodataset.Extent);//tGeodataset.Extent 24 25 26 27 int iDex = tFeatureClass.FindField(this._FieldName); 28 29 for (int i = 0; i < _Rows; i++) 30 31 { 32 33 for (int j = 0; j < _Cols; j++) 34 35 { 36 37 double[] pX = null; 38 39 double[] pY = null; 40 41 getPolygon(i, j, ref pX, ref pY); 42 43 IPoint tPoint = new PointClass(); 44 45 tPoint.X = pX[0] + (pX[3] - pX[0]) / 2; 46 47 tPoint.Y = pY[0] + (pY[0] - pY[3]) / 2; 48 49 50 51 int oid= tIndexQuery2.WithinFeature(tPoint); 52 53 if (oid>-1) 54 55 { 56 57 IFeature tFeature = tFeatureClass.GetFeature(oid); 58 59 object o = tFeature.get_Value(iDex); 60 61 if (o != null && o.ToString().Trim() != "") 62 63 { 64 65 tSB.Append(o.ToString() + " "); 66 67 } 68 69 else 70 71 { 72 73 tSB.Append("-9999" + " "); 74 75 } 76 77 } 78 79 else 80 81 { 82 83 tSB.Append("-9999" + " "); 84 85 } 86 87 88 89 } 90 91 } 92 93 94 95 return tSB; 96 97 }