コード例 #1
0
        public static IFeature FromByteBuffer(ByteBuffer bb, GeometryType geometryType, byte dimensions, IList <ColumnMeta> columns = null)
        {
            var feature = Feature.GetRootAsFeature(bb);
            IAttributesTable attributesTable = null;
            var propertiesArray = feature.GetPropertiesArray();

            if (propertiesArray != null && propertiesArray.Length > 0)
            {
                var memoryStream = new MemoryStream(propertiesArray);
                var reader       = new BinaryReader(memoryStream);
                attributesTable = new AttributesTable();
                while (memoryStream.Position < memoryStream.Length)
                {
                    ushort i      = reader.ReadUInt16();
                    var    column = columns[i];
                    var    type   = column.Type;
                    var    name   = column.Name;
                    switch (type)
                    {
                    case ColumnType.Bool:
                        attributesTable.AddAttribute(name, reader.ReadBoolean());
                        break;

                    case ColumnType.Int:
                        attributesTable.AddAttribute(name, reader.ReadInt32());
                        break;

                    case ColumnType.Long:
                        attributesTable.AddAttribute(name, reader.ReadInt64());
                        break;

                    case ColumnType.Double:
                        attributesTable.AddAttribute(name, reader.ReadDouble());
                        break;

                    case ColumnType.String:
                        int len = reader.ReadInt32();
                        var str = Encoding.UTF8.GetString(memoryStream.ToArray(), (int)memoryStream.Position, len);
                        memoryStream.Position += len;
                        attributesTable.AddAttribute(name, str);
                        break;

                    default: throw new ApplicationException("Unknown type");
                    }
                }
            }

            IGeometry geometry = null;

            if (feature.Geometry.HasValue)
            {
                geometry = GeometryConversions.FromFlatbuf(feature.Geometry.Value, geometryType);
            }
            var f = new NetTopologySuite.Features.Feature(geometry, attributesTable);

            return(f);
        }
コード例 #2
0
        public static IFeature FromByteBuffer(ByteBuffer bb, Header header)
        {
            // TODO: introspect which layer
            var            columnsLayer = header.Layers(0).Value;
            IList <Column> columns      = null;

            if (columnsLayer.ColumnsLength > 0)
            {
                columns = new List <Column>();
                for (int i = 0; i < columnsLayer.ColumnsLength; i++)
                {
                    var column = columnsLayer.Columns(i).Value;
                    columns.Add(column);
                }
            }

            var feature = Feature.GetRootAsFeature(bb);
            IAttributesTable attributesTable = null;

            if (feature.ValuesLength > 0)
            {
                attributesTable = new AttributesTable();
            }

            var layer = header.Layers((int)feature.Layer).Value;

            for (int i = 0; i < feature.ValuesLength; i++)
            {
                var value  = feature.Values(i).Value;
                var column = columns[value.ColumnIndex];
                switch (column.Type)
                {
                case ColumnType.Bool:
                    attributesTable.AddAttribute(column.Name, value.BoolValue);
                    break;

                case ColumnType.Int:
                    attributesTable.AddAttribute(column.Name, value.IntValue);
                    break;

                case ColumnType.Long:
                    attributesTable.AddAttribute(column.Name, value.LongValue);
                    break;

                case ColumnType.Double:
                    attributesTable.AddAttribute(column.Name, value.DoubleValue);
                    break;

                case ColumnType.String:
                    attributesTable.AddAttribute(column.Name, value.StringValue);
                    break;

                default: throw new ApplicationException("Unknown type");
                }
            }

            var geometry = GeometryConversions.FromFlatbuf(feature.Geometry.Value, layer.GeometryType, layer.Dimensions);
            var f        = new NetTopologySuite.Features.Feature(geometry, attributesTable);

            return(f);
        }