Tabnine Logo
Geometry.intersection
Code IndexAdd Tabnine to your IDE (free)

How to use
intersection
method
in
com.vividsolutions.jts.geom.Geometry

Best Java code snippets using com.vividsolutions.jts.geom.Geometry.intersection (Showing top 20 results out of 405)

origin: osmandapp/Osmand

/**
 * JTS 1.14 does not support intersection on a {@link GeometryCollection}. This function works around this
 * by performing intersection on a flat list of geometry. The resulting list is pre-filtered for invalid
 * or empty geometry (outside of bounds). Invalid geometry are logged as errors.
 *
 * @param envelope non-list geometry defines bounding area
 * @param dataGeoms geometry pre-passed through {@link #flatFeatureList(Geometry)}
 * @return list of geometry from {@code data} intersecting with {@code envelope}.
 */
private static List<Geometry> flatIntersection(Geometry envelope, List<Geometry> dataGeoms) {
  final List<Geometry> intersectedGeoms = new ArrayList<>(dataGeoms.size());
  Geometry nextIntersected;
  for(Geometry nextGeom : dataGeoms) {
    try {
      // AABB intersection culling
      if(envelope.getEnvelopeInternal().intersects(nextGeom.getEnvelopeInternal())) {
        nextIntersected = envelope.intersection(nextGeom);
        if(!nextIntersected.isEmpty()) {
          nextIntersected.setUserData(nextGeom.getUserData());
          intersectedGeoms.add(nextIntersected);
        }
      }
    } catch (TopologyException e) {
      //LoggerFactory.getLogger(JtsAdapter.class).error(e.getMessage(), e);
    }
  }
  return intersectedGeoms;
}
origin: com.vividsolutions/jts

 public Geometry map(Geometry g) {
  return g.intersection(g2);
 }
});
origin: opentripplanner/OpenTripPlanner

for (NamedArea area : areas) {
  Geometry polygon = area.getPolygon();
  Geometry intersection = polygon.intersection(line);
  if (intersection.getLength() > 0.000001) {
    intersects.add(area);
origin: com.vividsolutions/jts

public void intersection(String wktA, String wktB, PrecisionModel pm)
  throws ParseException
{
 System.out.println("Running example using Precision Model = " + pm);
 GeometryFactory fact = new GeometryFactory(pm);
 WKTReader wktRdr = new WKTReader(fact);
 Geometry A = wktRdr.read(wktA);
 Geometry B = wktRdr.read(wktB);
 Geometry C = A.intersection(B);
 System.out.println("A intersection B = " + C);
}
origin: com.vividsolutions/jts

 public static void main(String[] args)
   throws Exception
 {
  // read a geometry from a WKT string (using the default geometry factory)
  Geometry g1 = new WKTReader().read("LINESTRING (0 0, 10 10, 20 20)");
  System.out.println("Geometry 1: " + g1);

  // create a geometry by specifying the coordinates directly
  Coordinate[] coordinates = new Coordinate[]{new Coordinate(0, 0),
   new Coordinate(10, 10), new Coordinate(20, 20)};
  // use the default factory, which gives full double-precision
  Geometry g2 = new GeometryFactory().createLineString(coordinates);
  System.out.println("Geometry 2: " + g2);

  // compute the intersection of the two geometries
  Geometry g3 = g1.intersection(g2);
  System.out.println("G1 intersection G2: " + g3);
 }
}
origin: com.vividsolutions/jts

/**
 * Computes the set-theoretic intersection of two {@link Geometry}s, using enhanced precision.
 * @param geom0 the first Geometry
 * @param geom1 the second Geometry
 * @return the Geometry representing the set-theoretic intersection of the input Geometries.
 */
public Geometry intersection(Geometry geom0, Geometry geom1)
{
 Geometry[] geom = removeCommonBits(geom0, geom1);
 return computeResultPrecision(geom[0].intersection(geom[1]));
}
origin: com.vividsolutions/jts

public void run()
 throws ParseException
{
 GeometryFactory fact = new GeometryFactory();
 WKTReader wktRdr = new WKTReader(fact);
 String wktA = "POLYGON((40 100, 40 20, 120 20, 120 100, 40 100))";
 String wktB = "LINESTRING(20 80, 80 60, 100 140)";
 Geometry A = wktRdr.read(wktA);
 Geometry B = wktRdr.read(wktB);
 Geometry C = A.intersection(B);
 System.out.println("A = " + A);
 System.out.println("B = " + B);
 System.out.println("A intersection B = " + C);
 System.out.println("A relate C = " + A.relate(B));
}
origin: com.vividsolutions/jts

public double measure(Geometry g1, Geometry g2)
{        
  double areaInt = g1.intersection(g2).getArea();
  double areaUnion = g1.union(g2).getArea();
  return areaInt / areaUnion;
}
 
origin: com.vividsolutions/jts

void run()
  throws Exception
{
 String wkt1, wkt2;
 // two geometries which cause robustness problems
 wkt1 = "POLYGON ((708653.498611049 2402311.54647056, 708708.895756966 2402203.47250014, 708280.326454234 2402089.6337791, 708247.896591321 2402252.48269854, 708367.379593851 2402324.00761653, 708248.882609455 2402253.07294874, 708249.523621829 2402244.3124463, 708261.854734465 2402182.39086576, 708262.818392579 2402183.35452387, 708653.498611049 2402311.54647056))";
 wkt2 = "POLYGON ((708258.754920656 2402197.91172757, 708257.029447455 2402206.56901508, 708652.961095455 2402312.65463437, 708657.068786251 2402304.6356364, 708258.754920656 2402197.91172757))";
 Geometry g1 = reader.read(wkt1);
 Geometry g2 = reader.read(wkt2);
 System.out.println("This call to intersection will throw a topology exception due to robustness problems:");
 try {
  Geometry result = g1.intersection(g2);
 }
 catch (TopologyException ex) {
  ex.printStackTrace();
 }
 System.out.println("Using EnhancedPrecisionOp allows the intersection to be performed with no errors:");
 Geometry result = EnhancedPrecisionOp.intersection(g1, g2);
 System.out.println(result);
}
origin: com.vividsolutions/jts

Geometry result = geom0.intersection(geom1);
return result;
origin: com.vividsolutions/jts

System.out.println("Internal rep for g2: " + ((Polygon) g2).getExteriorRing().getCoordinateSequence());
Geometry gInt = g1.intersection(g2);
origin: org.orbisgis/h2gis

  /**
   * @param a Geometry instance.
   * @param b Geometry instance
   * @return the intersection between two geometries
   */
  public static Geometry intersection(Geometry a,Geometry b) {
    if(a==null || b==null) {
      return null;
    }
    return a.intersection(b);
  }
}
origin: com.vividsolutions/jts

  private static Geometry clipGeometryCollection(Geometry geom, Envelope clipEnv)
  {
    Geometry clipPoly = geom.getFactory().toGeometry(clipEnv);
    List clipped = new ArrayList();
    for (int i = 0; i < geom.getNumGeometries(); i++) {
      Geometry g = geom.getGeometryN(i);
      Geometry result = null;
      // don't clip unless necessary
      if (clipEnv.contains(g.getEnvelopeInternal()))
          result = g;
      else if (clipEnv.intersects(g.getEnvelopeInternal())) {
        result = clipPoly.intersection(g);
        // keep vertex key info
        result.setUserData(g.getUserData());
      }

      if (result != null && ! result.isEmpty()) {
        clipped.add(result);
      }
    }
    return geom.getFactory().createGeometryCollection(GeometryFactory.toGeometryArray(clipped));
  }
}
origin: matsim-org/matsim

  static Collection<Geometry> cutPolygonsByBoundary(Collection<Polygon> polygons, Polygon boundingPolygon) {
    Collection<Geometry> cutPolygons = new LinkedList<>();
    for (Polygon polygon : polygons) {
      // Need to determine convex hull of geometry to prevent it from staying self-intersecting
      Geometry hull = polygon.convexHull();
      Geometry intersection = hull.intersection(boundingPolygon);
      cutPolygons.add(intersection);
    }
    return cutPolygons;
  }
}
origin: com.vividsolutions/jts-example

public void intersection(String wktA, String wktB, PrecisionModel pm)
  throws ParseException
{
 System.out.println("Running example using Precision Model = " + pm);
 GeometryFactory fact = new GeometryFactory(pm);
 WKTReader wktRdr = new WKTReader(fact);
 Geometry A = wktRdr.read(wktA);
 Geometry B = wktRdr.read(wktB);
 Geometry C = A.intersection(B);
 System.out.println("A intersection B = " + C);
}
origin: org.geotools/gt-coverage

/**
 * Helper method for {@link #intersection(Geometry, Geometry) intersection(Geometry, Geometry)}
 */
private static List<Geometry> intersection(GeometryCollection gc, Geometry g) {
  List<Geometry> ret = new ArrayList<Geometry>();
  final int size=gc.getNumGeometries();
  for (int i = 0; i < size; i++) {
    Geometry g1 = (Geometry)gc.getGeometryN(i);
    collect(g1.intersection(g), ret);
  }
  return ret;
}
origin: Stratio/cassandra-lucene-index

/**
 * Returns the intersection of the specified shapes.
 *
 * @return the intersection
 */
@Override
public JtsGeometry apply() {
  Geometry result = shapes.get(0).apply().getGeom();
  for (int i = 1; i < shapes.size(); i++) {
    result = result.intersection(shapes.get(i).apply().getGeom());
  }
  return CONTEXT.makeShape(result);
}
origin: BaseXdb/basex

 @Override
 public Item item(final QueryContext qc, final InputInfo ii) throws QueryException {
  return toElement(checkGeo(0, qc).intersection(checkGeo(1, qc)), qc);
 }
}
origin: com.vividsolutions/jts-core

public double measure(Geometry g1, Geometry g2)
{        
  double areaInt = g1.intersection(g2).getArea();
  double areaUnion = g1.union(g2).getArea();
  return areaInt / areaUnion;
}
 
origin: org.teiid/teiid-engine

public static GeometryType intersection(GeometryType geom1, GeometryType geom2) throws FunctionExecutionException {
  Geometry g1 = getGeometry(geom1);
  Geometry g2 = getGeometry(geom2);
  return getGeometryType(g1.intersection(g2), geom1.getSrid());
}
com.vividsolutions.jts.geomGeometryintersection

Javadoc

Computes a Geometry representing the point-set which is common to both this Geometry and the other Geometry.

The intersection of two geometries of different dimension produces a result geometry of dimension less than or equal to the minimum dimension of the input geometries. The result geometry may be a heterogenous GeometryCollection. If the result is empty, it is an atomic geometry with the dimension of the lowest input dimension.

Intersection of GeometryCollections is supported only for homogeneous collection types.

Non-empty heterogeneous GeometryCollection arguments are not supported.

Popular methods of Geometry

  • getEnvelopeInternal
    Gets an Envelope containing the minimum and maximum x and y values in this Geometry. If the geometr
  • getCoordinates
    Returns an array containing the values of all the vertices for this geometry. If the geometry is a c
  • isEmpty
    Tests whether the set of points covered by this Geometry is empty.
  • getCentroid
    Computes the centroid of this Geometry. The centroid is equal to the centroid of the set of componen
  • getGeometryN
    Returns an element Geometry from a GeometryCollection(or this, if the geometry is not a collection).
  • toText
    Returns the Well-known Text representation of this Geometry. For a definition of the Well-known Text
  • getNumGeometries
    Returns the number of Geometrys in a GeometryCollection(or 1, if the geometry is not a collection).
  • getFactory
    Gets the factory which contains the context in which this geometry was created.
  • getGeometryType
    Returns the name of this Geometry's actual class.
  • getSRID
    Returns the ID of the Spatial Reference System used by the Geometry. JTS supports Spatial Reference
  • getCoordinate
    Returns a vertex of this Geometry (usually, but not necessarily, the first one). The returned coordi
  • buffer
    Computes a buffer area around this geometry having the given width and with a specified accuracy of
  • getCoordinate,
  • buffer,
  • contains,
  • getArea,
  • getEnvelope,
  • intersects,
  • union,
  • apply,
  • getLength

Popular in Java

  • Reactive rest calls using spring rest template
  • startActivity (Activity)
  • getSystemService (Context)
  • getExternalFilesDir (Context)
  • BufferedReader (java.io)
    Wraps an existing Reader and buffers the input. Expensive interaction with the underlying reader is
  • GregorianCalendar (java.util)
    GregorianCalendar is a concrete subclass of Calendarand provides the standard calendar used by most
  • TimeZone (java.util)
    TimeZone represents a time zone offset, and also figures out daylight savings. Typically, you get a
  • Executor (java.util.concurrent)
    An object that executes submitted Runnable tasks. This interface provides a way of decoupling task s
  • AtomicInteger (java.util.concurrent.atomic)
    An int value that may be updated atomically. See the java.util.concurrent.atomic package specificati
  • Scheduler (org.quartz)
    This is the main interface of a Quartz Scheduler. A Scheduler maintains a registry of org.quartz.Job
  • Best IntelliJ plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now