use of org.locationtech.jts.geom.LinearRing in project crate by crate.
the class PolygonBuilder method polygon.
protected static Polygon polygon(GeometryFactory factory, Coordinate[][] polygon) {
LinearRing shell = factory.createLinearRing(polygon[0]);
LinearRing[] holes;
if (polygon.length > 1) {
holes = new LinearRing[polygon.length - 1];
for (int i = 0; i < holes.length; i++) {
holes[i] = factory.createLinearRing(polygon[i + 1]);
}
} else {
holes = null;
}
return factory.createPolygon(shell, holes);
}
use of org.locationtech.jts.geom.LinearRing in project crate by crate.
the class PolygonBuilder method toPolygon.
protected Polygon toPolygon(GeometryFactory factory) {
final LinearRing shell = linearRing(factory, this.shell.coordinates);
final LinearRing[] holes = new LinearRing[this.holes.size()];
Iterator<LineStringBuilder> iterator = this.holes.iterator();
for (int i = 0; iterator.hasNext(); i++) {
holes[i] = linearRing(factory, iterator.next().coordinates);
}
return factory.createPolygon(shell, holes);
}
use of org.locationtech.jts.geom.LinearRing in project dhis2-core by dhis2.
the class GeoToolsPrimitiveFromJsonFactory method createPolygonFromJson.
/**
* Create a GeoTools geometric polygon primitive from coordinates in json.
*
* @param json the json array of linear ring
* @return the polygon
*/
public static Polygon createPolygonFromJson(JsonNode json) {
// Get the json array of coordinates representing the shell and make a
// linear-ring out of them
JsonNode shell = json.get(0);
LinearRing sh = createLinearRingFromJson(shell);
// Native array of linear-ring holes to pass to GeoFactory
LinearRing[] holes = null;
// Get the linear-ring holes if the polygon has any holes
if (json.size() > 1) {
// Allocate memory for the holes, i.e. minus the shell
holes = new LinearRing[shell.size() - 1];
// Read the json array of linear-ring into holes
for (int i = 1; i < shell.size(); i++) {
JsonNode hole = json.get(i);
if (hole != null && hole.size() > 0) {
holes[i] = createLinearRingFromJson(hole);
}
}
}
// Create the polygon from factory
return FACTORY.createPolygon(sh, holes);
}
use of org.locationtech.jts.geom.LinearRing in project ddf by codice.
the class Wfs20JTStoGML321Converter method convertToPolygonType.
public static PolygonType convertToPolygonType(Polygon polygon, String srsName) {
PolygonType polygonType = GML320_OBJECT_FACTORY.createPolygonType();
// exterior
LineString lineString = polygon.getExteriorRing();
LinearRing linearRing = lineString.getFactory().createLinearRing(lineString.getCoordinateSequence());
RingType ringType = convertToRingType(linearRing, srsName);
JAXBElement<RingType> ringTypeJAXBElement = GML320_OBJECT_FACTORY.createRing(ringType);
AbstractRingPropertyType abstractRingPropertyType = GML320_OBJECT_FACTORY.createAbstractRingPropertyType();
abstractRingPropertyType.setAbstractRing(ringTypeJAXBElement);
polygonType.setExterior(abstractRingPropertyType);
// interiors
for (int i = 0; i < polygon.getNumInteriorRing(); i++) {
LineString interiorRingN = polygon.getInteriorRingN(i);
LinearRing linearRing1 = interiorRingN.getFactory().createLinearRing(interiorRingN.getCoordinateSequence());
RingType ringType1 = convertToRingType(linearRing1, srsName);
JAXBElement<RingType> ringTypeJAXBElement1 = GML320_OBJECT_FACTORY.createRing(ringType1);
AbstractRingPropertyType abstractRingPropertyType1 = GML320_OBJECT_FACTORY.createAbstractRingPropertyType();
abstractRingPropertyType1.setAbstractRing(ringTypeJAXBElement1);
polygonType.getInterior().add(abstractRingPropertyType1);
}
polygonType.setSrsName(srsName);
return polygonType;
}
use of org.locationtech.jts.geom.LinearRing in project ddf by codice.
the class GmdTransformer method setLocationFromPolygon.
private void setLocationFromPolygon(String boundingPolygon, MetacardImpl metacard) {
try {
String[] stringArray = boundingPolygon.split(" ");
List<Coordinate> coordinates = new ArrayList<>();
for (int i = 0; i < stringArray.length - 1; i += 2) {
coordinates.add(new Coordinate(Double.parseDouble(stringArray[i]), Double.parseDouble(stringArray[i + 1])));
}
LinearRing linearRing = factory.createLinearRing(coordinates.toArray(new Coordinate[coordinates.size()]));
String wkt = WKT_WRITER_THREAD_LOCAL.get().write(factory.createPolygon(linearRing, null));
if (wkt != null) {
metacard.setAttribute(Core.LOCATION, wkt);
}
} catch (NumberFormatException nfe) {
LOGGER.debug("Unable to parse double in {}. Metacard location will not be set.", boundingPolygon);
}
}
Aggregations