コード例 #1
0
        private int GetRecordLength(IFeature feature)
        {
            var geometryBytes = new List <byte>();
            var geometryType  = feature.GeometryType;

            geometryBytes.AddRange(
                BitConverter
                .GetBytes((int)geometryType)
                .Reverse()
                );
            switch (geometryType)
            {
            case GeometryType.Point:
                geometryBytes.AddRange(
                    GeometryToBytes
                    .GetPointBytes(feature.Geometry.BasicGeometry)
                    );
                break;

            case GeometryType.MultiPoint:
                geometryBytes.AddRange(
                    GeometryToBytes
                    .GetMultiPointBytes(feature.Geometry.BasicGeometry)
                    );
                break;

            case GeometryType.PolyLine:
                geometryBytes.AddRange(
                    GeometryToBytes
                    .GetPolyLineBytes(feature.Geometry.BasicGeometry)
                    );
                break;

            case GeometryType.Polygon:
                geometryBytes.AddRange(
                    GeometryToBytes
                    .GetPolygonBytes(feature.Geometry.BasicGeometry)
                    );
                break;

            default:
                break;
            }

            var recordLength = geometryBytes.Count + 8;

            return(recordLength);
        }
コード例 #2
0
        public int WriterRecord(IFeature feature)
        {
            var geometryBytes = new List <byte>();
            var geometryType  = feature.GeometryType;

            if (geometryType == GeometryType.MultiPolyLine)
            {
                geometryBytes.AddRange(
                    BitConverter
                    .GetBytes((int)GeometryType.PolyLine)
                    );
            }
            else if (geometryType == GeometryType.MultiPolygon)
            {
                geometryBytes.AddRange(
                    BitConverter
                    .GetBytes((int)GeometryType.Polygon)
                    );
            }
            else
            {
                geometryBytes.AddRange(
                    BitConverter
                    .GetBytes((int)geometryType)
                    );
            }

            switch (geometryType)
            {
            case GeometryType.Point:
                geometryBytes.AddRange(
                    GeometryToBytes
                    .GetPointBytes(feature.Geometry.BasicGeometry)
                    );
                break;

            case GeometryType.MultiPoint:
                geometryBytes.AddRange(
                    GeometryToBytes
                    .GetMultiPointBytes(feature.Geometry.BasicGeometry)
                    );
                break;

            case GeometryType.PolyLine:
                geometryBytes.AddRange(
                    GeometryToBytes
                    .GetPolyLineBytes(feature.Geometry.BasicGeometry)
                    );
                break;

            case GeometryType.MultiPolyLine:
                geometryBytes.AddRange(
                    GeometryToBytes
                    .GetMultiPolyLineBytes(feature.Geometry.BasicGeometry)
                    );
                break;

            case GeometryType.Polygon:
                geometryBytes.AddRange(
                    GeometryToBytes
                    .GetPolygonBytes(feature.Geometry.BasicGeometry)
                    );
                break;

            default:
                break;
            }

            var recordList = new List <byte>();

            recordList.AddRange(BigOrderBitConverter.GetBytes(feature.Fid + 1));
            var recordLength = geometryBytes.Count + 8;

            recordList.AddRange(BigOrderBitConverter.GetBytes(geometryBytes.Count / 2));
            recordList.AddRange(geometryBytes);

            _shpWriterStream.Write(recordList.ToArray());
            _fileLength += recordList.Count;
            return(recordList.Count);
        }