# Z value lost when making new PointShape

**URL:** <https://community.thinkgeo.com/t/z-value-lost-when-making-new-pointshape/10141>\
**Category:** ThinkGeo UI for Desktop\
**Created:** [September 21, 2021, 5:44pm UTC](https://community.thinkgeo.com/t/z-value-lost-when-making-new-pointshape/10141 "2021-09-21T17:44:31Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Damian\_Hite](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/d/d2c977/32.png) [@Damian\_Hite](https://community.thinkgeo.com/u/Damian_Hite)\
**Post date:** [September 21, 2021, 5:44pm UTC](https://community.thinkgeo.com/t/z-value-lost-when-making-new-pointshape/10141/1 "2021-09-21T17:44:31Z")

</div>

Hi,

The following operation (and several similar ones) loses the Z value of PointShape class.

var pt = new PointShape(aX, aY, aZ);  
var fea = pt.GetFeature();  
var pt2 =(PointShape)fea.GetShape();

I think the constructor needs to have Z value assignment. This is a fairly urgent request. Can you please look into it?

Regards,  
Damian

---

<div class="post-metadata">

**Author:** ![Leo\_Liu](https://community.thinkgeo.com/user_avatar/community.thinkgeo.com/leo_liu/32/25689_2.png) [@Leo\_Liu](https://community.thinkgeo.com/u/Leo_Liu)\
**Post date:** [September 22, 2021, 3:40pm UTC](https://community.thinkgeo.com/t/z-value-lost-when-making-new-pointshape/10141/2 "2021-09-22T15:40:13Z")

</div>

Hi Damian,

We use WKB to store geometry in Feature, but WKB doesn’t support Z for now. We can store Z value to feature’s column value and restore it to PointShape, like the following methods:

```
    public Feature ConvertToFeature(PointShape point)
    {
        Feature feature = new Feature(point.X, point.Y);
        feature.ColumnValues.Add("zValue", point.Z.ToString());
        return feature;
    }

    public PointShape ConvertToPointShape(Feature feature)
    {
        string zValue = feature.ColumnValues["zValue"];
        double z;
        PointShape p = feature.GetShape() as PointShape;
        if (p != null && double.TryParse(zValue, out z))
        {
            p.Z = z;
        }
        return p;
    }

```

Thanks,  
Leo

---

<div class="post-metadata">

**Author:** ![Damian\_Hite](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/d/d2c977/32.png) [@Damian\_Hite](https://community.thinkgeo.com/u/Damian_Hite)\
**Post date:** [September 22, 2021, 4:50pm UTC](https://community.thinkgeo.com/t/z-value-lost-when-making-new-pointshape/10141/3 "2021-09-22T16:50:11Z")

</div>

Hi Leo,

My problem is that these points are being stored in sqlite db and the SQLiteFeatureLayer is used to display them. In the db, I am committing using the point.GetWellKnownBinary().

As the database takes byte[] for the geometry field, is it possible to substitute GetWellKnownBinary() with a standard binary formatter like follows:

```
    public static byte[] ObjectToByteArray(Object obj)
    {
        BinaryFormatter bf = new BinaryFormatter();

        using (var ms = new MemoryStream())
        {
            bf.Serialize(ms, obj);
            return ms.ToArray();
        }
    }

```

I notice if I serialize and deserialize using this method that the Z value is retained.

Thanks,  
Damian

---

<div class="post-metadata">

**Author:** ![Leo\_Liu](https://community.thinkgeo.com/user_avatar/community.thinkgeo.com/leo_liu/32/25689_2.png) [@Leo\_Liu](https://community.thinkgeo.com/u/Leo_Liu)\
**Post date:** [September 26, 2021, 2:15am UTC](https://community.thinkgeo.com/t/z-value-lost-when-making-new-pointshape/10141/4 "2021-09-26T02:15:10Z")

</div>

Hi Damian,

GetWellKnownBinary() is crucial in ThinkGeo Map, it would have a big impact if we change it.

In your db, besides featureIdColumn and geometryColumn, you could have another column “zValue” to store z values. When you get features from SQLiteFeatureLayer, you could get features with zValues in columnValues, and you could use method ConvertToPointShape(I replied previously) to create a PointShape with x, y, z.

Thanks,  
Leo

---

<div class="post-metadata">

**Author:** ![Damian\_Hite](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/d/d2c977/32.png) [@Damian\_Hite](https://community.thinkgeo.com/u/Damian_Hite)\
**Post date:** [October 21, 2021, 5:22pm UTC](https://community.thinkgeo.com/t/z-value-lost-when-making-new-pointshape/10141/5 "2021-10-21T17:22:51Z")

</div>

Hi Leo,

Sorry for the delayed reply.

I have just done an experiment that I don’t think worked the way it should.

```
                Feature f = new Feature(channel);
                f.ColumnValues.Add("Elevation", "40");
                byte[] bytes = f.GetWellKnownBinary();
                Feature uf = new Feature(bytes);

```

Feature uf does not contain the column value Elevation. So, if I ever write the feature f to my sqlite db, I still won’t be able to retrieve the elevation value and your method above can’t work.

Can you verify this is expected? If not and it’s a bug would appreciate knowing if it can be fixed as this would totally solve my problem and extend my program functionality quite a bit further without having to physically add columns to the database tables.

Thanks,  
Damian

---

<div class="post-metadata">

**Author:** ![Leo\_Liu](https://community.thinkgeo.com/user_avatar/community.thinkgeo.com/leo_liu/32/25689_2.png) [@Leo\_Liu](https://community.thinkgeo.com/u/Leo_Liu)\
**Post date:** [October 27, 2021, 2:18pm UTC](https://community.thinkgeo.com/t/z-value-lost-when-making-new-pointshape/10141/6 "2021-10-27T14:18:18Z")

</div>

hi Damian,

It’s not a bug, it’s expected. GetWellKnownBinary only return the well-known binary(see definition of [WKB](https://en.wikipedia.org/wiki/Well-known_text_representation_of_geometry)), it doesn’t have any columns value information.

Thanks,  
Leo
