How to query and get segment of polygon by shape

2753
12
Jump to solution
07-15-2013 01:44 AM
doxuan_cuong
New Contributor
Hi every one, i have a issue.I have a feature class type of polygon in SDE geodatabase, and i want to query by a shape and get all segment of polygon within shape (only segment, not all polygon) .How can i do it.I use arcgis engine 9.3 and C#.
Thanks and Regard.
Cuongdx
0 Kudos
1 Solution

Accepted Solutions
WeifengHe
Occasional Contributor II
I'd use esriGeometry2Dimension as I metntioned before to get the polygon output.

ESRI.ArcGIS.Geometry.IPolygon pPoly = pTopoOp2.Intersect(pPolygon2,
        ESRI.ArcGIS.Geometry.esriGeometryDimension.esriGeometry2Dimension) as
        IPolygon;

Then I will use ISegmentCollection

ISegmentCollection pSegColl = pPoly as ISegmentCollection

int count = pSegColl.SegmentCount
for(int i = 0; i<count; i++)
{
       ISegment pSeg = pSegColl(i);
      //Do whatever you want with it
}

You can create a segment collection of polyline type
ISegmentCollection pSegColl2 = new Polyline() as ISegmentCollection

and then add all the segment from the pSegColl to pSegColl2. 

I didn't check the syntax of the code, but you got the idea.

View solution in original post

0 Kudos
12 Replies
WeifengHe
Occasional Contributor II
I will use ISpatialFilter to get the polygons.  For each polygon, cast from IPolygon to ISegmentCollection interface, you get the segments that you want.
0 Kudos
doxuan_cuong
New Contributor
But I want to get a part of segment in shape, not all segment.How can i do it?
0 Kudos
WeifengHe
Occasional Contributor II
Use ITopologicalOperator::Intersect with output option set to esriGeometry2Dimension, you get a polygon, and then cast to ISegmentCollection.  All the segments in this collection will be within the shape.
0 Kudos
doxuan_cuong
New Contributor
Thank you  weif4314 , although i don't really know how to do but i will try by that way.Can you support me?
0 Kudos
WeifengHe
Occasional Contributor II
No problem.  I will try my best to help. 

First you need to get the polygon feature class, and a shape (a polygon or an envelope I assume) as input in your code.   We can then start from there.

What programming language you use?
0 Kudos
doxuan_cuong
New Contributor
I use arcgis engine 9.3 and C#, i want to query geodatabase by a rectangle and get all polygon or segment within rectangle.So i intend to query all polygon and use ITopologicalOperator::Intersect to get segment within rectangle.Is it the best way?Do you have any code about it?
0 Kudos
doxuan_cuong
New Contributor
I use this code to find intersect of 2 polygon
void CreatePolylineFromExistingGeometries(ESRI.ArcGIS.Geometry.IPolygon pPolygon1,
    ESRI.ArcGIS.Geometry.IPolygon pPolygon2)
{
    //Build a new polyline by intersecting two existing polygons.
    ESRI.ArcGIS.Geometry.ITopologicalOperator2 pTopoOp2 = pPolygon1 as
        ITopologicalOperator2;
    //Simplify.
    pTopoOp2.IsKnownSimple_2 = false;
    pTopoOp2.Simplify();

    ESRI.ArcGIS.Geometry.IPolyline pPoly = pTopoOp2.Intersect(pPolygon2,
        ESRI.ArcGIS.Geometry.esriGeometryDimension.esriGeometry1Dimension) as
        IPolyline;
    //pPoly is the new generated polyline.
}


but when i check pPoly ( new polyline generated) then the properties IsEmpty of pPoly is true so i can't show pPoly  in map.
When i change esriGeometry1Dimension to esriGeometry2Dimension and return IPolygon then i can show Polygon intersect of 2 polygon. But i want to use polyline more than polygon intersect. So how to fix this problem?
0 Kudos
WeifengHe
Occasional Contributor II
I'd use esriGeometry2Dimension as I metntioned before to get the polygon output.

ESRI.ArcGIS.Geometry.IPolygon pPoly = pTopoOp2.Intersect(pPolygon2,
        ESRI.ArcGIS.Geometry.esriGeometryDimension.esriGeometry2Dimension) as
        IPolygon;

Then I will use ISegmentCollection

ISegmentCollection pSegColl = pPoly as ISegmentCollection

int count = pSegColl.SegmentCount
for(int i = 0; i<count; i++)
{
       ISegment pSeg = pSegColl(i);
      //Do whatever you want with it
}

You can create a segment collection of polyline type
ISegmentCollection pSegColl2 = new Polyline() as ISegmentCollection

and then add all the segment from the pSegColl to pSegColl2. 

I didn't check the syntax of the code, but you got the idea.
0 Kudos
doxuan_cuong
New Contributor
Great.It work for me, thanks you weif4314 .
0 Kudos