Ejemplo n.º 1
0
        public static SpatialReferenceMsg ToSpatialReferenceMsg(
            [CanBeNull] SpatialReference spatialReference,
            SpatialReferenceMsg.FormatOneofCase format)
        {
            if (spatialReference == null)
            {
                return(null);
            }

            SpatialReferenceMsg result = new SpatialReferenceMsg();

            switch (format)
            {
            case SpatialReferenceMsg.FormatOneofCase.None:
                break;

            case SpatialReferenceMsg.FormatOneofCase.SpatialReferenceEsriXml:
                result.SpatialReferenceEsriXml = spatialReference.ToXML();
                break;

            case SpatialReferenceMsg.FormatOneofCase.SpatialReferenceWkid:
                result.SpatialReferenceWkid = spatialReference.Wkid;
                break;

            case SpatialReferenceMsg.FormatOneofCase.SpatialReferenceWkt:
                result.SpatialReferenceWkt = spatialReference.Wkt;
                break;

            default:
                throw new NotImplementedException(
                          $"Unsupported spatial reference format: {format}");
            }

            return(result);
        }
Ejemplo n.º 2
0
        public static ShapeMsg ToShapeMsg(
            [CanBeNull] IGeometry geometry,
            ShapeMsg.FormatOneofCase format = ShapeMsg.FormatOneofCase.EsriShape,
            SpatialReferenceMsg.FormatOneofCase spatialRefFormat =
            SpatialReferenceMsg.FormatOneofCase.SpatialReferenceWkid)
        {
            if (geometry == null)
            {
                return(null);
            }

            Assert.ArgumentCondition(format == ShapeMsg.FormatOneofCase.EsriShape ||
                                     format == ShapeMsg.FormatOneofCase.Wkb,
                                     "Unsupported format");

            if (_msg.IsVerboseDebugEnabled)
            {
                _msg.DebugFormat("Converting geometry {0} to shape msg",
                                 GeometryUtils.ToString(geometry));
            }

            var highLevelGeometry =
                GeometryUtils.GetHighLevelGeometry(geometry, true);

            var result = new ShapeMsg();

            if (format == ShapeMsg.FormatOneofCase.EsriShape)
            {
                result.EsriShape = ByteString.CopyFrom(
                    GeometryUtils.ToEsriShapeBuffer(highLevelGeometry));
            }
            else
            {
                var    wkbWriter = new WkbGeometryWriter();
                byte[] wkb       = wkbWriter.WriteGeometry(highLevelGeometry);
                result.Wkb = ByteString.CopyFrom(wkb);
            }

            if (geometry.SpatialReference != null)
            {
                result.SpatialReference =
                    ToSpatialReferenceMsg(geometry.SpatialReference, spatialRefFormat);
            }

            if (highLevelGeometry != geometry)
            {
                _msg.DebugFormat(
                    "Geometry was converted to high-level geometry to encode.");

                Marshal.ReleaseComObject(highLevelGeometry);
            }

            return(result);
        }
Ejemplo n.º 3
0
        public static GdbObjectMsg ToGdbObjectMsg(
            [NotNull] IObject featureOrObject,
            [CanBeNull] IGeometry geometry,
            int objectClassHandle,
            SpatialReferenceMsg.FormatOneofCase spatialRefFormat =
            SpatialReferenceMsg.FormatOneofCase.SpatialReferenceWkid)
        {
            var result = new GdbObjectMsg();

            result.ClassHandle = objectClassHandle;

            result.ObjectId = featureOrObject.OID;

            result.Shape =
                ProtobufGeometryUtils.ToShapeMsg(geometry, ShapeMsg.FormatOneofCase.EsriShape,
                                                 spatialRefFormat);

            return(result);
        }
Ejemplo n.º 4
0
        public static SpatialReferenceMsg ToSpatialReferenceMsg(
            [CanBeNull] ISpatialReference spatialReference,
            SpatialReferenceMsg.FormatOneofCase format)
        {
            if (spatialReference == null)
            {
                return(null);
            }

            SpatialReferenceMsg result = new SpatialReferenceMsg();

            switch (format)
            {
            case SpatialReferenceMsg.FormatOneofCase.None:
                break;

            case SpatialReferenceMsg.FormatOneofCase.SpatialReferenceEsriXml:
                result.SpatialReferenceEsriXml = SpatialReferenceUtils.ToXmlString(
                    spatialReference);
                break;

            case SpatialReferenceMsg.FormatOneofCase.SpatialReferenceWkid:
                result.SpatialReferenceWkid = spatialReference.FactoryCode;
                break;

            case SpatialReferenceMsg.FormatOneofCase.SpatialReferenceWkt:
                result.SpatialReferenceWkt =
                    SpatialReferenceUtils.ExportToESRISpatialReference(spatialReference);
                break;

            default:
                throw new NotImplementedException(
                          $"Unsupported spatial reference format: {format}");
            }

            return(result);
        }