/*
* Copyright (c) 2012 Data Harmonisation Panel
*
* All rights reserved. This program and the accompanying materials are made
* available under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution. If not, see <http://www.gnu.org/licenses/>.
*
* Contributors:
* HUMBOLDT EU Integrated Project #030962
* Data Harmonisation Panel <http://www.dhpanel.eu>
*/
package eu.esdihumboldt.hale.io.gml.geometry.handler;
import static org.junit.Assert.assertTrue;
import java.util.function.Consumer;
import org.junit.Test;
import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.geom.LinearRing;
import com.vividsolutions.jts.geom.Polygon;
import eu.esdihumboldt.hale.common.instance.geometry.InterpolationHelper;
import eu.esdihumboldt.hale.common.instance.model.Instance;
import eu.esdihumboldt.hale.common.instance.model.InstanceCollection;
import eu.esdihumboldt.hale.common.instance.model.ResourceIterator;
import eu.esdihumboldt.hale.io.gml.geometry.handler.internal.AbstractHandlerTest;
import eu.esdihumboldt.hale.io.gml.geometry.handler.internal.InterpolationConfigurations;
import eu.esdihumboldt.hale.io.gml.geometry.handler.internal.ReaderConfiguration;
import ru.yandex.qatools.allure.annotations.Features;
import ru.yandex.qatools.allure.annotations.Stories;
/**
* Tests for reading polygon geometries
*
* @author Patrick Lieb, Arun Varma
*/
@Features("Geometries")
@Stories("GML")
public class PolygonHandlerTest extends AbstractHandlerTest {
private Polygon reference;
private final ReaderConfiguration gridConfig = InterpolationConfigurations.ALL_TO_GRID_DEFAULT;
private Consumer<Geometry> checker;
private Consumer<Geometry> gridChecker;
// XXX no test for geometry properties
@Override
public void init() {
super.init();
LinearRing shell = geomFactory.createLinearRing(new Coordinate[] {
new Coordinate(0.01, 3.2), new Coordinate(3.33, 3.33), new Coordinate(0.01, -3.2),
new Coordinate(-3.33, -3.2), new Coordinate(0.01, 3.2) });
LinearRing[] holes = new LinearRing[2];
LinearRing hole1 = geomFactory
.createLinearRing(new Coordinate[] { new Coordinate(0, 1), new Coordinate(1, 1),
new Coordinate(0, -1), new Coordinate(-1, -1), new Coordinate(0, 1) });
LinearRing hole2 = geomFactory
.createLinearRing(new Coordinate[] { new Coordinate(0, 2), new Coordinate(2, 2),
new Coordinate(0, -2), new Coordinate(-2, -2), new Coordinate(0, 2) });
holes[0] = hole1;
holes[1] = hole2;
reference = geomFactory.createPolygon(shell, holes);
checker = combine(noCoordinatePairs(), referenceChecker(reference));
gridChecker = combine(noCoordinatePairs(),
referenceChecker(reference, InterpolationHelper.DEFAULT_MAX_POSITION_ERROR),
gridConfig.geometryChecker());
}
/**
* Test polygon geometries read from a GML 2 file
*
* @throws Exception if an error occurs
*/
@Test
public void testPolygonGml2() throws Exception {
InstanceCollection instances = AbstractHandlerTest.loadXMLInstances(
getClass().getResource("/data/gml/geom-gml2.xsd").toURI(),
getClass().getResource("/data/polygon/sample-polygon-gml2.xml").toURI());
// one instance expected
ResourceIterator<Instance> it = instances.iterator();
try {
// PolygonProperty with LinearRing defined through coordinates
assertTrue("First sample feature missing", it.hasNext());
Instance instance = it.next();
checkSingleGeometry(instance, checker);
} finally {
it.close();
}
}
/**
* Test polygon geometries read from a GML 3 file
*
* @throws Exception if an error occurs
*/
@Test
public void testPolygonGml3() throws Exception {
InstanceCollection instances = AbstractHandlerTest.loadXMLInstances(
getClass().getResource("/data/gml/geom-gml3.xsd").toURI(),
getClass().getResource("/data/polygon/sample-polygon-gml3.xml").toURI());
// one instance expected
ResourceIterator<Instance> it = instances.iterator();
try {
// PolygonProperty with LinearRing defined through coordinates
assertTrue("First sample feature missing", it.hasNext());
Instance instance = it.next();
checkSingleGeometry(instance, checker);
} finally {
it.close();
}
}
/**
* Test polygon geometries read from a GML 3.1 file
*
* @throws Exception if an error occurs
*/
@Test
public void testPolygonGml31() throws Exception {
InstanceCollection instances = AbstractHandlerTest.loadXMLInstances(
getClass().getResource("/data/gml/geom-gml31.xsd").toURI(),
getClass().getResource("/data/polygon/sample-polygon-gml31.xml").toURI());
// one instance expected
ResourceIterator<Instance> it = instances.iterator();
try {
// PolygonProperty with LinearRing defined through coordinates
assertTrue("First sample feature missing", it.hasNext());
Instance instance = it.next();
checkSingleGeometry(instance, checker);
} finally {
it.close();
}
}
/**
* Test polygon geometries read from a GML 3.2 file
*
* @throws Exception if an error occurs
*/
@Test
public void testPolygonGml32() throws Exception {
InstanceCollection instances = AbstractHandlerTest.loadXMLInstances(
getClass().getResource("/data/gml/geom-gml32.xsd").toURI(),
getClass().getResource("/data/polygon/sample-polygon-gml32.xml").toURI());
// one instance expected
ResourceIterator<Instance> it = instances.iterator();
try {
// LinearRingProperty with LinearRing defined through coordinates
assertTrue("First sample feature missing", it.hasNext());
Instance instance = it.next();
checkSingleGeometry(instance, checker);
} finally {
it.close();
}
}
/**
* Test polygon geometries read from a GML 2 file
*
* @throws Exception if an error occurs
*/
@Test
public void testPolygonGml2_Grid() throws Exception {
InstanceCollection instances = AbstractHandlerTest.loadXMLInstances(
getClass().getResource("/data/gml/geom-gml2.xsd").toURI(),
getClass().getResource("/data/polygon/sample-polygon-gml2.xml").toURI(),
gridConfig);
// one instance expected
ResourceIterator<Instance> it = instances.iterator();
try {
// PolygonProperty with LinearRing defined through coordinates
assertTrue("First sample feature missing", it.hasNext());
Instance instance = it.next();
checkSingleGeometry(instance, gridChecker);
} finally {
it.close();
}
}
/**
* Test polygon geometries read from a GML 3 file
*
* @throws Exception if an error occurs
*/
@Test
public void testPolygonGml3_Grid() throws Exception {
InstanceCollection instances = AbstractHandlerTest.loadXMLInstances(
getClass().getResource("/data/gml/geom-gml3.xsd").toURI(),
getClass().getResource("/data/polygon/sample-polygon-gml3.xml").toURI(),
gridConfig);
// one instance expected
ResourceIterator<Instance> it = instances.iterator();
try {
// PolygonProperty with LinearRing defined through coordinates
assertTrue("First sample feature missing", it.hasNext());
Instance instance = it.next();
checkSingleGeometry(instance, gridChecker);
} finally {
it.close();
}
}
/**
* Test polygon geometries read from a GML 3.1 file
*
* @throws Exception if an error occurs
*/
@Test
public void testPolygonGml31_Grid() throws Exception {
InstanceCollection instances = AbstractHandlerTest.loadXMLInstances(
getClass().getResource("/data/gml/geom-gml31.xsd").toURI(),
getClass().getResource("/data/polygon/sample-polygon-gml31.xml").toURI(),
gridConfig);
// one instance expected
ResourceIterator<Instance> it = instances.iterator();
try {
// PolygonProperty with LinearRing defined through coordinates
assertTrue("First sample feature missing", it.hasNext());
Instance instance = it.next();
checkSingleGeometry(instance, gridChecker);
} finally {
it.close();
}
}
/**
* Test polygon geometries read from a GML 3.2 file
*
* @throws Exception if an error occurs
*/
@Test
public void testPolygonGml32_Grid() throws Exception {
InstanceCollection instances = AbstractHandlerTest.loadXMLInstances(
getClass().getResource("/data/gml/geom-gml32.xsd").toURI(),
getClass().getResource("/data/polygon/sample-polygon-gml32.xml").toURI(),
gridConfig);
// one instance expected
ResourceIterator<Instance> it = instances.iterator();
try {
// LinearRingProperty with LinearRing defined through coordinates
assertTrue("First sample feature missing", it.hasNext());
Instance instance = it.next();
checkSingleGeometry(instance, gridChecker);
} finally {
it.close();
}
}
}