Esempio n. 1
0
        /**
         *
         */
        private HGTReader PrepReader(int res, int row, int col)
        {
            if (row >= readers.Length)
            {
                //log.error("invalid array index for row", row);
                return(null);
            }
            if (col >= readers[row].Length)
            {
                //log.error("invalid array index for col", row);
                return(null);
            }
            HGTReader rdr = readers[row][col];

            if (rdr == null)
            {
                //statRdrNull++;
                return(null);
            }

            // do not use if different resolution
            if (res != rdr.GetRes())
            {
                //statRdrRes++;
                return(null);
            }

            rdr.PrepRead();
            if (row > lastRow)
            {
                lastRow = row;
            }

            return(rdr);
        }
Esempio n. 2
0
        protected double GetElevation(int lat32, int lon32)
        {
            int row = (int)((lat32 - minLat32) * FACTOR);
            int col = (int)((lon32 - minLon32) * FACTOR);

            HGTReader rdr = readers[row][col];

            if (rdr == null)
            {
                // no reader : ocean or missing file
                return(outsidePolygonHeight);
            }
            int res = rdr.GetRes();

            rdr.PrepRead();
            if (res <= 0)
            {
                return(0); // assumed to be an area in the ocean
            }

            lastRow = row;

            double scale = res * FACTOR;

            double y1      = (lat32 - minLat32) * scale - row * res;
            double x1      = (lon32 - minLon32) * scale - col * res;
            int    xLeft   = (int)x1;
            int    yBottom = (int)y1;
            double qx      = x1 - xLeft;
            double qy      = y1 - yBottom;


            //statPoints++;
            if (useComplexInterpolation)
            {
                // bicubic (Catmull-Rom) interpolation with 16 points
                bool filled = FillArray(rdr, row, col, xLeft, yBottom);
                if (filled)
                {
                    h = BicubicInterpolation(eleArray, qx, qy);
                    //statBicubic++;
                }
            }

            if (h == HGTReader.UNDEF || !useComplexInterpolation)
            {
                // use bilinear interpolation if bicubic not available
                int xRight = xLeft + 1;
                int yTop   = yBottom + 1;

                int hLT = rdr.Ele(xLeft, yTop);
                maxhöhe = Math.Max(maxhöhe, hLT);
                minhöhe = Math.Min(minhöhe, hLT);
                int hRT = rdr.Ele(xRight, yTop);
                maxhöhe = Math.Max(maxhöhe, hRT);
                minhöhe = Math.Min(minhöhe, hRT);
                int hLB = rdr.Ele(xLeft, yBottom);
                maxhöhe = Math.Max(maxhöhe, hLB);
                minhöhe = Math.Min(minhöhe, hLB);
                int hRB = rdr.Ele(xRight, yBottom);
                maxhöhe = Math.Max(maxhöhe, hRB);
                minhöhe = Math.Min(minhöhe, hRB);


                h = InterpolatedHeight(qx, qy, hLT, hRT, hRB, hLB);
                //statBilinear++;
                //if (h == HGTReader.UNDEF) statVoid++;
            }

            //if (h == HGTReader.UNDEF && log.isLoggable(Level.WARNING))
            //{
            //    double lon = lon32 * FACTOR;
            //    double lat = lat32 * FACTOR;
            //    Coord c = new Coord(lat, lon);
            //    log.warn("height interpolation returns void at", c.toDegreeString());
            //}
            return(h);
        }