コード例 #1
0
ファイル: B3dm.cs プロジェクト: zhuowp/b3dm-tile-cs
        public byte[] ToBytes()
        {
            var header_length = 28;

            var featureTableJson   = BufferPadding.AddPadding(FeatureTableJson, header_length);
            var batchTableJson     = BufferPadding.AddPadding(BatchTableJson);
            var featureTableBinary = BufferPadding.AddPadding(FeatureTableBinary);
            var batchTableBinary   = BufferPadding.AddPadding(BatchTableBinary);

            B3dmHeader.ByteLength = GlbData.Length + header_length + featureTableJson.Length + batchTableJson.Length + batchTableBinary.Length + FeatureTableBinary.Length;

            B3dmHeader.FeatureTableJsonByteLength   = featureTableJson.Length;
            B3dmHeader.BatchTableJsonByteLength     = batchTableJson.Length;
            B3dmHeader.FeatureTableBinaryByteLength = featureTableBinary.Length;
            B3dmHeader.BatchTableBinaryByteLength   = batchTableBinary.Length;

            var memoryStream = new MemoryStream();
            var binaryWriter = new BinaryWriter(memoryStream);

            binaryWriter.Write(B3dmHeader.AsBinary());
            binaryWriter.Write(Encoding.UTF8.GetBytes(featureTableJson));
            if (featureTableBinary != null)
            {
                binaryWriter.Write(featureTableBinary);
            }
            binaryWriter.Write(Encoding.UTF8.GetBytes(batchTableJson));
            if (batchTableBinary != null)
            {
                binaryWriter.Write(batchTableBinary);
            }
            binaryWriter.Write(GlbData);
            binaryWriter.Flush();
            binaryWriter.Close();
            return(memoryStream.ToArray());
        }
コード例 #2
0
ファイル: B3dm.cs プロジェクト: zhuowp/b3dm-tile-cs
 public B3dm()
 {
     B3dmHeader         = new B3dmHeader();
     FeatureTableJson   = string.Empty;
     BatchTableJson     = string.Empty;
     FeatureTableJson   = "{\"BATCH_LENGTH\":0}  ";
     FeatureTableBinary = new byte[0];
     BatchTableBinary   = new byte[0];
 }
コード例 #3
0
ファイル: B3dmReader.cs プロジェクト: zhuowp/b3dm-tile-cs
        public static B3dm ReadB3dm(BinaryReader reader)
        {
            var b3dmHeader        = new B3dmHeader(reader);
            var featureTableJson  = Encoding.UTF8.GetString(reader.ReadBytes(b3dmHeader.FeatureTableJsonByteLength));
            var featureTableBytes = reader.ReadBytes(b3dmHeader.FeatureTableBinaryByteLength);
            var batchTableJson    = Encoding.UTF8.GetString(reader.ReadBytes(b3dmHeader.BatchTableJsonByteLength));
            var batchTableBytes   = reader.ReadBytes(b3dmHeader.BatchTableBinaryByteLength);

            var glbLength = b3dmHeader.ByteLength - b3dmHeader.Length;
            var glbBuffer = reader.ReadBytes(glbLength);

            var b3dm = new B3dm {
                B3dmHeader         = b3dmHeader,
                GlbData            = glbBuffer,
                FeatureTableJson   = featureTableJson,
                FeatureTableBinary = featureTableBytes,
                BatchTableJson     = batchTableJson,
                BatchTableBinary   = batchTableBytes
            };

            return(b3dm);
        }
コード例 #4
0
        public static B3dm ReadB3dm(Stream stream)
        {
            using (var reader = new BinaryReader(stream)) {
                var b3dmHeader        = new B3dmHeader(reader);
                var featureTableJson  = Encoding.UTF8.GetString(reader.ReadBytes(b3dmHeader.FeatureTableJsonByteLength));
                var featureTableBytes = reader.ReadBytes(b3dmHeader.FeatureTableBinaryByteLength);
                var batchTableJson    = Encoding.UTF8.GetString(reader.ReadBytes(b3dmHeader.BatchTableJsonByteLength));
                var batchTableBytes   = reader.ReadBytes(b3dmHeader.BatchTableBinaryByteLength);

                var glbLength = (int)(reader.BaseStream.Length - reader.BaseStream.Position);
                var glbBuffer = reader.ReadBytes(glbLength);

                var b3dm = new B3dm {
                    B3dmHeader         = b3dmHeader,
                    GlbData            = glbBuffer,
                    FeatureTableJson   = featureTableJson,
                    FeatureTableBinary = featureTableBytes,
                    BatchTableJson     = batchTableJson,
                    BatchTableBinary   = batchTableBytes
                };
                return(b3dm);
            }
        }