protected ArrayList<SquareZone> createSquaresGrid( int UTMZone, String hemisphere, Sector UTMZoneSector, double minEasting, double maxEasting, double minNorthing, double maxNorthing) { ArrayList<SquareZone> squares = new ArrayList<SquareZone>(); double startEasting = Math.floor(minEasting / ONEHT) * ONEHT; double startNorthing = Math.floor(minNorthing / ONEHT) * ONEHT; int cols = (int) Math.ceil((maxEasting - startEasting) / ONEHT); int rows = (int) Math.ceil((maxNorthing - startNorthing) / ONEHT); SquareZone[][] squaresArray = new SquareZone[rows][cols]; int col = 0; for (double easting = startEasting; easting < maxEasting; easting += ONEHT) { int row = 0; for (double northing = startNorthing; northing < maxNorthing; northing += ONEHT) { SquareZone sz = new SquareZone(UTMZone, hemisphere, UTMZoneSector, easting, northing, ONEHT); if (sz.boundingSector != null && !sz.isOutsideGridZone()) { squares.add(sz); squaresArray[row][col] = sz; } row++; } col++; } // Keep track of neighbors for (col = 0; col < cols; col++) { for (int row = 0; row < rows; row++) { SquareZone sz = squaresArray[row][col]; if (sz != null) { sz.setNorthNeighbor(row + 1 < rows ? squaresArray[row + 1][col] : null); sz.setEastNeighbor(col + 1 < cols ? squaresArray[row][col + 1] : null); } } } return squares; }