private static Geometry GetGeometryFromBuffer(byte[] geomBuffer, SpatialReference sr)
        {
            var geomType = GetGeometryType(geomBuffer);

            switch (geomType)
            {
            case GeometryType.Point:
            {
                int    offset = 4;
                double x      = DoubleWithNaN(BitConverter.ToDouble(geomBuffer, offset));
                offset += 8;
                double y = DoubleWithNaN(BitConverter.ToDouble(geomBuffer, offset));

                var mp = MapPointBuilder.FromEsriShape(geomBuffer, sr);
                //System.Diagnostics.Debug.WriteLine($@"x: {x} = {mp.X} y: {y} = {mp.Y}");
                return(mp);
            }

            case GeometryType.Polyline:
            {
                var line = PolylineBuilder.FromEsriShape(geomBuffer, sr);
                return(line);
            }

            case GeometryType.Polygon:
            {
                var poly = PolygonBuilder.FromEsriShape(geomBuffer, sr);
                return(poly);
            }
            }
            return(null);
        }
コード例 #2
0
        private static Geometry FromEsriShapeBuffer([NotNull] byte[] byteArray,
                                                    [CanBeNull] SpatialReference spatialReference)
        {
            var shapeType = EsriShapeFormatUtils.GetShapeType(byteArray);

            if (byteArray.Length == 5 && shapeType == EsriShapeType.EsriShapeNull)
            {
                // in case the original geometry was empty, ExportToWkb does not store byte order nor geometry type.
                throw new ArgumentException(
                          "The provided byte array represents an empty geometry with no geometry type information. Unable to create geometry");
            }

            Geometry result;

            var geometryType = EsriShapeFormatUtils.TranslateEsriShapeType(shapeType);

            switch (geometryType)
            {
            case ProSuiteGeometryType.Point:
                result = MapPointBuilder.FromEsriShape(byteArray, spatialReference);
                break;

            case ProSuiteGeometryType.Polyline:
                result = PolylineBuilder.FromEsriShape(byteArray, spatialReference);
                break;

            case ProSuiteGeometryType.Polygon:
                result = PolygonBuilder.FromEsriShape(byteArray, spatialReference);
                break;

            case ProSuiteGeometryType.Multipoint:
                result = MultipointBuilder.FromEsriShape(byteArray, spatialReference);
                break;

            case ProSuiteGeometryType.MultiPatch:
                result = MultipatchBuilder.FromEsriShape(byteArray, spatialReference);
                break;

            case ProSuiteGeometryType.Bag:
                result = GeometryBagBuilder.FromEsriShape(
                    byteArray, spatialReference);                             // experimental
                break;

            default:
                throw new ArgumentOutOfRangeException(
                          $"Unsupported geometry type {shapeType}");
            }

            return(result);
        }