/** * Test coverageToFeature process with a PixelInCell.CELL_CENTER coverage * * @throws NoSuchAuthorityCodeException * @throws FactoryException */ @Test public void coverageToFeatureTestPixelCenter() throws NoSuchAuthorityCodeException, FactoryException, ProcessException { Hints.putSystemDefault(Hints.LENIENT_DATUM_SHIFT, Boolean.TRUE); PixelInCell pixPos = PixelInCell.CELL_CENTER; GridCoverageReader reader = buildReader(pixPos); // Process ProcessDescriptor desc = ProcessFinder.getProcessDescriptor("coverage", "coveragetofeatures"); ParameterValueGroup in = desc.getInputDescriptor().createValue(); in.parameter("reader_in").setValue(reader); org.geotoolkit.process.Process proc = desc.createProcess(in); // Features out final Collection<Feature> featureListOut = (Collection<Feature>) proc.call().parameter("feature_out").getValue(); final List<Feature> featureListResult = (List<Feature>) buildFCResultPixelCenter(); assertEquals(featureListResult.get(0).getType(), featureListOut.iterator().next().getType()); assertEquals(featureListOut.size(), featureListResult.size()); Iterator<Feature> iteratorOut = featureListOut.iterator(); Iterator<Feature> iteratorResult = featureListResult.iterator(); ArrayList<Geometry> geomsOut = new ArrayList<Geometry>(); int itOut = 0; while (iteratorOut.hasNext()) { Feature featureOut = iteratorOut.next(); for (Property propertyOut : featureOut.getProperties()) { if (propertyOut.getDescriptor() instanceof GeometryDescriptor) { geomsOut.add(itOut++, (Geometry) propertyOut.getValue()); } } } ArrayList<Geometry> geomsResult = new ArrayList<Geometry>(); int itResult = 0; while (iteratorResult.hasNext()) { Feature featureResult = iteratorResult.next(); for (Property propertyResult : featureResult.getProperties()) { if (propertyResult.getDescriptor() instanceof GeometryDescriptor) { geomsResult.add(itResult++, (Geometry) propertyResult.getValue()); } } } assertEquals(geomsResult.size(), geomsOut.size()); for (int i = 0; i < geomsResult.size(); i++) { Geometry gOut = geomsOut.get(i); Geometry gResult = geomsResult.get(i); assertArrayEquals(gResult.getCoordinates(), gOut.getCoordinates()); } }
@Test public void placemarkWriteTest() throws KmlException, IOException, XMLStreamException, ParserConfigurationException, SAXException { final KmlFactory kmlFactory = DefaultKmlFactory.getInstance(); final Coordinate coordinate = kmlFactory.createCoordinate(-90.86948943473118, 48.25450093195546, 0); final CoordinateSequence coordinates = kmlFactory.createCoordinates(Arrays.asList(coordinate)); final Point point = kmlFactory.createPoint(coordinates); final LookAt lookAt = kmlFactory.createLookAt(); lookAt.setLongitude(-90.86879847669974); lookAt.setLatitude(48.25330383601299); lookAt.setHeading(2.7); lookAt.setTilt(8.3); lookAt.setRange(440.8); final Feature placemark = kmlFactory.createPlacemark(); final Collection<Property> placemarkProperties = placemark.getProperties(); placemarkProperties.add( FF.createAttribute("Google Earth - New Placemark", KmlModelConstants.ATT_NAME, null)); placemarkProperties.add( FF.createAttribute("Some Descriptive text.", KmlModelConstants.ATT_DESCRIPTION, null)); placemarkProperties.add(FF.createAttribute(lookAt, KmlModelConstants.ATT_VIEW, null)); placemarkProperties.add( FF.createAttribute(point, KmlModelConstants.ATT_PLACEMARK_GEOMETRY, null)); final Kml kml = kmlFactory.createKml(null, placemark, null, null); final File temp = File.createTempFile("testPlacemark", ".kml"); temp.deleteOnExit(); final KmlWriter writer = new KmlWriter(); writer.setOutput(temp); writer.write(kml); writer.dispose(); DomCompare.compare(new File(pathToTestFile), temp); }