Esempio n. 1
0
        /// <summary>
        /// Converts any <see cref="SharpMap.Geometries.Geometry"/> to the correspondant
        /// <see cref="GisSharpBlog.NetTopologySuite.Geometries.Geometry"/>.
        /// </summary>
        public static Geometries.Geometry ToSharpMapGeometry(NTSGeometry geometry)
        {
            if (geometry == null)
            {
                throw new NullReferenceException("geometry");
            }

            if (TypeOf(geometry, typeof(NTSPoint)))
            {
                return(ToSharpMapPoint(geometry as NTSPoint));
            }

            if (TypeOf(geometry, typeof(NTSLineString)))
            {
                return(ToSharpMapLineString(geometry as NTSLineString));
            }

            if (TypeOf(geometry, typeof(NTSPolygon)))
            {
                return(ToSharpMapPolygon(geometry as NTSPolygon));
            }

            if (TypeOf(geometry, typeof(NTSMultiPoint)))
            {
                return(ToSharpMapMultiPoint(geometry as NTSMultiPoint));
            }

            if (TypeOf(geometry, typeof(NTSMultiLineString)))
            {
                return(ToSharpMapMultiLineString(geometry as NTSMultiLineString));
            }

            if (TypeOf(geometry, typeof(NTSMultiPolygon)))
            {
                return(ToSharpMapMultiPolygon(geometry as NTSMultiPolygon));
            }

            if (TypeOf(geometry, typeof(NTSGeometryCollection)))
            {
                return(ToSharpMapGeometryCollection(geometry as NTSGeometryCollection));
            }

            var message = String.Format("Type {0} not supported", geometry.GetType().FullName);

            throw new NotSupportedException(message);
        }
Esempio n. 2
0
        private static bool TypeOf(NTSGeometry geometry, Type type)
        {
            if (geometry == null)
            {
                throw new ArgumentNullException("geometry");
            }
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }

            var interfaces = geometry.GetType().GetInterfaces();

            foreach (Type item in interfaces)
            {
                if (item == type)
                {
                    return(true);
                }
            }
            return(false);
        }
Esempio n. 3
0
        private static bool TypeOf(NTSGeometry geometry, Type type)
        {
            if (geometry == null)
                throw new ArgumentNullException("geometry");
            if (type == null)
                throw new ArgumentNullException("type");

            var interfaces = geometry.GetType().GetInterfaces();
            foreach (Type item in interfaces)
                if (item == type)
                    return true;
            return false;
        }
Esempio n. 4
0
        /// <summary>
        /// Converts any <see cref="SharpMap.Geometries.Geometry"/> to the correspondant 
        /// <see cref="GisSharpBlog.NetTopologySuite.Geometries.Geometry"/>.
        /// </summary>
        public static Geometries.Geometry ToSharpMapGeometry(NTSGeometry geometry)
        {
            if (geometry == null)
                throw new NullReferenceException("geometry");

            if (TypeOf(geometry, typeof(NTSPoint)))
                return ToSharpMapPoint(geometry as NTSPoint);

            if (TypeOf(geometry, typeof (NTSLineString)))
                return ToSharpMapLineString(geometry as NTSLineString);

            if (TypeOf(geometry, typeof (NTSPolygon)))
                return ToSharpMapPolygon(geometry as NTSPolygon);

            if (TypeOf(geometry, typeof (NTSMultiPoint)))
                return ToSharpMapMultiPoint(geometry as NTSMultiPoint);

            if (TypeOf(geometry, typeof (NTSMultiLineString)))
                return ToSharpMapMultiLineString(geometry as NTSMultiLineString);

            if (TypeOf(geometry, typeof (NTSMultiPolygon)))
                return ToSharpMapMultiPolygon(geometry as NTSMultiPolygon);

            if (TypeOf(geometry, typeof (NTSGeometryCollection)))
                return ToSharpMapGeometryCollection(geometry as NTSGeometryCollection);

            var message = String.Format("Type {0} not supported", geometry.GetType().FullName);
            throw new NotSupportedException(message);
        }