Pages

Search

Tuesday, December 23, 2008

How to find whether geometry is with in Feature class extent ESRI ?

Every feature class has its own extent for spatially distributing its features.

So we can check whether a given geometry lies in a given extent or envelope.

public static bool IsWithinExtent(IGeoDataset geoDataset, object geometry)
{
IGeometry pGeometry;
IRelationalOperator pRelOp;
try
{
//If given geometry is element then tracing its gemoetry to find
//with in extent
if (geometry is IElement)
pGeometry = ((IElement)geometry).Geometry;
//If given geometry is dimension, then considering all points lieing at the
//dimension feature boundaries
else if (geometry is IDimensionShape)
{
//Extracting the geometry of the dimension feature
IDimensionShape pDimShape = (IDimensionShape)geometry;
IPointCollection pPointCol = new PolygonClass();
object pBefore = Type.Missing;
object pAfter = Type.Missing;
//Creating a closed polygon with lines joining the dimension line point,
//dimension begin point, dimension end point
pPointCol.AddPoint(pDimShape.DimensionLinePoint, ref pBefore, ref pAfter);
pPointCol.AddPoint(pDimShape.BeginDimensionPoint, ref pBefore, ref pAfter);
pPointCol.AddPoint(pDimShape.EndDimensionPoint, ref pBefore, ref pAfter);
//Then taking geometry of finally created polygon
pGeometry = (IGeometry)pPointCol;
}
else
//Taking the exact geometry of the given object
pGeometry = (IGeometry)geometry;
//relation operator helps tp spatially licate the geometry
// and then chek its extent
pRelOp = (IRelationalOperator)pGeometry;
if (pRelOp.Within(geoDataset.Extent))
return true;
else
//Throughing coordinates out of boundary when give geometry
// does not lie with in the feature class extent
throw new Exception(conCoordsOutofBound);
}
catch
{
throw new Exception(conCoordsOutofBound);
}
}










No comments:

Post a Comment