ConstructUnion - shift

607
1
Jump to solution
02-28-2020 03:25 AM
M_DJohnson
Occasional Contributor

The data is in 'GCS_WGS_1984' and creating union polygon using IToplogicalOperator2.ConstructUnion successfully in different type of codes but in both cases found union polygon shift.

//Case-1

while ((feature = featureCursor.NextFeature()) != null)
{
ITopologicalOperator2 shape = feature.ShapeCopy as ITopologicalOperator2;
shape.IsKnownSimple_2 = false;
shape.Simplify();

geometriesToUnion.AddGeometry(shape as IGeometry, ref missing, ref missing);
}


IGeoDataset geoDataset = ipTargetFeatureClass.FeatureDataset as IGeoDataset;

IPolygon UnionPolygon = new PolygonClass();
UnionPolygon.SpatialReference = geoDataset.SpatialReference;
ITopologicalOperator2 topologicalOperator;
topologicalOperator = UnionPolygon as ITopologicalOperator2;

topologicalOperator.ConstructUnion(geometriesToUnion as IEnumGeometry);

//Case-2

while ((feature = featureCursor.NextFeature()) != null)
{
ITopologicalOperator2 shape = feature.ShapeCopy as ITopologicalOperator2;
shape.IsKnownSimple_2 = false;
shape.Simplify();

geometriesToUnion.AddGeometry(shape as IGeometry);
}

ITopologicalOperator2 topologicalOperator = new PolygonClass();
topologicalOperator.ConstructUnion(geometriesToUnion as IEnumGeometry); // union all features

Please suggest if anything missing in the code

0 Kudos
1 Solution

Accepted Solutions
M_DJohnson
Occasional Contributor

The issue is solved by setting spatial reference to GeometryBag

Snippet

IGeometryBag geoBag = new GeometryBagClass(); geoBag.SpatialReference = geoDataset.SpatialReference;  IGeometryCollection geometriesToUnion = geoBag as IGeometryCollection;

View solution in original post

0 Kudos
1 Reply
M_DJohnson
Occasional Contributor

The issue is solved by setting spatial reference to GeometryBag

Snippet

IGeometryBag geoBag = new GeometryBagClass(); geoBag.SpatialReference = geoDataset.SpatialReference;  IGeometryCollection geometriesToUnion = geoBag as IGeometryCollection;
0 Kudos