use of org.locationtech.jts.geom.LineString in project jena by apache.
the class GMLWriterTest method testWriteMultiCurve.
@Test
public void testWriteMultiCurve() {
LineString[] lineStrings = new LineString[2];
lineStrings[0] = GEOMETRY_FACTORY.createLineString(new CustomCoordinateSequence(CoordinateSequenceDimensions.XY, "10 10, 20 20, 10 40"));
lineStrings[1] = GEOMETRY_FACTORY.createLineString(new CustomCoordinateSequence(CoordinateSequenceDimensions.XY, "40 40, 30 30, 40 20, 30 10"));
Geometry geometry = GEOMETRY_FACTORY.createMultiLineString(lineStrings);
GeometryWrapper geometryWrapper = new GeometryWrapper(geometry, GML_SRS_NAMESPACE, GMLDatatype.URI, new DimensionInfo(2, 2, 0));
String result = GMLWriter.write(geometryWrapper);
String expResult = "<gml:MultiCurve xmlns:gml=\"http://www.opengis.net/ont/gml\" srsName=\"urn:ogc:def:crs:EPSG::27700\"><gml:curveMember><gml:LineString srsName=\"urn:ogc:def:crs:EPSG::27700\"><gml:posList>10 10 20 20 10 40</gml:posList></gml:LineString></gml:curveMember><gml:curveMember><gml:LineString srsName=\"urn:ogc:def:crs:EPSG::27700\"><gml:posList>40 40 30 30 40 20 30 10</gml:posList></gml:LineString></gml:curveMember></gml:MultiCurve>";
assertEquals(expResult.trim(), result.trim());
}
use of org.locationtech.jts.geom.LineString in project jena by apache.
the class WKTWriterTest method testWriteLineString.
/**
* Test of write method, of class WKTWriter.
*/
@Test
public void testWriteLineString() {
Geometry geometry = GEOMETRY_FACTORY.createLineString(new CustomCoordinateSequence(CoordinateSequenceDimensions.XY, "11.0 12.1, 3 4"));
GeometryWrapper geometryWrapper = new GeometryWrapper(geometry, SRS_URI.WGS84_CRS, WKTDatatype.URI, new DimensionInfo(2, 2, 1));
String expResult = "<" + SRS_URI.WGS84_CRS + "> LINESTRING(11 12.1, 3 4)";
String result = WKTWriter.write(geometryWrapper);
//
//
assertEquals(expResult, result);
}
use of org.locationtech.jts.geom.LineString in project jena by apache.
the class WKTWriter method buildPolygon.
private static String buildPolygon(final Polygon polygon, final boolean isIncludeGeometryType, final String dimensionString) {
StringBuilder sb = new StringBuilder();
if (isIncludeGeometryType) {
sb.append("POLYGON");
}
if (!polygon.isEmpty()) {
if (isIncludeGeometryType) {
sb.append(dimensionString);
}
sb.append("(");
// Find exterior shell
LineString lineString = polygon.getExteriorRing();
CustomCoordinateSequence coordSequence = (CustomCoordinateSequence) lineString.getCoordinateSequence();
sb.append(convertToWKTText(coordSequence));
// Find inner holes
int interiorRings = polygon.getNumInteriorRing();
for (int i = 0; i < interiorRings; i++) {
sb.append(", ");
LineString innerLineString = polygon.getInteriorRingN(i);
CustomCoordinateSequence innerCoordSequence = (CustomCoordinateSequence) innerLineString.getCoordinateSequence();
sb.append(convertToWKTText(innerCoordSequence));
}
sb.append(")");
} else {
sb.append(" EMPTY");
}
return sb.toString();
}
use of org.locationtech.jts.geom.LineString in project jena by apache.
the class WKTWriter method buildMultiLineString.
private static String buildMultiLineString(final MultiLineString multiLineString, final String dimensionString) {
StringBuilder sb = new StringBuilder("MULTILINESTRING");
if (!multiLineString.isEmpty()) {
sb.append(dimensionString);
sb.append("(");
// Find first linestring
LineString lineString = (LineString) multiLineString.getGeometryN(0);
CustomCoordinateSequence coordSequence = (CustomCoordinateSequence) lineString.getCoordinateSequence();
sb.append(buildWKT("", coordSequence));
// Encode remaining points
int geomCount = multiLineString.getNumGeometries();
for (int i = 1; i < geomCount; i++) {
sb.append(", ");
lineString = (LineString) multiLineString.getGeometryN(i);
coordSequence = (CustomCoordinateSequence) lineString.getCoordinateSequence();
sb.append(buildWKT("", coordSequence));
}
sb.append(")");
} else {
sb.append(" EMPTY");
}
return sb.toString();
}
use of org.locationtech.jts.geom.LineString in project jena by apache.
the class GeometryReverseTest method testCheckLineStringNotReversed.
/**
* Test of check method, of class GeometryReverse.
*/
@Test
public void testCheckLineStringNotReversed() {
WKTReader reader = new WKTReader();
try {
LineString geometry = (LineString) reader.read("LINESTRING(0 0, 2 0, 5 0)");
String srsURI = SRS_URI.DEFAULT_WKT_CRS84;
Geometry expResult = reader.read("LINESTRING(0 0, 2 0, 5 0)");
Geometry result = GeometryReverse.check(geometry, srsURI);
//
//
assertEquals(expResult, result);
} catch (ParseException ex) {
System.err.println("ParseException: " + ex.getMessage());
}
}
Aggregations