Aggregating features by attributes using Dissolve / Unionshapes ?

Oct 8, 2012 at 8:55 AM

Hello,

I'm trying to aggregate features based on specified attributes (like ArcGIS Geoprocessing Tool 'Dissolve' does).

Using DotSpatial.Data.FeatureSetExt.Dissolve calculates a union of any features that have a common value in the specified field a a multipart feature, but I need single shapes

So I tried a workaround by manually selecting the features that have a common value and then using DotSpatial.Data.FeatureSetExt.UnionShapes(ShapeRelateType.Intersecting).  But there I always get a NullReferenceException.

Has someone got a working code sample for this task?

Alternatively: is there a way to explode the multipart feature (resulting from the Dissolve function) into single shapes?

Thaks in advance,

Claudia

Mar 24, 2013 at 1:58 PM
Dear Claudia,

did you get a solution for your problem? I had the same problem but didn't find a solution yet

Thanks
Oscar
Mar 26, 2013 at 8:38 PM
Hello Oscar,

I'm using DotSpatial.Data.FeatureSetExt.Dissolve and then explode the multipart feature
Here's my code (in VB.NET):
Public Function Aggregate(ByVal fsInput As IFeatureSet, ByVal fieldname As String) As IFeatureSet

        Using fsTemp1 As IFeatureSet = fsInput.Dissolve(fieldname)
            fsTemp1.Extent = fsInput.Extent
            fsTemp1.Projection = fsInput.Projection

            Using fsOutput As IFeatureSet = New FeatureSet(FeatureType.Polygon)
                fsOutput.Extent = fsInput.Extent
                fsOutput.Projection = fsInput.Projection
                fsOutput.CopyTableSchema(fsTemp1)

                For i As Integer = 0 To fsTemp1.Features.Count - 1
                    Dim tempFeature As IFeature
                    tempFeature = fsTemp1.Features(i)
                    Dim value As Object = tempFeature.DataRow(fieldname)
                    For n As Integer = 0 To tempFeature.NumGeometries - 1
                        Dim tempBGeometry As IBasicGeometry
                        tempBGeometry = tempFeature.GetBasicGeometryN(n)
                        fsOutput.AddFeature(tempBGeometry)
                        fsOutput.Features(fsOutput.Features.Count - 1).DataRow(fieldname) = value
                    Next
                Next

                Return fsOutput

            End Using
        End Using
    End Function
First time for me to (hopefully) help someone here ;-)

Bye, Claudia
Apr 8, 2013 at 11:06 AM
Thanks Claudia,

I tried it and it seems to solve my problem.

Very grateful

Bye
Oscar