I'm trying to put a list of point features (selected points) into a new FeatureClass. but when I add them to my FeatureClass I get the "Geometry cannot have Z values." exception on the line "buff.Shape = point;" . can any one help?

        List<IFeature> features = GetSelectedFeatures(axMapControl1.get_Layer(0) as IFeatureLayer);
        IPointArray pa = new PointArrayClass();

        List<IPoint> p = new List<IPoint>();
        for (int i = 0; i < features.Count; i++)
            p.Add(features[i].ShapeCopy as IPoint);

        IPoint point = new PointClass();
        point = pa.get_Element(0);

        point.SpatialReference = p[0].SpatialReference;

        IWorkspaceFactory workspaceFactory = new ShapefileWorkspaceFactoryClass();
        IWorkspace workspace = workspaceFactory.OpenFromFile(@"C:\", 0);
        IFeatureWorkspace featureWorkspace = workspace as IFeatureWorkspace;

        IFeatureClass FC = CreateFeatureClass("FC", featureWorkspace, pa.get_Element(0).SpatialReference,esriGeometryType.esriGeometryPoint);

        IFeatureCursor fCur = FC.Insert(false);
        IFeatureBuffer buff = FC.CreateFeatureBuffer();

        buff.Shape = point;


        IFeatureLayer fl = new ESRI.ArcGIS.Carto.FeatureLayer();
        fl.FeatureClass = FC;
        var layer = fl as ILayer;


  • 2
    Obviously your input-featureclass which you refer in the very first line of your code is z-enabled while the second FC is not. – HimBromBeere Jan 25 '16 at 12:32
  • No it's not. it has no Z value. – Steve Jan 25 '16 at 12:39
  • 2
    Did you try to explicitly set the ZAware property of the point (using the IZAware interface)? – Richard Morgan Jan 25 '16 at 12:54
  • 1
    What is the geometry type of the second FC? Is it "Point", "PointZ" or "PointZM"? You can check by opening the attribute table (ArcMap or ArcCatalog) and looking at the values in the "Shape" column. The FC in question could be z-enabled (PointZ of PointZM) but have no Z values, – Brent Edwards Jan 25 '16 at 14:11
  • thank you guys. thank you Brent. it's Point and I checked and the Z value is enabled! can it be disabled or should I make a new FeatureClass? – Steve Jan 26 '16 at 6:34

I just encountered a similar problem and wanted to offer an answer since Richard Morgan's above comment solved the problem.

I had a point feature class that was not Z-enabled but was, at the same time, rejecting the assignment of a new point geometry that had no Z value. The error message was "Geometry cannot have Z values". It was confusing simply because there were no Z values, anywhere.This new point geometry even had "NaN" as the value of the Z property.

I took Richard's advice and QI'd to IZAware:

IPoint toPoint = new PointClass(); IZAware toZAware = toPoint as IZAware; toZAware.ZAware = false;

Then I assigned the XY value and spatial reference of the new point.

(toZAware as IPoint).SpatialReference = spatialRef;
(toZAware as IPoint).X = serviceLine.ToPoint.X;
(toZAware as IPoint).Y = serviceLine.ToPoint.Y;

After this, I was allowed to assign and store the new point geometry to the Shape field of my feature.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.