コード例 #1
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);
        }
コード例 #2
0
        public static GdbObjectMsg ToGdbObjectMsg([NotNull] IObject featureOrObject,
                                                  bool includeSpatialRef  = false,
                                                  bool includeFieldValues = false)
        {
            var result = new GdbObjectMsg();

            result.ClassHandle = featureOrObject.Class.ObjectClassID;

            result.ObjectId = featureOrObject.OID;

            if (featureOrObject is IFeature feature)
            {
                IGeometry featureShape = GdbObjectUtils.GetFeatureShape(feature);

                result.Shape = ProtobufGeometryUtils.ToShapeMsg(
                    featureShape, ShapeMsg.FormatOneofCase.EsriShape,
                    includeSpatialRef
                                                ? SpatialReferenceMsg.FormatOneofCase.SpatialReferenceEsriXml
                                                : SpatialReferenceMsg.FormatOneofCase.SpatialReferenceWkid);
            }

            if (includeFieldValues)
            {
                for (int i = 0; i < featureOrObject.Fields.FieldCount; i++)
                {
                    IField field = featureOrObject.Fields.Field[i];

                    object valueObject = featureOrObject.Value[i];

                    var attributeValue = new AttributeValue();

                    result.Values.Add(attributeValue);

                    if (valueObject == DBNull.Value || valueObject == null)
                    {
                        attributeValue.DbNull = true;
                    }
                    else
                    {
                        switch (field.Type)
                        {
                        case esriFieldType.esriFieldTypeSmallInteger:
                            attributeValue.ShortIntValue = (int)valueObject;
                            break;

                        case esriFieldType.esriFieldTypeInteger:
                            attributeValue.LongIntValue = (int)valueObject;
                            break;

                        case esriFieldType.esriFieldTypeSingle:
                            attributeValue.ShortIntValue = (int)valueObject;
                            break;

                        case esriFieldType.esriFieldTypeDouble:
                            attributeValue.DoubleValue = (double)valueObject;
                            break;

                        case esriFieldType.esriFieldTypeString:
                            attributeValue.StringValue = (string)valueObject;
                            break;

                        case esriFieldType.esriFieldTypeDate:
                            attributeValue.DateTimeTicksValue = ((DateTime)valueObject).Ticks;
                            break;

                        case esriFieldType.esriFieldTypeOID:
                            attributeValue.ShortIntValue = (int)valueObject;
                            break;

                        case esriFieldType.esriFieldTypeGeometry:
                            // Leave empty, it is sent through Shape property
                            break;

                        case esriFieldType.esriFieldTypeBlob:
                            // TODO: Test and make this work
                            attributeValue.BlobValue =
                                ByteString.CopyFrom((byte[])valueObject);
                            break;

                        case esriFieldType.esriFieldTypeRaster:
                            // Not supported, ignore
                            break;

                        case esriFieldType.esriFieldTypeGUID:
                            byte[] asBytes = new Guid((string)valueObject).ToByteArray();
                            attributeValue.UuidValue =
                                new UUID {
                                Value = ByteString.CopyFrom(asBytes)
                            };
                            break;

                        case esriFieldType.esriFieldTypeGlobalID:
                            asBytes = new Guid((string)valueObject).ToByteArray();
                            attributeValue.UuidValue =
                                new UUID {
                                Value = ByteString.CopyFrom(asBytes)
                            };
                            break;

                        case esriFieldType.esriFieldTypeXML:
                            // Not supported, ignore
                            break;

                        default:
                            throw new ArgumentOutOfRangeException();
                        }
                    }
                }
            }

            return(result);
        }