public override bool IsPointInTile(double lat, double lng)
        {
            if (Level == 0)
            {
                return(true);
            }

            if (Level == 1)
            {
                if ((lng >= 0 && lng <= 90) && (tileX == 0 && tileY == 1))
                {
                    return(true);
                }
                if ((lng > 90 && lng <= 180) && (tileX == 1 && tileY == 1))
                {
                    return(true);
                }
                if ((lng < 0 && lng >= -90) && (tileX == 0 && tileY == 0))
                {
                    return(true);
                }
                if ((lng < -90 && lng >= -180) && (tileX == 1 && tileY == 0))
                {
                    return(true);
                }
                return(false);
            }

            if (!this.DemReady || this.DemData == null)
            {
                return(false);
            }

            Vector3d testPoint = Coordinates.GeoTo3dDouble(-lat, lng);
            bool     top       = IsLeftOfHalfSpace(TopLeft.Copy(), TopRight.Copy(), testPoint);
            bool     right     = IsLeftOfHalfSpace(TopRight.Copy(), BottomRight.Copy(), testPoint);
            bool     bottom    = IsLeftOfHalfSpace(BottomRight.Copy(), BottomLeft.Copy(), testPoint);
            bool     left      = IsLeftOfHalfSpace(BottomLeft.Copy(), TopLeft.Copy(), testPoint);

            if (top && right && bottom && left)
            {
                // showSelected = true;
                return(true);
            }
            return(false);;
        }
        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);
        }