@Test public void testEqualProjectionsWithProjParamsNullParamsAreNotEqual() throws Exception { HdfEosGridInfo gridInfo1 = new HdfEosGridInfo("testName", -120, 50, -100, 40, "Sinusoidal"); gridInfo1.setProjectionParameter(PROJ_PARAMS); HdfEosGridInfo gridInfo2 = new HdfEosGridInfo("testName", -120, 50, -100, 40, "Sinusoidal"); gridInfo2.setProjectionParameter(null); assertFalse(gridInfo1.equalProjections(gridInfo2)); } }
static List<HdfEosGridInfo> createGridInfos(Element eosStructElement) { List<HdfEosGridInfo> gridInfos = new ArrayList<HdfEosGridInfo>(); if (eosStructElement != null) { Element gridStructureElem = eosStructElement.getChild("GridStructure"); if (gridStructureElem != null) { for (Element gridElem : (List<Element>) gridStructureElem.getChildren()) { if (gridElem != null) { HdfEosGridInfo gridInfo = createGridInfo(gridElem); if (gridInfo != null) { gridInfos.add(gridInfo); } } } } } return gridInfos; }
@Override public void decode(ProfileReadContext ctx, Product p) throws IOException { Element eosElement = (Element) ctx.getProperty(HdfEosUtils.STRUCT_METADATA); List<HdfEosGridInfo> gridInfos = HdfEosGridInfo.createGridInfos(eosElement); List<HdfEosGridInfo> compatibleGridInfos = HdfEosGridInfo.getCompatibleGridInfos(gridInfos); if (!compatibleGridInfos.isEmpty()) { HdfEosGridInfo hdfEosGeocodingInfo = compatibleGridInfos.get(0); attachGeoCoding(p, hdfEosGeocodingInfo.upperLeftLon, hdfEosGeocodingInfo.upperLeftLat, hdfEosGeocodingInfo.lowerRightLon, hdfEosGeocodingInfo.lowerRightLat, hdfEosGeocodingInfo.projection, hdfEosGeocodingInfo.getProjectionParameter()); } }
@Test public void testGridInfosAreNotEqual() throws Exception { HdfEosGridInfo gridInfo1 = new HdfEosGridInfo("testName", -120, 50.1, -100, 40, "Sinusoidal"); HdfEosGridInfo gridInfo2 = new HdfEosGridInfo("testName", -120, 50, -100, 40, "Sinusoidal"); assertFalse(gridInfo1.equalProjections(gridInfo2)); }
HdfEosGridInfo hdfEosGridInfo = new HdfEosGridInfo(gridName, upperLeftLon, upperLeftLat, lowerRightLon, lowerRightLat, projection); if (projParamsElem != null) { List<Element> children = projParamsElem.getChildren(); projParameterValues[i] = Double.parseDouble(child.getValue()); hdfEosGridInfo.setProjectionParameter(projParameterValues);
static List<HdfEosGridInfo> getCompatibleGridInfos(List<HdfEosGridInfo> allGridInfos) { List<HdfEosGridInfo> compatibleGridInfos = new ArrayList<HdfEosGridInfo>(); if (allGridInfos.isEmpty()) { return compatibleGridInfos; } HdfEosGridInfo first = allGridInfos.get(0); for (HdfEosGridInfo gridInfo : allGridInfos) { if (first.equalProjections(gridInfo)) { compatibleGridInfos.add(gridInfo); } } return compatibleGridInfos; }
@Override protected void initReadContext(ProfileReadContext ctx) throws IOException { Group eosGroup = ctx.getNetcdfFile().getRootGroup(); Element eosElement = HdfEosUtils.getEosElement(HdfEosUtils.STRUCT_METADATA, eosGroup); List<HdfEosGridInfo> gridInfos = HdfEosGridInfo.createGridInfos(eosElement); List<HdfEosGridInfo> compatibleGridInfos = HdfEosGridInfo.getCompatibleGridInfos(gridInfos); if (compatibleGridInfos.isEmpty()) { throw new ProductIOException("Could not find grids."); } List<Group> gridGroups = new ArrayList<Group>(); for (HdfEosGridInfo gridInfo : compatibleGridInfos) { gridGroups.add(HdfEosUtils.findGroupNested(eosGroup, gridInfo.gridName)); } if (gridGroups.isEmpty()) { throw new ProductIOException("Could not find grid group."); } Group[] groups = gridGroups.toArray(new Group[gridGroups.size()]); RasterDigest rasterDigest = RasterDigest.createRasterDigest(groups); ctx.setRasterDigest(rasterDigest); ctx.setProperty(HdfEosUtils.STRUCT_METADATA, eosElement); ctx.setProperty(HdfEosUtils.CORE_METADATA, HdfEosUtils.getEosElement(HdfEosUtils.CORE_METADATA, eosGroup)); ctx.setProperty(HdfEosUtils.ARCHIVE_METADATA, HdfEosUtils.getEosElement(HdfEosUtils.ARCHIVE_METADATA, eosGroup)); }
@Override protected DecodeQualification getDecodeQualification(NetcdfFile netcdfFile) { try { Element eosElement = HdfEosUtils.getEosElement(HdfEosUtils.STRUCT_METADATA, netcdfFile.getRootGroup()); // check for GRID if (!HdfEosGridInfo.createGridInfos(eosElement).isEmpty()) { return DecodeQualification.INTENDED; } } catch (Exception ignore) { } return DecodeQualification.UNABLE; }
@Test public void testGridInfosAreEqual() throws Exception { HdfEosGridInfo gridInfo1 = new HdfEosGridInfo("testName", -120, 50, -100, 40, "Sinusoidal"); HdfEosGridInfo gridInfo2 = new HdfEosGridInfo("testName", -120, 50, -100, 40, "Sinusoidal"); assertTrue(gridInfo1.equalProjections(gridInfo2)); }
@Test public void testGridInfosWithProjParamsAreEqual() throws Exception { HdfEosGridInfo gridInfo1 = new HdfEosGridInfo("testName", -120, 50, -100, 40, "Sinusoidal"); gridInfo1.setProjectionParameter(PROJ_PARAMS); HdfEosGridInfo gridInfo2 = new HdfEosGridInfo("testName", -120, 50, -100, 40, "Sinusoidal"); gridInfo2.setProjectionParameter(PROJ_PARAMS); assertTrue(gridInfo1.equalProjections(gridInfo2)); }
@Test public void testGridInfosWithProjParamsAreNotEqual() throws Exception { HdfEosGridInfo gridInfo1 = new HdfEosGridInfo("testName", -120, 50, -100, 40, "Sinusoidal"); gridInfo1.setProjectionParameter(PROJ_PARAMS); HdfEosGridInfo gridInfo2 = new HdfEosGridInfo("testName", -120, 50, -100, 40, "Sinusoidal"); double[] projParams2 = PROJ_PARAMS.clone(); projParams2[4] = 42.42; gridInfo2.setProjectionParameter(projParams2); assertFalse(gridInfo1.equalProjections(gridInfo2)); }