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;
}
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.
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.
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.
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.