Ejemplo n.º 1
0
        public static IGeometry SqlGeometryToGeometry(SqlGeometry geom, GeometryFactory factory)
        {
            if (geom.STIsEmpty())
                return factory.CreateGeometryCollection(null);

            OpenGisGeometryType geometryType = (OpenGisGeometryType)Enum.Parse(typeof(OpenGisGeometryType), geom.STGeometryType().Value);
            switch (geometryType)
            {
                case OpenGisGeometryType.Point:
                    return SqlGeometryToGeometryPoint(geom, factory);
                case OpenGisGeometryType.LineString:
                    return SqlGeometryToGeometryLineString(geom, factory);
                case OpenGisGeometryType.Polygon:
                    return SqlGeometryToGeometryPolygon(geom, factory);
                case OpenGisGeometryType.MultiPoint:
                    return SqlGeometryToGeometryMultiPoint(geom, factory);
                case OpenGisGeometryType.MultiLineString:
                    return SqlGeometryToGeometryMultiLineString(geom, factory);
                case OpenGisGeometryType.MultiPolygon:
                    return SqlGeometryToGeometryMultiPolygon(geom, factory);
                case OpenGisGeometryType.GeometryCollection:
                    return SqlGeometryToGeometryGeometryCollection(geom, factory);
            }

            throw new ArgumentException(string.Format("Cannot convert SqlServer '{0}' to Geometry", geom.STGeometryType()), "geom");
        }
Ejemplo n.º 2
0
        private static IGeometryCollection SqlGeometryToGeometryGeometryCollection(SqlGeometry geometry, GeometryFactory factory)
        {
            IGeometry[] geoms = new IGeometry[geometry.STNumGeometries().Value];
            for (int i = 1; i <= geoms.Length; i++)
                geoms[i - 1] = SqlGeometryToGeometry(geometry.STGeometryN(i), factory);

            return factory.CreateGeometryCollection(geoms);
        }