ThinkGeo.com    |     Documentation    |     Premium Support

Can features be created out of 3d geometries?

I have some 3D geometries in a wkb format I’m trying to create features out of. Things like point/line/polygon z/m/zm (see https://postgis.net/workshops/postgis-intro/3d.html for reference). Converting those to WKT have extra ordinates in them. For example:

LINESTRINGM (1 1 0, 1 2 0, 1 3 1, 2 2 0)

Passing the wkb of these into a new Feature(wkb) makes an invalid feature. For instance, calling .GetShape() on it will throw a null exception.

Is there a way to create these features and ignore the extra ordinates?

hi @Dan_Weaver,

You could convert WKB to WKT using NetTopologySuite.IO.WKBReader and then create features using WKT. Since NetTopologySuite is included with ThinkGeo.Core , you can use it directly.

        byte[] wkb = // 3D point wkb

        // Create a WKBReader
        NetTopologySuite.IO.WKBReader reader = new NetTopologySuite.IO.WKBReader();

        // Read the geometry from WKB
        var geometry = reader.Read(wkb);

        // Convert to WKT, Z coordinates will be dropped
        string wkt = geometry.AsText();

        // Z coordinates will be ignored if you pass a 3D geometries WKT
        var feature = Feature.CreateFeatureFromWellKnownData(wkt);

Regards,
Leo

Thanks Leo! Appreciate it

You’re welcome. Let me you know if you have any questions. :slight_smile:

Regards,
Leo