예제 #1
0
        /// <summary>
        /// Returns the reference system specified by the attribute.
        /// </summary>
        /// <param name="attribute">The XML attribute.</param>
        /// <param name="referenceSystemFactory">The reference system factory.</param>
        /// <returns>The reference system.</returns>
        private static IReferenceSystem GetReferenceSystem(XAttribute attribute, IReferenceSystemFactory referenceSystemFactory)
        {
            if (attribute == null || referenceSystemFactory == null)
            {
                return(null);
            }

            if (!attribute.Value.Contains(ReferenceSystemUri))
            {
                return(null);
            }

            return(referenceSystemFactory.CreateReferenceSystemFromIdentifier("EPSG::" + attribute.Value.Remove(0, ReferenceSystemUri.Length)));
        }
예제 #2
0
		public void ReferenceSystemFactory(IReferenceSystemFactory referenceSystemFactory
			)
		{
			_config.Put(ReferenceSystemFactoryKey, referenceSystemFactory);
		}
예제 #3
0
		private void InitializeReferenceSystemFactory(Config4Impl config)
		{
			_referenceSystemFactory = config.ReferenceSystemFactory();
		}
예제 #4
0
 public void ReferenceSystemFactory(IReferenceSystemFactory referenceSystemFactory
                                    )
 {
     _config.Put(ReferenceSystemFactoryKey, referenceSystemFactory);
 }
예제 #5
0
        /// <summary>
        /// Converts the geometry from Geography Markup Language (GML) representation.
        /// </summary>
        /// <param name="source">The source string.</param>
        /// <param name="geometryFactory">The geometry factory.</param>
        /// <param name="referenceSystemFactory">The reference system factory.</param>
        /// <returns>The converted geometry.</returns>
        /// <exception cref="System.ArgumentNullException">
        /// The source is null.
        /// or
        /// The geometry factory is null.
        /// or
        /// The reference system factory is null.
        /// </exception>
        /// <exception cref="System.ArgumentException">The specified source is invalid.</exception>
        public static IGeometry ToGeometry(this String source, IGeometryFactory geometryFactory, IReferenceSystemFactory referenceSystemFactory)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }
            if (geometryFactory == null)
            {
                throw new ArgumentNullException(nameof(geometryFactory));
            }
            if (referenceSystemFactory == null)
            {
                throw new ArgumentNullException(nameof(referenceSystemFactory));
            }

            try
            {
                XDocument doc = XDocument.Parse(source);

                return(ToGeometry(doc.Elements(), geometryFactory, referenceSystemFactory));
            }
            catch (Exception ex)
            {
                throw new ArgumentException(CoreMessages.SourceIsInvalid, nameof(source), ex);
            }
        }
예제 #6
0
        /// <summary>
        /// Converts the geometry from Geography Markup Language (GML) representation.
        /// </summary>
        /// <param name="source">The source collection of XML elements.</param>
        /// <param name="geometryFactory">The geometry factory.</param>
        /// <param name="referenceSystemFactory">The reference system factory.</param>
        /// <returns>The converted geometry.</returns>
        /// <exception cref="System.ArgumentNullException">
        /// The source is null.
        /// or
        /// The geometry factory is null.
        /// or
        /// The reference system factory is null.
        /// </exception>
        /// <exception cref="System.ArgumentException">The specified source is invalid.</exception>
        public static IGeometry ToGeometry(this IEnumerable <XElement> source, IGeometryFactory geometryFactory, IReferenceSystemFactory referenceSystemFactory)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }
            if (geometryFactory == null)
            {
                throw new ArgumentNullException(nameof(geometryFactory));
            }
            if (referenceSystemFactory == null)
            {
                throw new ArgumentNullException(nameof(referenceSystemFactory));
            }

            try
            {
                List <IGeometry> geometries = new List <IGeometry>();

                foreach (XElement element in source)
                {
                    geometries.Add(ToGeometry(element, geometryFactory, referenceSystemFactory));
                }

                if (geometries.Count == 0)
                {
                    return(null);
                }

                if (geometries.Count == 1)
                {
                    return(geometries[0]);
                }

                if (geometries.All(geometry => geometry is IPoint))
                {
                    return(geometryFactory.CreateMultiPoint(geometries.Cast <IPoint>()));
                }

                if (geometries.All(geometry => geometry is ILineString))
                {
                    return(geometryFactory.CreateMultiLineString(geometries.Cast <ILineString>()));
                }

                if (geometries.All(geometry => geometry is IPolygon))
                {
                    return(geometryFactory.CreateMultiPolygon(geometries.Cast <IPolygon>()));
                }

                return(geometryFactory.CreateGeometryCollection(geometries));
            }
            catch (Exception ex)
            {
                throw new ArgumentException(CoreMessages.SourceIsInvalid, nameof(source), ex);
            }
        }
예제 #7
0
        /// <summary>
        /// Converts the geometry from Geography Markup Language (GML) representation.
        /// </summary>
        /// <param name="source">The source XML element.</param>
        /// <param name="geometryFactory">The geometry factory.</param>
        /// <param name="referenceSystemFactory">The reference system factory.</param>
        /// <returns>The converted geometry.</returns>
        /// <remarks>
        /// The <see cref="XElement" /> does not contain the namespace attribute for <code>gml</code>
        /// (<code>xmlns:gml="http://www.opengis.net/gml/"</code>), which should be added to a parent node before usage.
        /// </remarks>
        /// <exception cref="System.ArgumentNullException">
        /// The source is null.
        /// or
        /// The geometry factory is null.
        /// or
        /// The reference system factory is null.
        /// </exception>
        /// <exception cref="System.ArgumentException">The specified source is invalid.</exception>
        public static IGeometry ToGeometry(this XElement source, IGeometryFactory geometryFactory, IReferenceSystemFactory referenceSystemFactory)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }
            if (geometryFactory == null)
            {
                throw new ArgumentNullException(nameof(geometryFactory));
            }
            if (referenceSystemFactory == null)
            {
                throw new ArgumentNullException(nameof(referenceSystemFactory));
            }

            IReferenceSystem referenceSystem = GetReferenceSystem(source.Attribute("srsName"), referenceSystemFactory);

            return(ToGeometry(source, geometryFactory.WithReferenceSystem(referenceSystem)));
        }