Exemple #1
0
        private double GetAltitudeFromLatLng(double lat, double lng, bool meters)
        {
            Vector3d testPoint = Coordinates.GeoTo3dDouble(lat, lng);
            Vector2d uv        = DistanceCalc.GetUVFromInnerPoint(TopLeft, TopRight, BottomLeft, BottomRight, testPoint);

            // Get 4 samples and interpolate
            double uud = Math.Max(0, Math.Min(16, (uv.X * 16)));
            double vvd = Math.Max(0, Math.Min(16, (uv.Y * 16)));

            int uu = Math.Max(0, Math.Min(15, (int)(uv.X * 16)));
            int vv = Math.Max(0, Math.Min(15, (int)(uv.Y * 16)));

            double ha = uud - uu;
            double va = vvd - vv;

            if (demArray != null)
            {
                // 4 nearest neighbors
                double ul = demArray[uu + 17 * vv];
                double ur = demArray[(uu + 1) + 17 * vv];
                double ll = demArray[uu + 17 * (vv + 1)];
                double lr = demArray[(uu + 1) + 17 * (vv + 1)];

                double top    = ul * (1 - ha) + ha * ur;
                double bottom = ll * (1 - ha) + ha * lr;
                double val    = top * (1 - va) + va * bottom;

                return(val / (meters ? 1 : DemScaleFactor));
            }

            return(demAverage / (meters ? 1 : DemScaleFactor));
        }
        public override double GetSurfacePointAltitude(double lat, double lng, bool meters)
        {
            if (Level < lastDeepestLevel)
            {
                //interate children
                for (int ii = 0; ii < 4; ii++)
                {
                    Tile child = children[ii];
                    if (child != null)
                    {
                        if (child.IsPointInTile(lat, lng))
                        {
                            double retVal = child.GetSurfacePointAltitude(lat, lng, meters);
                            if (retVal != 0)
                            {
                                return(retVal);
                            }
                            else
                            {
                                break;
                            }
                        }
                    }
                }
            }

            TileTargetLevel = Level;
            TileTargetX     = tileX;
            TileTargetY     = tileY;



            Vector3d testPoint = Coordinates.GeoTo3dDouble(-lat, lng);

            testPoint = Vector3d.SubtractVectors(new Vector3d(), testPoint);
            Vector2d uv = DistanceCalc.GetUVFromInnerPoint(TopLeft.Copy(), TopRight.Copy(), BottomLeft.Copy(), BottomRight.Copy(), testPoint.Copy());


            //Document.Title = "u:" + uv.X + ", v:" + uv.Y;
            //uv.X = 1 - uv.X;
            //uv.Y = 1 - uv.Y;
            // Get 4 samples and interpolate
            double uud = Math.Max(0, Math.Min(16, (uv.X * 16)));
            double vvd = Math.Max(0, Math.Min(16, (uv.Y * 16)));



            int uu = Math.Max(0, Math.Min(15, (int)(uv.X * 16)));
            int vv = Math.Max(0, Math.Min(15, (int)(uv.Y * 16)));

            double ha = uud - uu;
            double va = vvd - vv;

            if (demArray != null)
            {
                // 4 nearest neighbors
                double ul = demArray[uu + 17 * vv];
                double ur = demArray[(uu + 1) + 17 * vv];
                double ll = demArray[uu + 17 * (vv + 1)];
                double lr = demArray[(uu + 1) + 17 * (vv + 1)];

                double top    = ul * (1 - ha) + ha * ur;
                double bottom = ll * (1 - ha) + ha * lr;
                double val    = top * (1 - va) + va * bottom;

                return(val / DemScaleFactor);
            }

            return(demAverage / DemScaleFactor);
        }