com.vividsolutions.jts.geom.prep.PreparedGeometryFactory Java Examples

The following examples show how to use com.vividsolutions.jts.geom.prep.PreparedGeometryFactory. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: InvalidHoleRemover.java    From jts with GNU Lesser General Public License v2.1 6 votes vote down vote up
public Polygon getResult()
{
  GeometryFactory gf = poly.getFactory();
  Polygon shell = gf.createPolygon((LinearRing) poly.getExteriorRing());
  PreparedGeometry shellPrep = PreparedGeometryFactory.prepare(shell);
  
  List holes = new ArrayList();
  for (int i = 0; i < poly.getNumInteriorRing(); i++) {
    LinearRing hole = (LinearRing) poly.getInteriorRingN(i);
    if (shellPrep.covers(hole)) {
      holes.add(hole);
    }
  }
  // all holes valid, so return original
  if (holes.size() == poly.getNumInteriorRing())
    return poly;
  
  // return new polygon with covered holes only
  Polygon result = gf.createPolygon((LinearRing) poly.getExteriorRing(), 
      GeometryFactory.toLinearRingArray(holes));
  return result;
}
 
Example #2
Source File: WebMercatorTile.java    From xyz-hub with Apache License 2.0 5 votes vote down vote up
public PreparedGeometry getAsPolygon() {
  if (polygon != null) {
    return polygon;
  }

  final BBox bbox = getBBox(false);
  final Envelope envelope = new Envelope(bbox.minLon(), bbox.maxLon(), bbox.minLat(), bbox.maxLat());
  polygon = PreparedGeometryFactory.prepare(JTSHelper.factory.toGeometry(envelope));
  return polygon;
}
 
Example #3
Source File: WebMercatorTile.java    From xyz-hub with Apache License 2.0 5 votes vote down vote up
public PreparedGeometry getExtendedBBoxAsPolygon(int buffer) {
  if (ePolygon != null && ePolygonBuffer == buffer) {
    return ePolygon;
  }

  final BBox bbox = getExtendedBBox(buffer);
  final Envelope envelope = new Envelope(bbox.minLon(), bbox.maxLon(), bbox.minLat(), bbox.maxLat());

  ePolygonBuffer = buffer;
  ePolygon = PreparedGeometryFactory.prepare(JTSHelper.factory.toGeometry(envelope));
  return ePolygon;
}
 
Example #4
Source File: PreparedGeometryTeeOperation.java    From jts with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void checkAllPrepOps(Geometry g1, Geometry g2)
{
   PreparedGeometry prepGeom = PreparedGeometryFactory.prepare(g1);

	checkIntersects(prepGeom, g2);
	checkContains(prepGeom, g2);
	checkContainsProperly(prepGeom, g2);
	checkCovers(prepGeom, g2);	
}
 
Example #5
Source File: PreparedGeometryFunctions.java    From jts with GNU Lesser General Public License v2.1 4 votes vote down vote up
private static PreparedGeometry createPG(Geometry g)
{
  return (new PreparedGeometryFactory()).create(g);
}
 
Example #6
Source File: PreparedGeometryTeeOperation.java    From jts with GNU Lesser General Public License v2.1 4 votes vote down vote up
public static boolean intersects(Geometry g1, Geometry g2)
{
   PreparedGeometryFactory pgFact = new PreparedGeometryFactory();
   PreparedGeometry prepGeom = pgFact.create(g1);
   return prepGeom.intersects(g2);
}
 
Example #7
Source File: PreparedGeometryTeeOperation.java    From jts with GNU Lesser General Public License v2.1 4 votes vote down vote up
public static boolean contains(Geometry g1, Geometry g2)
{
   PreparedGeometryFactory pgFact = new PreparedGeometryFactory();
   PreparedGeometry prepGeom = pgFact.create(g1);
   return prepGeom.contains(g2);
}
 
Example #8
Source File: PreparedGeometryTeeOperation.java    From jts with GNU Lesser General Public License v2.1 4 votes vote down vote up
public static boolean covers(Geometry g1, Geometry g2)
{
   PreparedGeometryFactory pgFact = new PreparedGeometryFactory();
   PreparedGeometry prepGeom = pgFact.create(g1);
   return prepGeom.contains(g2);
}
 
Example #9
Source File: PreparedGeometryThreadSafeTest.java    From jts with GNU Lesser General Public License v2.1 4 votes vote down vote up
public void setup()
{
  Geometry sinePoly = createSineStar(new Coordinate(0, 0), 100000.0, nPts);
  pg = PreparedGeometryFactory.prepare(sinePoly);
  g = createSineStar(new Coordinate(10, 10), 100000.0, 100);
}