private static IGeometry get_GraphicShape(IEnumElement theElements, int a_Dimensionality, bool multipart, ref IElementCollection elemCollection) { IGeometry theReturn = null; IGeometryCollection theGeomColl = null; object missing = Type.Missing; try { elemCollection.Clear(); if (theElements != null) { theElements.Reset(); IElement theElement = theElements.Next(); while (theElement != null) { if (theGeomColl == null) theGeomColl = new GeometryBagClass(); IGeometry theShape = null; if (theElement is IGroupElement) { theShape = get_GraphicShape(((IGroupElement)theElement).Elements, a_Dimensionality, multipart,ref elemCollection); } else if (theElement is ICircleElement || theElement is IPolygonElement || theElement is IRectangleElement || theElement is IEllipseElement || theElement is ILineElement || theElement is IMarkerElement) theShape = theElement.Geometry; if (theShape != null) theGeomColl.AddGeometry(theShape, ref missing, ref missing); elemCollection.Add(theElement,-1); theElement = theElements.Next(); } } if (theGeomColl != null && theGeomColl.GeometryCount > 0) { ITopologicalOperator theTopoOp = null; switch (a_Dimensionality) { case 0: if (multipart) { theTopoOp = new MultipointClass(); theTopoOp.ConstructUnion((IEnumGeometry)theGeomColl); } else theTopoOp = theGeomColl.get_Geometry(0) as ITopologicalOperator; break; case 1: theTopoOp = new PolylineClass(); theTopoOp.ConstructUnion((IEnumGeometry)theGeomColl); break; case 2: theTopoOp = new PolygonClass(); theTopoOp.ConstructUnion((IEnumGeometry)theGeomColl); break; } theReturn = theTopoOp as IGeometry; } } catch(Exception ex) { util.Logger.Write(" Descrip : Finding elements with a specific dimensionality. " + "\n Message : " + ex.Message + "\n StackTrc : " + ex.StackTrace,util.Logger.LogLevel.Debug); } return theReturn; }
public static IGeometry get_GraphicShape(IEnumElement theElements, int a_Dimensionality, bool multipart) { IGeometry theReturn = null; IGeometryCollection theGeomColl = null; object missing = Type.Missing; if (theElements != null) { theElements.Reset(); IElement theElement = theElements.Next(); while (theElement != null) { if (theGeomColl == null) theGeomColl = new GeometryBagClass(); IGeometry theShape = null; if (theElement is IGroupElement) { theShape = get_GraphicShape(((IGroupElement)theElement).Elements, a_Dimensionality, multipart); } else if (theElement is ICircleElement || theElement is IPolygonElement || theElement is IRectangleElement || theElement is IEllipseElement || theElement is ILineElement || theElement is IMarkerElement) theShape = theElement.Geometry; if (theShape != null) theGeomColl.AddGeometry(theShape, ref missing, ref missing); theElement = theElements.Next(); } } if (theGeomColl != null && theGeomColl.GeometryCount > 0) { ITopologicalOperator theTopoOp = null; switch (a_Dimensionality) { case 0: if (multipart) { theTopoOp = new MultipointClass(); theTopoOp.ConstructUnion((IEnumGeometry)theGeomColl); } else theTopoOp = theGeomColl.get_Geometry(0) as ITopologicalOperator; break; case 1: theTopoOp = new PolylineClass(); theTopoOp.ConstructUnion((IEnumGeometry)theGeomColl); break; case 2: theTopoOp = new PolygonClass(); theTopoOp.ConstructUnion((IEnumGeometry)theGeomColl); break; } theReturn = theTopoOp as IGeometry; } return theReturn; }
public IGeometry GetSpatialFilter() { IGeometry geom = null; IFeature feature; IFeatureCursor featCursor = null; IQueryFilter queryFilter = new QueryFilter(); queryFilter.WhereClause = tbQuery.Text; //set query clause //query DataOperator dataOperator = new DataOperator(m_map); IFeatureLayer featureLayer = (IFeatureLayer)dataOperator.GetLayerByName(cbLayerName.Text); try { //get feature cursor featCursor = (IFeatureCursor)featureLayer.FeatureClass.Search(queryFilter, false); } catch { MessageBox.Show("Invalid query!"); return(null); } feature = featCursor.NextFeature(); IFeatureClass featureClass = feature.Class as IFeatureClass; //combine the geometries int count = 0; IGeometryCollection geometries = new GeometryBagClass(); object missing = Type.Missing; while (feature != null) { geom = feature.ShapeCopy; geometries.AddGeometry(geom, ref missing, ref missing); feature = featCursor.NextFeature(); count++; } //combine the geometries if (count > 1) { ITopologicalOperator unionedGeometry = null; switch (featureClass.ShapeType) { case esriGeometryType.esriGeometryMultipoint: unionedGeometry = new MultipointClass(); break; case esriGeometryType.esriGeometryPolyline: unionedGeometry = new PolylineClass(); break; case esriGeometryType.esriGeometryPolygon: unionedGeometry = new PolygonClass(); break; case esriGeometryType.esriGeometryPoint: unionedGeometry = new MultipointClass(); break; default: break; } unionedGeometry.ConstructUnion(geometries as IEnumGeometry); geom = unionedGeometry as IGeometry; } //get buffer if (cbMethod.Text == "Are within a distance of") { ITopologicalOperator ipTO = (ITopologicalOperator)geom; IGeometry iGeomBuffer = ipTO.Buffer(int.Parse(tbSearchDistance.Text)); geom = iGeomBuffer; } return(geom); }