Beispiel #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);
        }
Beispiel #2
0
        public static SpatialReference FromSpatialReferenceMsg(
            [CanBeNull] SpatialReferenceMsg spatialRefMsg,
            [CanBeNull] SpatialReference classSpatialRef = null)
        {
            if (spatialRefMsg == null)
            {
                return(null);
            }

            switch (spatialRefMsg.FormatCase)
            {
            case SpatialReferenceMsg.FormatOneofCase.None:
                return(null);

            case SpatialReferenceMsg.FormatOneofCase.SpatialReferenceEsriXml:

                string xml = spatialRefMsg.SpatialReferenceEsriXml;

                return(string.IsNullOrEmpty(xml)
                                                       ? null
                                                       : SpatialReferenceBuilder.FromXML(xml));

            case SpatialReferenceMsg.FormatOneofCase.SpatialReferenceWkid:

                int wkId = spatialRefMsg.SpatialReferenceWkid;

                return(classSpatialRef?.Wkid == wkId
                                                       ? classSpatialRef
                                                       : SpatialReferenceBuilder.CreateSpatialReference(wkId));

            case SpatialReferenceMsg.FormatOneofCase.SpatialReferenceWkt:

                return(SpatialReferenceBuilder.CreateSpatialReference(
                           spatialRefMsg.SpatialReferenceWkt));

            default:
                throw new NotImplementedException(
                          $"Unsupported spatial reference format: {spatialRefMsg.FormatCase}");
            }
        }
        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);
        }