Exemplo n.º 1
0
        public static ISpatialReference FromSpatialReferenceMsg(
            [CanBeNull] SpatialReferenceMsg spatialRefMsg,
            [CanBeNull] ISpatialReference 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
                                                       : SpatialReferenceUtils.FromXmlString(xml));

            case SpatialReferenceMsg.FormatOneofCase.SpatialReferenceWkid:

                int wkId = spatialRefMsg.SpatialReferenceWkid;

                return(classSpatialRef?.FactoryCode == wkId
                                                       ? classSpatialRef
                                                       : SpatialReferenceUtils.CreateSpatialReference(wkId));

            case SpatialReferenceMsg.FormatOneofCase.SpatialReferenceWkt:

                return(SpatialReferenceUtils.ImportFromESRISpatialReference(
                           spatialRefMsg.SpatialReferenceWkt));

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