Select to view content in your preferred language

search cursor - spatialfilter - query for multipart polygon - arc 10 desktop

958
3
Jump to solution
04-03-2012 08:05 AM
tonydavid
Occasional Contributor
Does anyone know why multipart polygon doesn't work with this??

            pGridGeom = pGridFeature.Shape
            pGridSpatialFilter = New SpatialFilterClass
            With pGridSpatialFilter
                .GeometryField = pFeatcls.ShapeFieldName
                ' .SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects
                .SpatialRel = esriSpatialRelEnum.esriSpatialRelWithin
                .Geometry = pGridGeom
            End With
            pCursor = pFeatcls.Search(pGridSpatialFilter, True)

Should we 'explode' multipart poly into geometries?? Tried this but doesn't work ...

                If pGeomColl.GeometryCount > 1 Then
                    For i As Integer = 0 To pGeomColl.GeometryCount - 1
                        Dim pPolygonNew As IPolygon
                        Dim NewGeometryArray(0) As IGeometry
                        NewGeometryArray(0) = pGeomColl.Geometry(i)
                        Dim gBridge As IGeometryBridge = New GeometryEnvironment()
                        gBridge.AddGeometries(pPolygonNew, NewGeometryArray)
                        pGridGeom = pPolygonNew
                    Next
                 endif

Any help or suggestions?? Cheers.
0 Kudos
1 Solution

Accepted Solutions
NeilClemmons
Honored Contributor
It sounds like a problem with the geometry itself.  When you view its record in the layer's attribute table, does it have a positive area?  If the area is negative (or 0) then the polygon is oriented incorrectly.  You might also try simplifying the geometry before using it in the query.

Dim topoOp As ITopologicalOperator2 = CType(geometry, ITopologicalOperator2) topoOp.IsKnownSimple_2 = False topoOp.Simplify()


Another possibility is the polygon and the layer you are querying do not share the same spatial reference.  If this is the case you should set the OutputSpatialReference property on the spatial filter using the spatial reference of the polygon.

View solution in original post

0 Kudos
3 Replies
NeilClemmons
Honored Contributor
A spatial query can be performed with a multi-part polygon.  Are you getting an error or is your query simply not returning any features?  You're specifying esriSpatialRelEnum.esriSpatialRelWithin as the relationship type.  This means the query will return only features that wholly contain your multi-part polygon.  If you want to query for features that are inside your multi-part polygon then you need to use esriSpatialRelContains.
0 Kudos
tonydavid
Occasional Contributor
I tried esriSpatialRelEnum.esriSpatialRelContains and earlier esriSpatialRelEnum.esriSpatialRelIntersects ... its still not returning the overlapping line features. For non multipart polygons ... its working ... returning the overlapping line correctly. There's no return error messages.

I also tried -
.SpatialRel = esriSpatialRelEnum.esriSpatialRelRelation
.SpatialRelDescription = "T********"
0 Kudos
NeilClemmons
Honored Contributor
It sounds like a problem with the geometry itself.  When you view its record in the layer's attribute table, does it have a positive area?  If the area is negative (or 0) then the polygon is oriented incorrectly.  You might also try simplifying the geometry before using it in the query.

Dim topoOp As ITopologicalOperator2 = CType(geometry, ITopologicalOperator2) topoOp.IsKnownSimple_2 = False topoOp.Simplify()


Another possibility is the polygon and the layer you are querying do not share the same spatial reference.  If this is the case you should set the OutputSpatialReference property on the spatial filter using the spatial reference of the polygon.
0 Kudos