ThinkGeo.com    |     Documentation    |     Premium Support

Z value lost when making new PointShape

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

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

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

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

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

hi Damian,

It’s not a bug, it’s expected. GetWellKnownBinary only return the well-known binary(see definition of WKB), it doesn’t have any columns value information.

Thanks,
Leo