use of org.locationtech.jts.geom.LineString in project hale by halestudio.
the class CurveHelper method combineCurve.
/**
* Combine the given {@link LineString}s to a single {@link LineString} if
* possible.
*
* @param lineStrings the line strings
* @param fact a geometry factory
* @return the combined {@link LineString} or <code>null</code> if the
* geometry did not meet the requirements of the strict mode
*/
@Nullable
public static LineString combineCurve(List<? extends LineString> lineStrings, GeometryFactory fact) {
return combineCurve(lineStrings, true, geoms -> {
List<Coordinate> coordinates = new ArrayList<>();
boolean skipFirst = false;
for (LineString geom : geoms) {
int index = 0;
if (!skipFirst) {
skipFirst = true;
} else {
index = 1;
}
for (int i = index; i < geom.getNumPoints(); i++) {
coordinates.add(geom.getCoordinateN(i));
}
}
return fact.createLineString(coordinates.toArray(new Coordinate[coordinates.size()]));
});
}
use of org.locationtech.jts.geom.LineString in project sldeditor by robward-scisys.
the class SLDEditorBufferedImageLegendGraphicBuilder method getSampleShape.
/**
* Returns a <code>java.awt.Shape</code> appropiate to render a legend graphic given the
* symbolizer type and the legend dimensions.
*
* @param symbolizer the Symbolizer for whose type a sample shape will be created
* @param legendWidth the requested width, in output units, of the legend graphic
* @param legendHeight the requested height, in output units, of the legend graphic
* @return an appropiate Line2D, Rectangle2D or LiteShape(Point) for the symbolizer, wether it
* is a LineSymbolizer, a PolygonSymbolizer, or a Point ot Text Symbolizer
* @throws IllegalArgumentException if an unknown symbolizer impl was passed in.
*/
private LiteShape2 getSampleShape(Symbolizer symbolizer, int legendWidth, int legendHeight) {
LiteShape2 sampleShape;
final float hpad = (legendWidth * LegendUtils.hpaddingFactor);
final float vpad = (legendHeight * LegendUtils.vpaddingFactor);
if (symbolizer instanceof LineSymbolizer) {
Coordinate[] coords = { new Coordinate(hpad, legendHeight - vpad - 1), new Coordinate(legendWidth - hpad - 1, vpad) };
LineString geom = geomFac.createLineString(coords);
try {
this.sampleLine = new LiteShape2(geom, null, null, false);
} catch (Exception e) {
this.sampleLine = null;
}
sampleShape = this.sampleLine;
} else if ((symbolizer instanceof PolygonSymbolizer) || (symbolizer instanceof RasterSymbolizer)) {
final float w = legendWidth - (2 * hpad) - 1;
final float h = legendHeight - (2 * vpad) - 1;
Coordinate[] coords = { new Coordinate(hpad, vpad), new Coordinate(hpad, vpad + h), new Coordinate(hpad + w, vpad + h), new Coordinate(hpad + w, vpad), new Coordinate(hpad, vpad) };
LinearRing shell = geomFac.createLinearRing(coords);
Polygon geom = geomFac.createPolygon(shell, null);
try {
this.sampleRect = new LiteShape2(geom, null, null, false);
} catch (Exception e) {
this.sampleRect = null;
}
sampleShape = this.sampleRect;
} else if (symbolizer instanceof PointSymbolizer || symbolizer instanceof TextSymbolizer) {
Coordinate coord = new Coordinate(legendWidth / 2, legendHeight / 2);
try {
this.samplePoint = new LiteShape2(geomFac.createPoint(coord), null, null, false);
} catch (Exception e) {
this.samplePoint = null;
}
sampleShape = this.samplePoint;
} else {
throw new IllegalArgumentException("Unknown symbolizer: " + symbolizer);
}
return sampleShape;
}
use of org.locationtech.jts.geom.LineString 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.LineString in project ddf by codice.
the class Wfs20JTStoGML321Converter method createGeometryPropertyType.
private static GeometryPropertyType createGeometryPropertyType(Geometry geometry, String srsName) {
final GeometryPropertyType geometryPropertyType = GML320_OBJECT_FACTORY.createGeometryPropertyType();
if (geometry instanceof Point) {
PointType pointType = convertToPointType((Point) geometry, srsName);
geometryPropertyType.setAbstractGeometry(convertPointTypeToJAXB(pointType));
} else if (geometry instanceof LineString) {
LineStringType lineStringType = convertToLineStringType((LineString) geometry, srsName);
geometryPropertyType.setAbstractGeometry(convertLineStringTypeToJAXB(lineStringType));
} else if (geometry instanceof Polygon) {
PolygonType polygonType = convertToPolygonType((Polygon) geometry, srsName);
geometryPropertyType.setAbstractGeometry(convertPolygonTypeToJAXB(polygonType));
} else if (geometry instanceof MultiPoint) {
MultiPointType multiPointType = convertToMultiPointType((MultiPoint) geometry, srsName);
geometryPropertyType.setAbstractGeometry(convertMultiPointTypeToJAXB(multiPointType));
} else if (geometry instanceof MultiLineString) {
MultiCurveType multiCurveType = convertToMultiLineStringType((MultiLineString) geometry, srsName);
geometryPropertyType.setAbstractGeometry(convertMultiCurveTypeToJAXB(multiCurveType));
} else if (geometry instanceof MultiPolygon) {
MultiSurfaceType multiSurfaceType = convertToMultiSurfaceType((MultiPolygon) geometry, srsName);
geometryPropertyType.setAbstractGeometry(convertMultiSurfaceTypeToJAXB(multiSurfaceType));
} else if (geometry instanceof GeometryCollection) {
MultiGeometryType multiGeometryType = convertToMultiGeometryType((GeometryCollection) geometry, srsName);
geometryPropertyType.setAbstractGeometry(convertMultiGeometryTypeToJAXB(multiGeometryType));
} else {
throw new IllegalArgumentException();
}
return geometryPropertyType;
}
use of org.locationtech.jts.geom.LineString in project ddf by codice.
the class WfsFilterDelegate method createGeometryOperand.
private JAXBElement<?> createGeometryOperand(String wkt) {
String convertedWkt = convertWktToLatLonOrdering(wkt);
Geometry wktGeometry = null;
try {
wktGeometry = getGeometryFromWkt(convertedWkt);
} catch (ParseException e) {
throw new UnsupportedOperationException("Unable to parse WKT Geometry [" + convertedWkt + "]", e);
}
if (wktGeometry instanceof Polygon) {
GeometryOperand polygonOperand = new GeometryOperand();
polygonOperand.setName(Wfs20Constants.POLYGON);
if (isGeometryOperandSupported(polygonOperand)) {
return createPolygon(wktGeometry);
}
GeometryOperand envelopeOperand = new GeometryOperand();
envelopeOperand.setName(Wfs20Constants.ENVELOPE);
if (isGeometryOperandSupported(envelopeOperand)) {
return createEnvelope(wktGeometry);
}
} else if (wktGeometry instanceof Point) {
GeometryOperand pointOperand = new GeometryOperand();
pointOperand.setName(Wfs20Constants.POINT);
if (isGeometryOperandSupported(pointOperand)) {
return createPoint(wktGeometry);
}
} else if (wktGeometry instanceof LineString) {
GeometryOperand lineStringOperand = new GeometryOperand();
lineStringOperand.setName(Wfs20Constants.LINESTRING);
if (isGeometryOperandSupported(lineStringOperand)) {
return createLineString(wktGeometry);
}
}
throw new UnsupportedOperationException(MessageFormat.format(NOT_SUPPORTED_MSG, "Geometry Operand from WKT", convertedWkt));
}
Aggregations