Ejemplo n.º 1
0
        public static double[][] unpack_geometry(string geometry)
        {
            if (!String.IsNullOrEmpty(geometry))
            {
                var numberChars = geometry.Length;
                var bytes       = new byte[numberChars / 2];
                for (var i = 0; i < numberChars; i += 2)
                {
                    bytes[i / 2] = Convert.ToByte(geometry.Substring(i, 2), 16);
                }

                WkbShape shape = WkbDecoder.Parse(bytes);

                if (shape.GetType() == typeof(WkbMultiLineString))
                {
                    var lineString = (WkbMultiLineString)shape;
                    if (lineString.LineString.Count() > 0)
                    {
                        var index  = 0;
                        var points = new double[lineString.LineString[0].Points.Count()][];
                        foreach (var point in lineString.LineString[0].Points)
                        {
                            points[index] = new[] { point.X, point.Y };
                            index++;
                        }
                        return(points);
                    }
                }
            }
            return(new double[][] { });
        }
Ejemplo n.º 2
0
            static WkbGeometryCollection ParseGeometryCollection(byte[] wkb, ref int pos)
            {
                if (wkb[pos] != 1)
                {
                    throw new Exception("Sorry, only Little Endian format is supported");
                }
                var type = BitConverter.ToUInt32(wkb, pos + 1);

                if (type != (uint)WkbGeometryType.WkbGeometryCollection)
                {
                    throw new Exception("Invalid object type");
                }
                var nbShapes = BitConverter.ToUInt32(wkb, pos + 5);

                pos += 9;

                var shapes = new WkbShape[nbShapes];

                for (var r = 0; r < nbShapes; ++r)
                {
                    shapes[r] = ParseShape(wkb, ref pos);
                }

                return(new WkbGeometryCollection(shapes));
            }