All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.vividsolutions.jtstest.function.PolygonizeFunctions Maven / Gradle / Ivy

package com.vividsolutions.jtstest.function;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.geom.GeometryFactory;
import com.vividsolutions.jts.geom.Polygon;
import com.vividsolutions.jts.geom.util.LineStringExtracter;
import com.vividsolutions.jts.operation.polygonize.Polygonizer;

public class PolygonizeFunctions {

  private static Geometry polygonize(Geometry g, boolean extractOnlyPolygonal) {
    List lines = LineStringExtracter.getLines(g);
    Polygonizer polygonizer = new Polygonizer(extractOnlyPolygonal);
    polygonizer.add(lines);
    return polygonizer.getGeometry();
    /*
    Collection polys = polygonizer.getPolygons();
    Polygon[] polyArray = GeometryFactory.toPolygonArray(polys);
    return g.getFactory().createGeometryCollection(polyArray);
    */
  }
  public static Geometry polygonize(Geometry g)
  {
    return polygonize(g, false);
  }
  public static Geometry polygonizePolygonal(Geometry g)
  {
    return polygonize(g, true);
  }
  public static Geometry polygonizeDangles(Geometry g)
  {
    List lines = LineStringExtracter.getLines(g);
    Polygonizer polygonizer = new Polygonizer();
    polygonizer.add(lines);
    Collection geom = polygonizer.getDangles();
    return g.getFactory().buildGeometry(geom);
  }
  public static Geometry polygonizeCutEdges(Geometry g)
  {
    List lines = LineStringExtracter.getLines(g);
    Polygonizer polygonizer = new Polygonizer();
    polygonizer.add(lines);
    Collection geom = polygonizer.getCutEdges();
    return g.getFactory().buildGeometry(geom);
  }
  public static Geometry polygonizeInvalidRingLines(Geometry g)
  {
    List lines = LineStringExtracter.getLines(g);
    Polygonizer polygonizer = new Polygonizer();
    polygonizer.add(lines);
    Collection geom = polygonizer.getInvalidRingLines();
    return g.getFactory().buildGeometry(geom);
  }
  public static Geometry polygonizeAllErrors(Geometry g)
  {
    List lines = LineStringExtracter.getLines(g);
    Polygonizer polygonizer = new Polygonizer();
    polygonizer.add(lines);
    List errs = new ArrayList();
    errs.addAll(polygonizer.getDangles());
    errs.addAll(polygonizer.getCutEdges());
    errs.addAll(polygonizer.getInvalidRingLines());
    return g.getFactory().buildGeometry(errs);
  }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy