コード例 #1
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);
        }
コード例 #2
0
        private static IssueMsg CreateIssueProto(
            [NotNull] IssueFoundEventArgs args,
            [NotNull] IBackgroundVerificationInputs backgroundVerificationInputs)
        {
            QualityCondition qualityCondition =
                args.QualitySpecificationElement.QualityCondition;

            IssueMsg issueProto = new IssueMsg();

            issueProto.ConditionId   = qualityCondition.Id;
            issueProto.Allowable     = args.IsAllowable;
            issueProto.StopCondition = args.Issue.StopCondition;

            CallbackUtils.DoWithNonNull(
                args.Issue.Description, s => issueProto.Description = s);

            IssueCode issueCode = args.Issue.IssueCode;

            if (issueCode != null)
            {
                CallbackUtils.DoWithNonNull(
                    issueCode.ID, s => issueProto.IssueCodeId = s);

                CallbackUtils.DoWithNonNull(
                    issueCode.Description, s => issueProto.IssueCodeDescription = s);
            }

            CallbackUtils.DoWithNonNull(
                args.Issue.AffectedComponent,
                (value) => issueProto.AffectedComponent = value);

            issueProto.InvolvedTables.AddRange(GetInvolvedTableMessages(args.Issue.InvolvedTables));

            CallbackUtils.DoWithNonNull(
                args.LegacyInvolvedObjectsString,
                (value) => issueProto.LegacyInvolvedRows = value);

            IVerificationContext verificationContext =
                Assert.NotNull(backgroundVerificationInputs.VerificationContext);

            var supportedGeometryTypes =
                GetSupportedErrorRepoGeometryTypes(verificationContext).ToList();

            // create valid Error geometry (geometry type, min dimensions) if possible
            IGeometry geometry = ErrorRepositoryUtils.GetGeometryToStore(
                args.ErrorGeometry,
                verificationContext.SpatialReferenceDescriptor.SpatialReference,
                supportedGeometryTypes);

            issueProto.IssueGeometry =
                ProtobufGeometryUtils.ToShapeMsg(geometry);

            // NOTE: Multipatches are not restored from byte arrays in EsriShape (10.6.1)
            ShapeMsg.FormatOneofCase format =
                geometry?.GeometryType == esriGeometryType.esriGeometryMultiPatch
                                        ? ShapeMsg.FormatOneofCase.Wkb
                                        : ShapeMsg.FormatOneofCase.EsriShape;

            issueProto.IssueGeometry =
                ProtobufGeometryUtils.ToShapeMsg(geometry, format);

            issueProto.CreationDateTimeTicks = DateTime.Now.Ticks;

            //issueProto.IsInvalidException = args.us;

            //if (args.IsAllowed)
            //{
            //	issueProto.ExceptedObjRef = new GdbObjRefMsg()
            //	                            {
            //		                            ClassHandle = args.AllowedErrorRef.ClassId,
            //		                            ObjectId = args.AllowedErrorRef.ObjectId
            //	                            };
            //}

            return(issueProto);
        }