public static WKTGeometry parseWKTString(String wktString){
  if (wktParser == null) {
    initialise();
  }
  if (wktString == null) {
    return null;
  }
  WKTGeometry wktGeometry=new WKTGeometry();
  if (wktString.startsWith(WKT_PREFIX)) {
    wktString=wktString.substring(WKT_PREFIX.length());
  }
  try {
    org.opengis.geometry.Geometry geometry=wktParser.parse(wktString);
    if (geometry instanceof MultiPrimitiveImpl) {
      int index=0;
      MultiPrimitiveImpl multiLine=(MultiPrimitiveImpl)geometry;
      for (      Primitive primitive : multiLine.getElements()) {
        if (primitive instanceof CurveImpl) {
          WKTSegmentList ptList=new WKTSegmentList();
          wktGeometry.setGeometryType(getWKTType(WKT_MULTILINESTRING));
          CurveImpl curve=(CurveImpl)primitive;
          extractLineSegments(curve,ptList);
          wktGeometry.addSegmentList(index,ptList);
        }
 else         if (primitive instanceof PointImpl) {
          WKTSegmentList ptList=new WKTSegmentList();
          wktGeometry.setGeometryType(getWKTType(WKT_MULTIPOINT));
          PointImpl point=(PointImpl)primitive;
          WKTPoint wktPoint=new WKTPoint(point.getDirectPosition());
          ptList.addPoint(wktPoint);
          wktGeometry.addSegmentList(index,ptList);
        }
 else         if (primitive instanceof SurfaceImpl) {
          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);
          }
        }
        index++;
      }
    }
 else     if (geometry instanceof PointImpl) {
      wktGeometry.setGeometryType(getWKTType(WKT_POINT));
      PointImpl pointImpl=(PointImpl)geometry;
      WKTSegmentList ptList=new WKTSegmentList();
      wktGeometry.addSegmentList(0,ptList);
      WKTPoint point=new WKTPoint(pointImpl.getDirectPosition());
      ptList.addPoint(point);
    }
 else     if (geometry instanceof CurveImpl) {
      wktGeometry.setGeometryType(getWKTType(WKT_LINESTRING));
      CurveImpl curveImpl=(CurveImpl)geometry;
      WKTSegmentList ptList=new WKTSegmentList();
      wktGeometry.addSegmentList(0,ptList);
      extractLineSegments(curveImpl,ptList);
    }
 else     if (geometry instanceof SurfaceImpl) {
      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);
          }
        }
      }
    }
  }
 catch (  ParseException e) {
    wktGeometry.setValid(false);
    for (    WKTType wktType : wktTypeList) {
      if (wktString.startsWith(wktType.getName())) {
        wktGeometry.setGeometryType(wktType);
      }
    }
  }
  return wktGeometry;
}

public static WKTGeometry parseWKTString ( String wktString ) { if ( wktParser == null ) { initialise ( ) ; } if ( wktString == null ) { return null ; } WKTGeometry wktGeometry = new WKTGeometry ( ) ; if ( wktString . startsWith ( WKT_PREFIX ) ) { wktString = wktString . substring ( WKT_PREFIX . length ( ) ) ; } try { org . opengis . geometry . Geometry geometry = wktParser . parse ( wktString ) ; if ( geometry instanceof MultiPrimitiveImpl ) { int index = 0 ; MultiPrimitiveImpl multiLine = ( MultiPrimitiveImpl ) geometry ; for ( Primitive primitive : multiLine . getElements ( ) ) { if ( primitive instanceof CurveImpl ) { WKTSegmentList ptList = new WKTSegmentList ( ) ; wktGeometry . setGeometryType ( getWKTType ( WKT_MULTILINESTRING ) ) ; CurveImpl curve = ( CurveImpl ) primitive ; extractLineSegments ( curve , ptList ) ; wktGeometry . addSegmentList ( index , ptList ) ; } else if ( primitive instanceof PointImpl ) { WKTSegmentList ptList = new WKTSegmentList ( ) ; wktGeometry . setGeometryType ( getWKTType ( WKT_MULTIPOINT ) ) ; PointImpl point = ( PointImpl ) primitive ; WKTPoint wktPoint = new WKTPoint ( point . getDirectPosition ( ) ) ; ptList . addPoint ( wktPoint ) ; wktGeometry . addSegmentList ( index , ptList ) ; } else if ( primitive instanceof SurfaceImpl ) { 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 ) ; } } index ++ ; } } else if ( geometry instanceof PointImpl ) { wktGeometry . setGeometryType ( getWKTType ( WKT_POINT ) ) ; PointImpl pointImpl = ( PointImpl ) geometry ; WKTSegmentList ptList = new WKTSegmentList ( ) ; wktGeometry . addSegmentList ( 0 , ptList ) ; WKTPoint point = new WKTPoint ( pointImpl . getDirectPosition ( ) ) ; ptList . addPoint ( point ) ; } else if ( geometry instanceof CurveImpl ) { wktGeometry . setGeometryType ( getWKTType ( WKT_LINESTRING ) ) ; CurveImpl curveImpl = ( CurveImpl ) geometry ; WKTSegmentList ptList = new WKTSegmentList ( ) ; wktGeometry . addSegmentList ( 0 , ptList ) ; extractLineSegments ( curveImpl , ptList ) ; } else if ( geometry instanceof SurfaceImpl ) { 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 ) ; } } } } } catch ( ParseException e ) { wktGeometry . setValid ( false ) ; for ( WKTType wktType : wktTypeList ) { if ( wktString . startsWith ( wktType . getName ( ) ) ) { wktGeometry . setGeometryType ( wktType ) ; } } } return wktGeometry ; }
parses the wkt string .
