Hello, I am using the sketch tool to create and pass geometry to a function that will create a new polygon feature in a geodatabase that does not support z-values. The problem is the sketch tool geometry Has a Z value and thus the code fails. I would have thought this would be an easy fix but I have spent to much time trying to figure this out with no success. Anyone have any suggestions on how to remove the Z-Value from the incoming geometry or a way to prevent the sketch tool from creating the Z-value in the first place.
This is the basic code I am using and it fails when assigning the NewGeometry to the shapefield.
using (RowBuffer rowBuffer = featClass.CreateRowBuffer())
{
rowBuffer[facilitySiteDefinition.GetShapeField()] = NewGeometry;
using (Feature newfeature = featClass.CreateRow(rowBuffer))
{
//To Indicate that the attribute table has to be updated
context.Invalidate(newfeature);
}
}
Hi,
Convert your sketched geometry to a polygon using PolygonBuilderEx. Set the "HasZ" property to false. Like this:
var poly = geometry as Polygon;
var builderPoly = new PolygonBuilderEx(poly);
builderPoly.HasZ = false;
And then create your new feature by using the ToGeometry method. Like this:
rowBuffer[featureClass.GetDefinition().GetShapeField()] = builderPoly.ToGeometry();