use of org.opengis.geometry.primitive.Curve in project geotoolkit by Geomatys.
the class AbstractGeometryTest method createSurface.
/**
* Creates a simple polygon with no holes
* @param points points defining the polygon (surface)
* @return the surface created out of the points
*/
protected Surface createSurface(final DirectPosition[] points) {
Curve curve = createCurve(points);
SurfaceBoundary surfaceBoundary = createSurfaceBoundary(curve);
Surface surface = PRIMITIVE_FACTORY.createSurface(surfaceBoundary);
return surface;
}
use of org.opengis.geometry.primitive.Curve in project geotoolkit by Geomatys.
the class GeometryParser method readPolygonText.
/**
* Creates a <code>SurfaceBoundary</code> using the next token in the stream.
*
* @param tokenizer tokenizer over a stream of text in Well-known Text
* format. The next tokens must form a <Polygon Text>.
* @return a <code>Surface</code> specified by the vertices in the stream
* @throws ParseException if the coordinates used to create the <code>Polygon</code>
* shell and holes do not form closed linestrings, or if an unexpected
* token was encountered.
* @throws IOException if an I/O error occurs
*/
private Surface readPolygonText(final StreamTokenizer tokenizer) throws IOException, ParseException {
String nextToken = getNextEmptyOrOpener(tokenizer);
if (nextToken.equals(EMPTY)) {
return null;
}
Curve curve = readLinearRingText(tokenizer);
List<OrientableCurve> curveList = Collections.singletonList((OrientableCurve) curve);
Ring shell = primitiveFactory.createRing(curveList);
// Ring shell = readLinearRingText(tokenizer);
List<Ring> holes = new ArrayList<Ring>();
nextToken = getNextCloserOrComma(tokenizer);
while (nextToken.equals(COMMA)) {
Curve holecurve = readLinearRingText(tokenizer);
List<OrientableCurve> holeList = Collections.singletonList((OrientableCurve) holecurve);
Ring hole = primitiveFactory.createRing(holeList);
// Ring hole = readLinearRingText(tokenizer);
holes.add(hole);
nextToken = getNextCloserOrComma(tokenizer);
}
SurfaceBoundary sb = primitiveFactory.createSurfaceBoundary(shell, holes);
return primitiveFactory.createSurface(sb);
}
use of org.opengis.geometry.primitive.Curve in project geotoolkit by Geomatys.
the class GeometryUtils method getLineCharSequences.
/**
* Recursively populates the specified List with LineCharSequences corresponding
* to the primitive elements of the specified CompositeCurve.
* Returns null if any element of the CompositeCurve cannot be converted
* to a LineString.
* @param cc The CompositeCurve of interest
* @param lsList The ArrayList to be populated
* @return The populated List, or null if not valid
*/
private static ArrayList getLineCharSequences(final CompositeCurve cc, final ArrayList lsList) {
// Cast below can be removed when Types will be allowed to abandon Java 1.4 support.
List elements = (List) cc.getGenerators();
boolean valid = true;
if (!elements.isEmpty()) {
Iterator it = elements.iterator();
LineString ls = null;
while (it.hasNext() && valid) {
Object element = it.next();
if (element instanceof CompositeCurve) {
valid = getLineCharSequences((CompositeCurve) element, lsList) != null;
} else if (element instanceof Curve) {
// PENDING(NL): When we have arc geometries implemented,
// make provision to pass in real parameters for spacing and offset.
// What we have below essentially just returns start and end points
// if it's not a LineString
ls = ((Curve) element).asLineString(Double.MAX_VALUE, Double.MAX_VALUE);
if (ls != null) {
lsList.add(ls);
} else {
valid = false;
}
} else {
valid = false;
}
}
}
if (valid) {
return null;
}
return lsList;
}
use of org.opengis.geometry.primitive.Curve in project geotoolkit by Geomatys.
the class GeometryUtils method getDirectPositions.
public static DirectPosition[] getDirectPositions(final Ring ring) {
final List directPositionList = new ArrayList();
// Cast below can be removed when Types will be allowed to abandon Java 1.4 support.
final List /*<Curve>*/
generators = (List) ring.getGenerators();
for (int i = 0; i < generators.size(); i++) {
final Curve curve = (Curve) generators.get(i);
final List /*<CurveSegments>*/
segments = curve.getSegments();
for (int j = 0; j < segments.size(); j++) {
final CurveSegment curveSegment = (CurveSegment) segments.get(j);
if (curveSegment instanceof LineString) {
final LineString lineString = (LineString) curveSegment;
final DirectPosition[] positions = getDirectPositions(lineString);
directPositionList.addAll(Arrays.asList(positions));
/*final List<Position> positions = lineString.getControlPoints().positions();
for (int k = 0; k < positions.size(); k++) {
Position position = (Position) positions.get(k);
directPositionList.add(position.getPosition());
}*/
}
}
}
if (directPositionList.size() > 0) {
return (DirectPosition[]) directPositionList.toArray(new DirectPosition[directPositionList.size()]);
}
return new DirectPosition[0];
}
use of org.opengis.geometry.primitive.Curve in project geotoolkit by Geomatys.
the class JTSUtils method linearRingToRing.
public static Ring linearRingToRing(final org.locationtech.jts.geom.LineString jtsLinearRing, final CoordinateReferenceSystem crs) {
int numPoints = jtsLinearRing.getNumPoints();
if (numPoints != 0 && !jtsLinearRing.getCoordinateN(0).equals(jtsLinearRing.getCoordinateN(numPoints - 1))) {
throw new IllegalArgumentException("LineString must be a ring");
}
// FactoryFinder.getPrimitiveFactory(hints);
PrimitiveFactory pf = new JTSPrimitiveFactory(crs);
// FactoryFinder.getGeometryFactory(hints);
GeometryFactory gf = new JTSGeometryFactory(crs);
LineString ls = gf.createLineString(new ArrayList());
List pointList = ls.getControlPoints();
for (int i = 0; i < numPoints; i++) {
pointList.add(coordinateToDirectPosition(jtsLinearRing.getCoordinateN(i), crs));
}
Curve curve = pf.createCurve(new ArrayList());
// Cast below can be removed when Types will be allowed to abandon Java 1.4 support.
((List) curve.getSegments()).add(ls);
Ring result = pf.createRing(new ArrayList());
// Cast below can be removed when Types will be allowed to abandon Java 1.4 support.
((List) result.getGenerators()).add(curve);
return result;
}
Aggregations