I have some polygonal features that have minimum and maximum z values.
I'm trying to calculate the difference between a fixed extruded polygons and the sum of extruded related polygons.
Here's how I'm doing it:
Notes: the cursor is non recycling.
IExtrude extrude = new GeometryEnvironmentClass();
while ((tempFeature = cursor.NextFeature()) != null)
{
var lower = Classifier.GetNamedLevelValue(tempFeature.get_Value(lowerIdx).ToString());
var upper = Classifier.GetNamedLevelValue(tempFeature.get_Value(upperIdx).ToString());
var geometry = extrude.ExtrudeFromTo(lower, upper, tempFeature.ShapeCopy);
geometries.Add(geometry);
}
IGeometryFactory fact = new GeometryEnvironmentClass();
IGeometry unioned = null;
fact.CreateEmptyGeometryByType(esriGeometryType.esriGeometryMultiPatch, out unioned);
for (int i = 0; i <= geometries.Count - 1; i++)
{
var topo = (ITopologicalOperator)unioned;
var tempGeom = topo.Union(geometries[i]);
unioned = (IGeometry)((IClone)tempGeom).Clone();
}
var extrudedParent = extrude.ExtrudeFromTo(0, 999, feature.ShapeCopy);
var topoParent = (ITopologicalOperator)extrudedParent;
var remaining = topoParent.Difference((IGeometry)unioned);
I get a COM Exception in topoParent.Difference. I'm not sure what is the problem. Can anyone help me? Any other ways to do it?
This is the COMException: - "Exceção de HRESULT: 0x80040229"} System.Exception {System.Runtime.InteropServices.COMException}
I even whipped up a little unit test to check if it was my code or if the operation is illegal. Still crashes in the same spot.
[TestMethod]
public void VolumeTest()
{
object missing = Type.Missing;
var p1 = PointHelper.ConstructPoint(0, 0);
var p2 = PointHelper.ConstructPoint(0, 1);
var p3 = PointHelper.ConstructPoint(1, 1);
var p4 = PointHelper.ConstructPoint(1, 0);
var p5 = PointHelper.ConstructPoint(0, 2);
var p6 = PointHelper.ConstructPoint(2, 2);
var p7 = PointHelper.ConstructPoint(2, 0);
IPointCollection pointCol = new PolygonClass();
pointCol.AddPoint(p1, ref missing, ref missing);
pointCol.AddPoint(p2, ref missing, ref missing);
pointCol.AddPoint(p3, ref missing, ref missing);
pointCol.AddPoint(p4, ref missing, ref missing);
pointCol.AddPoint(p1, ref missing, ref missing);
IPointCollection pointCol2 = new PolygonClass();
pointCol2.AddPoint(p1, ref missing, ref missing);
pointCol2.AddPoint(p5, ref missing, ref missing);
pointCol2.AddPoint(p6, ref missing, ref missing);
pointCol2.AddPoint(p7, ref missing, ref missing);
pointCol2.AddPoint(p1, ref missing, ref missing);
IExtrude ext = new GeometryEnvironmentClass();
IGeometry extruded = ext.ExtrudeFromTo(0, 1, (IPolygon)pointCol);
IGeometry extruded2 = ext.ExtrudeFromTo(0, 2, (IPolygon)pointCol2);
ITopologicalOperator topo = (ITopologicalOperator)extruded2;
IGeometry result = topo.Difference(extruded);
}
Thanks