/** * Performs a NTv2 grid file lookup given its name, and checks for file format correctness. * * @param name The NTv2 grid file name * @return {@code true} if file exists and is valid, {@code false} otherwise */ public boolean isNTv2Grid(URL location) { if (location != null) { return isNTv2GridFileValid(location); // Check } else { return false; } }
/** * Constructs a {@code NTv2Transform} from the specified grid shift file. * * <p>This constructor checks for grid shift file availability, but doesn't actually load the * full grid into memory to preserve resources. * * @param file NTv2 grid file name * @throws NoSuchIdentifierException if the grid is not available. */ public NTv2Transform(URI file) throws NoSuchIdentifierException { if (file == null) { throw new NoSuchIdentifierException("No NTv2 Grid File specified.", null); } this.grid = file; gridLocation = locateGrid(grid.toString()); if (gridLocation == null) { throw new NoSuchIdentifierException("Could not locate NTv2 Grid File " + file, null); } // Search for grid file if (!FACTORY.isNTv2Grid(gridLocation)) { throw new NoSuchIdentifierException("NTv2 Grid File not available.", file.toString()); } }
gridShift = FACTORY.createNTv2Grid(gridLocation); } catch (FactoryException e) { throw new TransformException(
/** * Instantiates the test {@link NTv2GridShiftFactory} * * @throws java.lang.Exception */ @Before public void setUp() throws Exception { factory = new NTv2GridShiftFactory(); }
/** * Creates a NTv2 Grid. * * @param name The NTv2 grid name * @return the grid * @throws FactoryException if grid cannot be created */ public GridShiftFile createNTv2Grid(URL gridLocation) throws FactoryException { if (gridLocation == null) { throw new FactoryException("The grid location must be not null"); } synchronized (ntv2GridCache) { // Prevent simultaneous threads trying to load same grid GridShiftFile grid = ntv2GridCache.get(gridLocation.toExternalForm()); if (grid != null) { // Cached: return grid; // - Return } else { // Not cached: if (gridLocation != null) { grid = loadNTv2Grid(gridLocation); // - Load if (grid != null) { ntv2GridCache.put(gridLocation.toExternalForm(), grid); // - Cache return grid; // - Return } } throw new FactoryException("NTv2 Grid " + gridLocation + " could not be created."); } } }
/** * Test method for {@link * org.geotools.referencing.factory.gridshift.NTv2GridShiftFactory#isNTv2Grid(java.lang.String)}. */ @Test public void testIsNTv2GridAvailable() { assertFalse(factory.isNTv2Grid(null)); assertFalse(factory.isNTv2Grid(INEXISTENT_GRID)); // Will log a FINEST message assertFalse(factory.isNTv2Grid(MALFORMED_GRID)); // Will log a WARNING message assertTrue(factory.isNTv2Grid(TEST_GRID)); }
factory.createNTv2Grid(null); } catch (FactoryException e) { factoryExceptionThrown = true; factory.createNTv2Grid(INEXISTENT_GRID); // Will log a FINEST message } catch (FactoryException e) { factoryExceptionThrown = true; factory.createNTv2Grid(MALFORMED_GRID); // Will log a SEVERE message } catch (FactoryException e) { factoryExceptionThrown = true; GridShiftFile grid = null; try { grid = factory.createNTv2Grid(TEST_GRID); } catch (FactoryException e) { factoryExceptionThrown = true;