Search in sources :

Example 1 with CurveImpl

use of org.geotools.geometry.iso.primitive.CurveImpl in project sldeditor by robward-scisys.

the class WKTConversion method parseWKTString.

/**
 * Parses the wkt string.
 *
 * @param wktString the wkt string
 * @return the WKT geometry
 */
public static WKTGeometry parseWKTString(String wktString) {
    if (wktParser == null) {
        initialise();
    }
    if (wktString == null) {
        return null;
    }
    WKTGeometry wktGeometry = new WKTGeometry();
    // Remove wkt:// prefix
    if (wktString.startsWith(WKT_PREFIX)) {
        wktString = wktString.substring(WKT_PREFIX.length());
    }
    try {
        org.opengis.geometry.Geometry geometry = wktParser.parse(wktString);
        if (geometry instanceof MultiPrimitiveImpl) {
            MultiPrimitiveImpl multiLine = (MultiPrimitiveImpl) geometry;
            parseWKTMultiPrimitive(wktGeometry, multiLine);
        } else if (geometry instanceof PointImpl) {
            parseWKTPoint(wktGeometry, geometry);
        } else if (geometry instanceof CurveImpl) {
            parseWKTCurve(wktGeometry, geometry);
        } else if (geometry instanceof SurfaceImpl) {
            parseWKTSurface(wktGeometry, geometry);
        }
    } catch (ParseException e) {
        wktGeometry.setValid(false);
        for (WKTType wktType : wktTypeList) {
            if (wktString.startsWith(wktType.getName())) {
                wktGeometry.setGeometryType(wktType);
            }
        }
    } catch (IllegalArgumentException e) {
        ConsoleManager.getInstance().error(WKTConversion.class, e.getLocalizedMessage());
    }
    return wktGeometry;
}
Also used : MultiPrimitiveImpl(org.geotools.geometry.iso.aggregate.MultiPrimitiveImpl) CurveImpl(org.geotools.geometry.iso.primitive.CurveImpl) SurfaceImpl(org.geotools.geometry.iso.primitive.SurfaceImpl) ParseException(java.text.ParseException) PointImpl(org.geotools.geometry.iso.primitive.PointImpl)

Example 2 with CurveImpl

use of org.geotools.geometry.iso.primitive.CurveImpl in project sldeditor by robward-scisys.

the class WKTConversion method parseWKTSurface.

/**
 * Parses the WKT surface.
 *
 * @param wktGeometry the wkt geometry
 * @param geometry the geometry
 */
private static void parseWKTSurface(WKTGeometry wktGeometry, org.opengis.geometry.Geometry geometry) {
    wktGeometry.setGeometryType(getWKTType(WKT_POLYGON));
    SurfaceImpl surfaceImpl = (SurfaceImpl) geometry;
    for (Ring ring : surfaceImpl.getBoundaryRings()) {
        WKTSegmentList ptList = new WKTSegmentList();
        wktGeometry.addSegmentList(0, ptList);
        for (Primitive primitive : ring.getElements()) {
            if (primitive instanceof CurveImpl) {
                CurveImpl curve = (CurveImpl) primitive;
                extractLineSegments(curve, ptList);
            }
        }
    }
}
Also used : Primitive(org.opengis.geometry.primitive.Primitive) Ring(org.opengis.geometry.primitive.Ring) CurveImpl(org.geotools.geometry.iso.primitive.CurveImpl) SurfaceImpl(org.geotools.geometry.iso.primitive.SurfaceImpl)

Example 3 with CurveImpl

use of org.geotools.geometry.iso.primitive.CurveImpl in project sldeditor by robward-scisys.

the class WKTConversion method parseWKTMultiSurface.

/**
 * Parses the WKT multi surface.
 *
 * @param wktGeometry the wkt geometry
 * @param index the index
 * @param primitive the primitive
 */
private static void parseWKTMultiSurface(WKTGeometry wktGeometry, int index, Primitive primitive) {
    wktGeometry.setGeometryType(getWKTType(WKT_MULTIPOLYGON));
    SurfaceImpl surfaceImpl = (SurfaceImpl) primitive;
    for (Ring ring : surfaceImpl.getBoundaryRings()) {
        WKTSegmentList ptList = new WKTSegmentList();
        for (Primitive ringPrimitive : ring.getElements()) {
            if (ringPrimitive instanceof CurveImpl) {
                CurveImpl curve = (CurveImpl) ringPrimitive;
                extractLineSegments(curve, ptList);
            }
        }
        wktGeometry.addSegmentList(index, ptList);
    }
}
Also used : Primitive(org.opengis.geometry.primitive.Primitive) Ring(org.opengis.geometry.primitive.Ring) CurveImpl(org.geotools.geometry.iso.primitive.CurveImpl) SurfaceImpl(org.geotools.geometry.iso.primitive.SurfaceImpl)

Example 4 with CurveImpl

use of org.geotools.geometry.iso.primitive.CurveImpl in project sldeditor by robward-scisys.

the class WKTConversion method parseWKTMultiCurve.

/**
 * Parses the WKT multi curve.
 *
 * @param wktGeometry the wkt geometry
 * @param index the index
 * @param primitive the primitive
 */
private static void parseWKTMultiCurve(WKTGeometry wktGeometry, int index, Primitive primitive) {
    WKTSegmentList ptList = new WKTSegmentList();
    wktGeometry.setGeometryType(getWKTType(WKT_MULTILINESTRING));
    CurveImpl curve = (CurveImpl) primitive;
    extractLineSegments(curve, ptList);
    wktGeometry.addSegmentList(index, ptList);
}
Also used : CurveImpl(org.geotools.geometry.iso.primitive.CurveImpl)

Example 5 with CurveImpl

use of org.geotools.geometry.iso.primitive.CurveImpl in project sldeditor by robward-scisys.

the class WKTConversion method parseWKTCurve.

/**
 * Parses the WKT curve.
 *
 * @param wktGeometry the wkt geometry
 * @param geometry the geometry
 */
private static void parseWKTCurve(WKTGeometry wktGeometry, org.opengis.geometry.Geometry geometry) {
    wktGeometry.setGeometryType(getWKTType(WKT_LINESTRING));
    CurveImpl curveImpl = (CurveImpl) geometry;
    WKTSegmentList ptList = new WKTSegmentList();
    wktGeometry.addSegmentList(0, ptList);
    extractLineSegments(curveImpl, ptList);
}
Also used : CurveImpl(org.geotools.geometry.iso.primitive.CurveImpl)

Aggregations

CurveImpl (org.geotools.geometry.iso.primitive.CurveImpl)5 SurfaceImpl (org.geotools.geometry.iso.primitive.SurfaceImpl)3 Primitive (org.opengis.geometry.primitive.Primitive)2 Ring (org.opengis.geometry.primitive.Ring)2 ParseException (java.text.ParseException)1 MultiPrimitiveImpl (org.geotools.geometry.iso.aggregate.MultiPrimitiveImpl)1 PointImpl (org.geotools.geometry.iso.primitive.PointImpl)1