Страница 1 из 1

Как определить полигон, которому принадлежит точка x,y

Добавлено: 14 июн 2012, 10:43
Tereha
Уважаемые Гуру!
Если не сложно, где можно посмотреть - как определить какому полигону принадлежит точка с координатами x,y?
(arcgis engine 2010, c#+ vs 2010)

Re: Как определить полигон, которому принадлежит точка x,y

Добавлено: 14 июн 2012, 11:14
Дмитрий Барышников

Re: Как определить полигон, которому принадлежит точка x,y

Добавлено: 14 июн 2012, 11:54
Tereha
Спасибо, огромное!

Код: Выделить всё

///<summary>Finds all the features in a GeoFeature layer by supplying a point. The point could come from a mouse click on the map.</summary>
///  
///<param name="searchTolerance">A System.Double that is the number of map units to search. Example: 25</param>
///<param name="point">An IPoint interface in map units where the user clicked on the map</param>
///<param name="geoFeatureLayer">An ILayer interface to search upon</param>
///<param name="activeView">An IActiveView interface</param>
///   
///<returns>An IFeatureCursor interface is returned containing all the selected features found in the GeoFeatureLayer.</returns>
///   
///<remarks></remarks>
public ESRI.ArcGIS.Geodatabase.IFeatureCursor GetAllFeaturesFromPointSearchInGeoFeatureLayer(System.Double searchTolerance, ESRI.ArcGIS.Geometry.IPoint point, ESRI.ArcGIS.Carto.IGeoFeatureLayer geoFeatureLayer, ESRI.ArcGIS.Carto.IActiveView activeView)
{

  if (searchTolerance < 0 || point == null || geoFeatureLayer == null || activeView == null)
  {
    return null;
  }
  ESRI.ArcGIS.Carto.IMap map = activeView.FocusMap;

  // Expand the points envelope to give better search results    
  ESRI.ArcGIS.Geometry.IEnvelope envelope = point.Envelope;
  envelope.Expand(searchTolerance, searchTolerance, false);

  ESRI.ArcGIS.Geodatabase.IFeatureClass featureClass = geoFeatureLayer.FeatureClass;
  System.String shapeFieldName = featureClass.ShapeFieldName;

  // Create a new spatial filter and use the new envelope as the geometry    
  ESRI.ArcGIS.Geodatabase.ISpatialFilter spatialFilter = new ESRI.ArcGIS.Geodatabase.SpatialFilterClass();
  spatialFilter.Geometry = envelope;
  spatialFilter.SpatialRel = ESRI.ArcGIS.Geodatabase.esriSpatialRelEnum.esriSpatialRelEnvelopeIntersects;
  spatialFilter.set_OutputSpatialReference(shapeFieldName, map.SpatialReference);
  spatialFilter.GeometryField = shapeFieldName;

  // Do the search
  ESRI.ArcGIS.Geodatabase.IFeatureCursor featureCursor = featureClass.Search(spatialFilter, false);

  return featureCursor;
}