Search in sources :

Example 1 with CompositeCurve

use of org.opengis.geometry.complex.CompositeCurve 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;
}
Also used : LineString(org.opengis.geometry.coordinate.LineString) Iterator(java.util.Iterator) Curve(org.opengis.geometry.primitive.Curve) CompositeCurve(org.opengis.geometry.complex.CompositeCurve) CompositeCurve(org.opengis.geometry.complex.CompositeCurve) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 List (java.util.List)1 CompositeCurve (org.opengis.geometry.complex.CompositeCurve)1 LineString (org.opengis.geometry.coordinate.LineString)1 Curve (org.opengis.geometry.primitive.Curve)1