Tabnine Logo
TurfJoins
Code IndexAdd Tabnine to your IDE (free)

How to use
TurfJoins
in
com.mapbox.turf

Best Java code snippets using com.mapbox.turf.TurfJoins (Showing top 8 results out of 315)

origin: mapbox/mapbox-java

/**
 * Takes a {@link Point} and a {@link Polygon} and determines if the point resides inside the
 * polygon. The polygon can be convex or concave. The function accounts for holes.
 *
 * @param point   which you'd like to check if inside the polygon
 * @param polygon which you'd like to check if the points inside
 * @return true if the Point is inside the Polygon; false if the Point is not inside the Polygon
 * @see <a href="http://turfjs.org/docs/#inside">Turf Inside documentation</a>
 * @since 1.3.0
 */
public static boolean inside(Point point, Polygon polygon) {
 // This API needs to get better
 List<List<Point>> coordinates = polygon.coordinates();
 List<List<List<Point>>> multiCoordinates = new ArrayList<>();
 multiCoordinates.add(coordinates);
 return inside(point, MultiPolygon.fromLngLats(multiCoordinates));
}
origin: mapbox/mapbox-java

for (int i = 0; i < polys.size() && !insidePoly; i++) {
 if (inRing(point, polys.get(i).get(0))) {
  boolean inHole = false;
  int temp = 1;
   if (inRing(point, polys.get(i).get(temp))) {
    inHole = true;
origin: mapbox/mapbox-java

FeatureCollection ptFeatureCollection = FeatureCollection.fromFeatures(features2);
FeatureCollection counted = TurfJoins.pointsWithinPolygon(ptFeatureCollection, polyFeatureCollection);
assertNotNull(counted);
assertEquals(counted.features().size(), 1); // 1 point in 1 polygon
 Feature.fromGeometry(pt4), Feature.fromGeometry(pt5), Feature.fromGeometry(pt6)});
counted = TurfJoins.pointsWithinPolygon(ptFeatureCollection, polyFeatureCollection);
assertNotNull(counted);
assertEquals(counted.features().size(), 5); // multiple points in multiple polygons
origin: mapbox/mapbox-java

/**
 * Takes a {@link FeatureCollection} of {@link Point} and a {@link FeatureCollection} of
 * {@link Polygon} and returns the points that fall within the polygons.
 *
 * @param points   input points.
 * @param polygons input polygons.
 * @return points that land within at least one polygon.
 * @since 1.3.0
 */
public static FeatureCollection pointsWithinPolygon(FeatureCollection points,
                          FeatureCollection polygons) {
 ArrayList<Feature> features = new ArrayList<>();
 for (int i = 0; i < polygons.features().size(); i++) {
  for (int j = 0; j < points.features().size(); j++) {
   Point point = (Point) points.features().get(j).geometry();
   boolean isInside
    = TurfJoins.inside(point, (Polygon) polygons.features().get(i).geometry());
   if (isInside) {
    features.add(Feature.fromGeometry(point));
   }
  }
 }
 return FeatureCollection.fromFeatures(features);
}
origin: mapbox/mapbox-java

@Test
public void testMultipolygonWithHole() throws TurfException, IOException {
 Point ptInHole = Point.fromLngLat(-86.69208526611328, 36.20373274711739);
 Point ptInPoly = Point.fromLngLat(-86.72229766845702, 36.20258997094334);
 Point ptInPoly2 = Point.fromLngLat(-86.75079345703125, 36.18527313913089);
 Point ptOutsidePoly = Point.fromLngLat(-86.75302505493164, 36.23015046460186);
 Feature multiPolyHole = Feature.fromJson(loadJsonFixture(MULTIPOLY_WITH_HOLE_FIXTURE));
 assertFalse(TurfJoins.inside(ptInHole, (MultiPolygon) multiPolyHole.geometry()));
 assertTrue(TurfJoins.inside(ptInPoly, (MultiPolygon) multiPolyHole.geometry()));
 assertTrue(TurfJoins.inside(ptInPoly2, (MultiPolygon) multiPolyHole.geometry()));
 assertFalse(TurfJoins.inside(ptOutsidePoly, (MultiPolygon) multiPolyHole.geometry()));
}
origin: mapbox/mapbox-java

@Test
public void testPolyWithHole() throws TurfException, IOException {
 Point ptInHole = Point.fromLngLat(-86.69208526611328, 36.20373274711739);
 Point ptInPoly = Point.fromLngLat(-86.72229766845702, 36.20258997094334);
 Point ptOutsidePoly = Point.fromLngLat(-86.75079345703125, 36.18527313913089);
 Feature polyHole = Feature.fromJson(loadJsonFixture(POLY_WITH_HOLE_FIXTURE));
 assertFalse(TurfJoins.inside(ptInHole, (Polygon) polyHole.geometry()));
 assertTrue(TurfJoins.inside(ptInPoly, (Polygon) polyHole.geometry()));
 assertFalse(TurfJoins.inside(ptOutsidePoly, (Polygon) polyHole.geometry()));
}
origin: mapbox/mapbox-java

Point ptOut = Point.fromLngLat(140, 150);
assertTrue(TurfJoins.inside(ptIn, poly));
assertFalse(TurfJoins.inside(ptOut, poly));
ptOut = Point.fromLngLat(25, 50);
assertTrue(TurfJoins.inside(ptIn, concavePoly));
assertFalse(TurfJoins.inside(ptOut, concavePoly));
origin: mapbox/mapbox-java

@Test
public void testInputPositions() throws IOException, TurfException {
 Point ptInPoly = Point.fromLngLat(-86.72229766845702, 36.20258997094334);
 Point ptOutsidePoly = Point.fromLngLat(-86.75079345703125, 36.18527313913089);
 Feature polyHole = Feature.fromJson(loadJsonFixture(POLY_WITH_HOLE_FIXTURE));
 Polygon polygon = (Polygon) polyHole.geometry();
 assertTrue(TurfJoins.inside(ptInPoly, polygon));
 assertFalse(TurfJoins.inside(ptOutsidePoly, polygon));
}
com.mapbox.turfTurfJoins

Javadoc

Class contains methods that can determine if points lie within a polygon or not.

Most used methods

  • inside
    Takes a Point and a Polygon and determines if the point resides inside the polygon. The polygon can
  • inRing
  • pointsWithinPolygon
    Takes a FeatureCollection of Point and a FeatureCollection of Polygon and returns the points that fa

Popular in Java

  • Making http requests using okhttp
  • orElseThrow (Optional)
    Return the contained value, if present, otherwise throw an exception to be created by the provided s
  • findViewById (Activity)
  • getOriginalFilename (MultipartFile)
    Return the original filename in the client's filesystem.This may contain path information depending
  • ObjectMapper (com.fasterxml.jackson.databind)
    ObjectMapper provides functionality for reading and writing JSON, either to and from basic POJOs (Pl
  • KeyStore (java.security)
    KeyStore is responsible for maintaining cryptographic keys and their owners. The type of the syste
  • Date (java.sql)
    A class which can consume and produce dates in SQL Date format. Dates are represented in SQL as yyyy
  • Date (java.util)
    A specific moment in time, with millisecond precision. Values typically come from System#currentTime
  • JTextField (javax.swing)
  • BasicDataSource (org.apache.commons.dbcp)
    Basic implementation of javax.sql.DataSource that is configured via JavaBeans properties. This is no
  • Top plugins for WebStorm
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