Пример #1
0
        /// <summary>
        /// converts the map's/datasource's bbox to geographic bbox
        /// </summary>
        /// <param name="bb"></param>
        /// <returns></returns>
        protected EX_GeographicBoundingBox ConvertToGeographicBoundingBox(BoundingBox bb)
        {
            //output object
            EX_GeographicBoundingBox bbox = new EX_GeographicBoundingBox();


            //coordinate projection transformation
            DotSpatial.Projections.ProjectionInfo pTo   = DotSpatial.Projections.KnownCoordinateSystems.Geographic.World.WGS1984;
            DotSpatial.Projections.ProjectionInfo pFrom = null;

            pFrom = DotSpatial.Projections.ProjectionInfo.FromEpsgCode(this.SRID);

            double minx, miny, maxx, maxy;

            if (pFrom == null)
            {
                //from projection not known so just assume world coords
                minx = -180;
                miny = -90;
                maxx = 180;
                maxy = 90;
            }
            else
            {
                //projecton seems to be ok, so reproject
                //coordinate pairs
                double[] points = new double[4];

                points[0] = bb.minx;
                points[1] = bb.miny;

                points[2] = bb.maxx;
                points[3] = bb.maxy;

                double[] z = { 1 };

                DotSpatial.Projections.Reproject.ReprojectPoints(points, z, pFrom, pTo, 0, 2);

                minx = points[0];
                miny = points[1];
                maxx = points[2];
                maxy = points[3];
            }


            //transfer values
            bbox.westBoundLongitude = minx;
            bbox.southBoundLatitude = miny;
            bbox.eastBoundLongitude = maxx;
            bbox.northBoundLatitude = maxy;

            //and return the object
            return(bbox);
        }
Пример #2
0
        public void InitFromGeometry_ShouldCreateValidBoundingBox(string wkt, double east, double north, double south, double west)
        {
            var wgs84=CommonServiceLocator.GetCoordinateSystemProvider().Wgs84;
            var builder=new Ogc.Gml.V311.GmlGeometryBuilder(wgs84);
            builder.Parse(wkt, wgs84);
            var input=builder.ConstructedGeometry;

            var res=new EX_GeographicBoundingBox();
            res.InitFromGeometry(input);

            Assert.Equal(east, (double)res.eastBoundLongitude.Decimal.TypedValue);
            Assert.Equal(north, (double)res.northBoundLatitude.Decimal.TypedValue);
            Assert.Equal(south, (double)res.southBoundLatitude.Decimal.TypedValue);
            Assert.Equal(west, (double)res.westBoundLongitude.Decimal.TypedValue);
        }
Пример #3
0
        public void InitFromGeometry_ShouldCreateValidBoundingBox(string wkt, double east, double north, double south, double west)
        {
            var wgs84   = CommonServiceLocator.GetCoordinateSystemProvider().Wgs84;
            var builder = new Ogc.Gml.V311.GmlGeometryBuilder(wgs84);

            builder.Parse(wkt, wgs84);
            var input = builder.ConstructedGeometry;

            var res = new EX_GeographicBoundingBox();

            res.InitFromGeometry(input);

            Assert.Equal(east, (double)res.eastBoundLongitude.Decimal.TypedValue);
            Assert.Equal(north, (double)res.northBoundLatitude.Decimal.TypedValue);
            Assert.Equal(south, (double)res.southBoundLatitude.Decimal.TypedValue);
            Assert.Equal(west, (double)res.westBoundLongitude.Decimal.TypedValue);
        }