use of org.locationtech.jts.geom.LineString in project hale by halestudio.
the class InterpolationAlgorithm method interpolateArcString.
/**
* Interpolate an arc string.
*
* @param arcs the arc string to interpolate
* @return the interpolated geometry
*/
default LineString interpolateArcString(ArcString arcs) {
List<Coordinate> coords = new ArrayList<>();
List<Arc> arcList = new ArrayList<>(arcs.getArcs());
for (int i = 0; i < arcList.size(); i++) {
Arc arc = arcList.get(i);
LineString interpolated = interpolateArc(arc);
Coordinate[] lineCoords = interpolated.getCoordinates();
int startIndex = 1;
if (i == 0) {
startIndex = 0;
}
for (int j = startIndex; j < lineCoords.length; j++) {
Coordinate coord = lineCoords[j];
coords.add(coord);
}
}
return new InterpolatedLineString(getGeometryFactory().getCoordinateSequenceFactory().create(coords.toArray(new Coordinate[coords.size()])), getGeometryFactory(), arcs);
}
use of org.locationtech.jts.geom.LineString in project hale by halestudio.
the class StreamGmlWriterTest method testGeometry_2_LineString.
/**
* Test writing a {@link LineString} to a GML 2 geometry type
*
* @throws Exception if an error occurs
*/
@Ignore
// GML 2 stuff currently not working (because of unrelated schemas)
@Test
public void testGeometry_2_LineString() throws Exception {
// create the geometry
LineString lineString = createLineString(0.0);
Map<List<QName>, Object> values = new HashMap<List<QName>, Object>();
// $NON-NLS-1$
values.put(GEOMETRY_PROPERTY, lineString);
IOReport report = fillFeatureTest(// $NON-NLS-1$
"Test", // $NON-NLS-1$
getClass().getResource("/data/geom_schema/geom-gml2.xsd").toURI(), values, "geometry_2_LineString", // $NON-NLS-1$
DEF_SRS_NAME);
// $NON-NLS-1$
assertTrue("Expected GML output to be valid", report.isSuccess());
}
use of org.locationtech.jts.geom.LineString in project hale by halestudio.
the class StreamGmlWriterTest method testGeometryAggregate_32_LineString.
/**
* Test writing a {@link LineString} to a GML 3.2 geometry aggregate type
*
* @throws Exception if an error occurs
*/
@Test
public void testGeometryAggregate_32_LineString() throws Exception {
// create the geometry
LineString lineString = createLineString(0.0);
Map<List<QName>, Object> values = new HashMap<List<QName>, Object>();
// $NON-NLS-1$
values.put(GEOMETRY_PROPERTY, lineString);
IOReport report = fillFeatureTest(// $NON-NLS-1$
"AggregateTest", // $NON-NLS-1$
getClass().getResource("/data/geom_schema/geom-gml32.xsd").toURI(), // $NON-NLS-1$
values, // $NON-NLS-1$
"geometryAggregate_32_LineString", // $NON-NLS-1$
DEF_SRS_NAME, true, false);
// $NON-NLS-1$
assertTrue("Expected GML output to be valid", report.isSuccess());
}
use of org.locationtech.jts.geom.LineString in project hale by halestudio.
the class PolygonToLineStringTest method testBox.
/**
* Test conversion with a simple box
*/
@Test
public void testBox() {
Coordinate[] coordinates = new Coordinate[5];
coordinates[0] = coordinates[4] = new Coordinate(0, 0);
coordinates[1] = new Coordinate(1, 0);
coordinates[2] = new Coordinate(1, 1);
coordinates[3] = new Coordinate(0, 1);
LinearRing shell = geomFactory.createLinearRing(coordinates);
Polygon poly = geomFactory.createPolygon(shell, null);
PolygonToLineString converter = new PolygonToLineString();
LineString mls = converter.convert(poly);
// $NON-NLS-1$
assertEquals("Expecting 1 lines", 1, mls.getNumGeometries());
// $NON-NLS-1$
assertEquals("Should have 5 points", 5, mls.getNumPoints());
// first point
assertEquals(coordinates[0], mls.getCoordinateN(0));
// second point
assertEquals(coordinates[0], mls.getCoordinateN(4));
}
use of org.locationtech.jts.geom.LineString in project hale by halestudio.
the class LinearRingHandler method createGeometry.
/**
* Create a {@link LinearRing} geometry from the given instance.
*
* @param instance the instance
* @param srsDimension the SRS dimension
* @param allowTryOtherDimension if trying another dimension is allowed on
* failure (e.g. 3D instead of 2D)
* @param reader the I/O Provider to get value
* @return the {@link LinearRing} geometry
* @throws GeometryNotSupportedException if the type definition doesn't
* represent a geometry type supported by the handler
*/
protected GeometryProperty<LinearRing> createGeometry(Instance instance, int srsDimension, boolean allowTryOtherDimension, IOProvider reader) throws GeometryNotSupportedException {
LinearRing ring = null;
LineStringHandler handler = new LineStringHandler();
// for use with GML 2, 3, 3.1, 3.2
@SuppressWarnings("unchecked") DefaultGeometryProperty<LineString> linestring = (DefaultGeometryProperty<LineString>) handler.createGeometry(instance, srsDimension, reader);
try {
ring = getGeometryFactory().createLinearRing(linestring.getGeometry().getCoordinates());
} catch (IllegalArgumentException e) {
if (allowTryOtherDimension) {
// the error
// "Points of LinearRing do not form a closed linestring"
// can be an expression of a wrong dimension being used
// we try an alternative, to be sure (e.g. 3D instead of 2D)
int alternativeDimension = (srsDimension == 2) ? (3) : (2);
GeometryProperty<LinearRing> geom = createGeometry(instance, alternativeDimension, false, reader);
log.debug("Assuming geometry is " + alternativeDimension + "-dimensional.");
return geom;
}
throw e;
}
if (ring != null) {
CRSDefinition crsDef = GMLGeometryUtil.findCRS(instance);
return new DefaultGeometryProperty<LinearRing>(crsDef, ring);
}
throw new GeometryNotSupportedException();
}
Aggregations