
// WTKExamples.java
// Andrew Davison, ad@coe.psu.ac.th, March 2023

/* Convert a WTK (Well-known text) string into a geometry, 
   load WTK shapes from a file, and write the shapes into a file.

   More info on WTK:
     https://en.m.wikipedia.org/wiki/Well-known_text_representation_of_geometry
     https://libgeos.org/specifications/wkt/

   Usage:
    > compile WTKExamples.java
    > run WTKExamples
*/


import java.util.*;

import org.locationtech.jts.geom.*;
import org.locationtech.jts.io.WKTReader;
import org.locationtech.jts.awt.*;


public class WTKExamples
{
  public static void main(String[] args)
  {
    GeomsViewer gv = Utils.view("WTK Examples");

    Geometry g1 = Utils.toGeometry("LINESTRING (20 20, 80 80, 140 180)");
    System.out.println("Geometry 1: " + g1);
    gv.add(g1);
    Utils.pause(1000);
    System.out.println();

    ArrayList<Geometry> geoms = Utils.loadGeoms("data1.txt");
        // note: could use WKBReader
    System.out.println("\nLoaded geometries:");
    for(Geometry g : geoms) {
      System.out.println(" " + Utils.simplify(g));
      gv.add(g);
    }
    System.out.println();

    Utils.saveGeoms(geoms, "copy1.txt");
  } // end of main()

} // end of WTKExamples class
