Last active
May 5, 2017 03:37
-
-
Save YinChaoOnline/269f993d9dfd67032c7a341a95d9ac08 to your computer and use it in GitHub Desktop.
查询亚洲范围内人口等级(POP_RANK)为5的所有城市(针对示例数据World.mxd)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//省略若干其他代码 | |
private void menuSpatialIntersect_Click(object sender, EventArgs e) | |
{ | |
//get the continent layer | |
IFeatureLayer continentLayer = GetLayerByName("Continents", axMapControl1.Map) as IFeatureLayer; | |
//query the continents layer where its name equals 'asia' | |
//get the feature's geometry matching the above condition | |
IQueryFilter queryFilter = new QueryFilterClass(); | |
queryFilter.WhereClause = "CONTINENT='Asia'"; | |
IFeatureCursor cursor = continentLayer.FeatureClass.Search(queryFilter, false); | |
IGeometry intersectGeomtry = cursor.NextFeature().Shape; | |
//get city layer | |
//do spatial query where it is intersected with the geometry and pop_rank =5 | |
IFeatureLayer cityLayer = GetLayerByName("World Cities", axMapControl1.Map) as IFeatureLayer; | |
ISpatialFilter spatialFilter = new SpatialFilter(); | |
spatialFilter.WhereClause = "POP_RANK=5"; | |
spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects; | |
spatialFilter.Geometry = intersectGeomtry; | |
//highlight by SelectionSet | |
IFeatureSelection featureSelection = cityLayer as IFeatureSelection; | |
featureSelection.SelectFeatures(spatialFilter, esriSelectionResultEnum.esriSelectionResultNew, false); | |
//partial refresh | |
axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, intersectGeomtry, null); | |
} | |
private ILayer GetLayerByName(String layerName, IMap map) | |
{ | |
ILayer layer = null; | |
for (int i = 0; i < map.LayerCount; i++) | |
{ | |
if (map.get_Layer(i).Name == layerName) | |
{ | |
layer = map.get_Layer(i); | |
break; | |
} | |
} | |
return layer; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment