public void ShapeInWhereTest() { new ArcEngineLicense(); var sdeWs = DataActions.GetSdeWorkspace(new Dictionary <string, object>() { { "INSTANCE", "sde:oracle11g:192.168.0.2/orcl" }, { "USER", "dzgisdata" }, { "PASSWORD", "dzgisdata" }, }); var feaWs = (IFeatureWorkspace)sdeWs; IFeatureClass xzqh = null; IFeatureClass ydhx = null; try { xzqh = feaWs.OpenFeatureClass("DZGISDATA.XZQH"); ydhx = feaWs.OpenFeatureClass("DZGISDATA.YDHX_SP"); } catch (Exception ex) { throw new Exception("尝试打开图层失败,名字或许不存在"); } var chartMap = new Dictionary <string, int>(); ydhx.Features().ToList().ForEach((feature) => { Dictionary <string, double> interectAreasDic = new Dictionary <string, double>(); xzqh.Features().ToList().ForEach((xz) => { var copy = xz.ShapeCopy; copy.SpatialReference = feature.Shape.SpatialReference; var intersect = ((ITopologicalOperator)(feature.Shape)).Intersect(copy, esriGeometryDimension.esriGeometry2Dimension); var area = ((IArea)intersect).Area; var row = (IRow)xz; var fieldIndex = row.Fields.FindField("NAME"); string name = String.Empty; try { name = (string)xz.Value[fieldIndex]; } catch (Exception) { } double storedArea; if (interectAreasDic.TryGetValue(name, out storedArea)) { if (area > storedArea) { interectAreasDic[name] = area; } } else { interectAreasDic[name] = area; } }); var descendOrder = interectAreasDic.OrderByDescending(kvp => kvp.Value); var finalRegionName = descendOrder.First().Key; var preCount = 0; if (chartMap.TryGetValue(finalRegionName, out preCount)) { chartMap[finalRegionName] += 1; } else { chartMap[finalRegionName] = 0; } }); }