Ejemplo n.º 1
0
        private void btnCenter_Click(object sender, EventArgs e)
        {
            LLBoundingBox bb = new LLBoundingBox(170, -43, 180, -44, false);
            var           t1 = bb.GetCenter();

            listBox1.Items.Add($"BB Center Test1 Not Radians {t1.Longitude} , {t1.Latitude}");
            LLBoundingBox bb2 = new LLBoundingBox(MapUtil.Deg2Rad(170), MapUtil.Deg2Rad(-43), MapUtil.Deg2Rad(180), MapUtil.Deg2Rad(-44));
            var           t2  = bb2.GetCenter();

            listBox1.Items.Add($"BB Center Test2 Not Radians {MapUtil.Rad2Deg( t2.Longitude)} , {MapUtil.Rad2Deg(t2.Latitude)}");

            var t3 = MapUtil.MidPointRad(new MapPoint(MapUtil.Deg2Rad(170.0), MapUtil.Deg2Rad(-43)), new MapPoint(MapUtil.Deg2Rad(180.0), MapUtil.Deg2Rad(-44.0)));

            listBox1.Items.Add($"BB Center Test3 Not Radians {MapUtil.Rad2Deg(t3.Longitude)} , {MapUtil.Rad2Deg(t3.Latitude)}");
        }
Ejemplo n.º 2
0
        private void btnXYZ_Click(object sender, EventArgs e)
        {
            int lon  = Convert.ToInt32(txtX5.Text);
            int lat  = Convert.ToInt32(txtY5.Text);
            int zoom = Convert.ToInt32(txtZ5.Text);
            var bb   = Geographic.TileXYToRectangleLL(lon, lat, zoom);

            ToDisplay(bb.ToDisplay());

            var midPt = bb.GetCenter();

            ToDisplay($"Mo=idPoint XY ({midPt.Longitude} , {midPt.Latitude})");
            var pt = Coord.geo_to_ecef(new Vector3(MapUtil.Deg2Rad(midPt.Longitude), MapUtil.Deg2Rad(midPt.Latitude), 1)); // zero elevation for now

            //var pt = MapUtil.LatLonToEcef(midPt.Latitude, midPt.Longitude, 0); // zero elevation for now

            ToDisplay($"CenterXYZ {pt.X}, {pt.Y}, {pt.Z}");
        }
Ejemplo n.º 3
0
        public Vector2 MapProject(double lat, double lon)
        {
            if (lat > 83.0)
            {
                lat = 83.0;
            }
            if (lat < -83.0)
            {
                lat = -83.0;
            }

            var x = MapUtil.Deg2Rad(lon);
            var y = MercY(MapUtil.Deg2Rad(lat));

            x = (x - West) * xFactor;
            y = (ymax - y) * yFactor; // y points south
            return(new Vector2(x, y));
        }
Ejemplo n.º 4
0
        private void button5_Click(object sender, EventArgs e)
        {
            /* max boundry in radians
             * double south = -1.4844222297453324;
             * double north = 1.4844222297453322;
             * double east = 3.141592653589793;
             * double west = -3.141592653589793;
             * listBox1.Items.Add($"Val {MapUtil.Rad2Deg(west)}");
             * listBox1.Items.Add($"Val {MapUtil.Rad2Deg(south)}");
             * listBox1.Items.Add($"Val {MapUtil.Rad2Deg(east)}");
             * listBox1.Items.Add($"Val {MapUtil.Rad2Deg(north)}");
             */
            double lon  = MapUtil.Deg2Rad(Convert.ToDouble(txtX4.Text));
            double lat  = MapUtil.Deg2Rad(Convert.ToDouble(txtY4.Text));
            int    zoom = Convert.ToInt32(txtZ4.Text);

//      var res = CesiumMerc.PositionToTileXY(new PointD(lon, lat), zoom);
            var res = CesiumMerc.PositionToTileXY(new PointD(lat, lon), zoom);

            listBox1.Items.Add($"ZXY {(zoom)} / {res.X} / {res.Y}" + ",  CesiumMerc.PositionToTileXY");
        }
Ejemplo n.º 5
0
        private ElevationData GetData(LLBoundingBox bbox, out Vector3[] ecefPoints)
        {
            //todo get data from TRex
            //Boolean dataAvailable = true;
            // if ((lat >= -43.548006 & lat <= -43.547679) & (lon >= 172.632951 & lon <= 172.633542))
            ElevationData ed;

            LLBoundingBox data           = new LLBoundingBox(172.632951, -43.548006, 172.633542, -43.547679);
            bool          dataAvailable  = data.East >= bbox.West && data.West <= bbox.East && data.North >= bbox.South && data.South <= bbox.North;
            LLBoundingBox data2          = new LLBoundingBox(-0.124629, 51.500745, 1.0, 51.6);
            bool          dataAvailable2 = data2.East >= bbox.West && data2.West <= bbox.East && data2.North >= bbox.South && data2.South <= bbox.North;

            int _gridSize;

            if (dataAvailable | dataAvailable2)
            {
                _gridSize = GridSize;
            }
            else
            {
                _gridSize = 2;
            }
            ed         = new ElevationData(_gridSize);
            ecefPoints = new Vector3[_gridSize * _gridSize];

            int PixelCount = _gridSize - 1;

            var    yRange  = bbox.North - bbox.South;
            var    xRange  = bbox.East - bbox.West;
            var    xStep   = xRange / PixelCount;
            var    yStep   = yRange / PixelCount;
            float  minElev = float.PositiveInfinity;
            float  maxElev = float.NegativeInfinity;
            Random rnd     = new Random();
            int    i       = 0;
            float  hgt     = 0;
            var    HgtMode = 2;

            for (int y = 0; y < GridSize; y++)
            {
                for (int x = 0; x < GridSize; x++)
                {
                    var lat = bbox.South + (y * yStep);
                    var lon = bbox.West + (x * xStep);


                    if (HgtMode == 1)
                    {
                        ed.Elev[i] = rnd.Next(1, 8000);
                    }
                    else if (HgtMode == 2)
                    {
                        if ((lat >= -43.548006 & lat <= -43.547679) & (lon >= 172.632951 & lon <= 172.633542))
                        {
                            ed.Elev[i] = (float)10.0;
                        }
                        else if ((lat >= 51.500745 & lat <= 51.6) & (lon >= -0.124629 & lon <= 1.0))
                        {
                            ed.Elev[i] = rnd.Next(1, 10);
                        }
                        else
                        {
                            ed.Elev[i] = 0;
                        }
                    }

                    if (ed.Elev[i] < minElev)
                    {
                        minElev = ed.Elev[i];
                    }

                    if (ed.Elev[i] > maxElev)
                    {
                        maxElev = ed.Elev[i];
                    }

                    // Make ecef point list for later header calculations
                    ecefPoints[i] = Coord.geo_to_ecef(new Vector3()
                    {
                        X = MapUtil.Deg2Rad(lon), Y = MapUtil.Deg2Rad(lat), Z = ed.Elev[i]
                    });

                    i++;
                }
            }

            ed.MaximumHeight = maxElev;
            ed.MinimumHeight = minElev;
            return(ed);
        }
Ejemplo n.º 6
0
        /*
         * https://cesium.com/blog/2013/05/09/computing-the-horizon-occlusion-point/
         * private computeMagnitude(ellipsoid, position, scaledSpaceDirectionToPoint)
         * {
         * var scaledSpacePosition = ellipsoid.transformPositionToScaledSpace(position);
         * var magnitudeSquared = scaledSpacePosition.magnitudeSquared();
         * var magnitude = Math.sqrt(magnitudeSquared);
         * var direction = scaledSpacePosition.divideByScalar(magnitude);
         *
         * // For the purpose of this computation, points below the ellipsoid
         * // are considered to be on it instead.
         * magnitudeSquared = Math.max(1.0, magnitudeSquared);
         * magnitude = Math.max(1.0, magnitude);
         *
         * var cosAlpha = direction.dot(scaledSpaceDirectionToPoint);
         * var sinAlpha = direction.cross(scaledSpaceDirectionToPoint).magnitude();
         * var cosBeta = 1.0 / magnitude;
         * var sinBeta = Math.sqrt(magnitudeSquared - 1.0) * cosBeta;
         *
         * return 1.0 / (cosAlpha * cosBeta - sinAlpha * sinBeta);
         * }
         */

        /// <summary>
        /// By LatLon
        /// </summary>
        /// <param name="bb"></param>
        /// <returns></returns>
        private ElevationData MakeTileDEM(LLBoundingBox bb)
        {
            // todo we also need to comput header info for the quantized mesh


            Vector2 v;

            v.X = 0;
            v.Y = 0;
            int x2         = 0;
            int y2         = 0;
            int PixelCount = GridSize - 1;


            var DoRandom = false;
            int HgtMode  = 2;

            float minElev = float.PositiveInfinity;
            float maxElev = float.NegativeInfinity;

            Random rnd = new Random();

            ElevationData ed = new ElevationData(GridSize);

            var midPt = bb.GetCenter();
            //  var pt2 =  Coord.geo_to_ecef(new Vector3( MapUtil.Deg2Rad(midPt.Longitude), MapUtil.Deg2Rad(midPt.Latitude),0)); // zero elevation for now
            var pt = MapUtil.LatLonToEcef(midPt.Latitude, midPt.Longitude, 0); // zero elevation for now

            Vector3[] ecefPoints = new Vector3[GridSize * GridSize];

            try
            {
                // we are going to walk up from sw to ne for returning dem in latlon coordinates
                var yRange = bb.North - bb.South;
                var xRange = bb.East - bb.West;
                var xStep  = xRange / PixelCount;
                var yStep  = yRange / PixelCount;


                int   i   = 0;
                float hgt = 0;
                for (int y = 0; y < GridSize; y++)
                {
                    for (int x = 0; x < GridSize; x++)
                    {
                        var lat = bb.South + (y * yStep);
                        var lon = bb.West + (x * xStep);
                        v = MapProject(lat, lon); // MapProject is lat long


                        if (v.X >= Width)
                        {
                            v.X = Width - 1;
                        }
                        if (v.Y >= Depth)
                        {
                            v.Y = Depth - 1;
                        }
                        if (v.X < 0)
                        {
                            v.X = 0;
                        }
                        if (v.Y < 0)
                        {
                            v.Y = 0;
                        }

                        x2 = (int)v.X;
                        y2 = (int)v.Y;

                        //hgt = 0;
                        // if (i == 4)
                        //  hgt = 100;

                        if (HgtMode == 1)
                        {
                            ed.Elev[i] = rnd.Next(1, 8000);
                        }
                        else if (HgtMode == 2)
                        {
                            ed.Elev[i] = 0;
                            if (lat >= -43.548006 & lat <= -43.547679)
                            {
                                if (lon >= 172.632951 & lon <= 172.633542)
                                {
                                    ed.Elev[i] = (float)10.0;
                                }
                            }
                        }
                        else
                        {
                            hgt        = Map.GetPixel(x2, y2).GetBrightness(); // 0=black, 1= white
                            ed.Elev[i] = MapUtil.Lerp(0, 1, ElevMin, ElevMax, hgt);
                        }

                        if (ed.Elev[i] < minElev)
                        {
                            minElev = ed.Elev[i];
                        }

                        if (ed.Elev[i] > maxElev)
                        {
                            maxElev = ed.Elev[i];
                        }

                        // Make ecef point list for later calculations
                        ecefPoints[i] = Coord.geo_to_ecef(new Vector3()
                        {
                            X = MapUtil.Deg2Rad(lon), Y = MapUtil.Deg2Rad(lat), Z = ed.Elev[i]
                        });


                        i++;
                    }
                }
            }
            catch (Exception ex)
            {
#if DEBUG
                System.Diagnostics.Debug.WriteLine($"**** MakeTileDEM Exception ****:{ex} v:{v} x2{x2} y2{y2} ");
// file writer        System.Diagnostics.Trace.WriteLine($"**** MakeTileDEM Exception *********:{ex} v:{v} x2{x2} y2{y2} ");
#endif
            }

            // todo now make a ecfc array to calculate header info
            TileInfo tileInfo = new TileInfo();
            var      hdr      = tileInfo.CalculateHeaderInfo(ref ecefPoints, false);
            ed.CenterX = hdr.CenterX;
            ed.CenterY = hdr.CenterY;
            ed.CenterZ = hdr.CenterZ;
            ed.BoundingSphereCenterX = hdr.CenterX;
            ed.BoundingSphereCenterY = hdr.CenterY;
            ed.BoundingSphereCenterZ = hdr.CenterZ;
            ed.BoundingSphereRadius  = hdr.BoundingSphereRadius;
            ed.MaximumHeight         = maxElev;
            ed.MinimumHeight         = minElev;


            var hop = HorizonOcclusionPoint.FromPoints(ecefPoints, tileInfo.BoundingSphere);
            ed.HorizonOcclusionPointX = hop.X;
            ed.HorizonOcclusionPointY = hop.Y;
            ed.HorizonOcclusionPointZ = hop.Z;


            /*
             * // FIXME: is there a better choice for a horizon occlusion point?
             * // Currently it's the center of tile elevated to bbox's max Z
             * header.horizon_occlusion = c;
             * header.horizon_occlusion.z = bbox.max.z;
             *
             *
             * ed.HorizonOcclusionPointX = hdr.CenterX;
             * ed.HorizonOcclusionPointY = hdr.CenterY;
             * ed.HorizonOcclusionPointZ = maxElev;
             */
            return(ed);
        }