How to use the turf.inside function in turf

To help you get started, we’ve selected a few turf examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ProgressiveMass / legislator-scorecard / src / abandoned / getDistrict.js View on Github external
const matches = massSenate.features.filter((f) => {
      // f is already a geojson polygon
    return turf.inside(point, f)
  })
github davidmcclure / earthxray / src / javascripts / lib / borders.js View on Github external
let [lon, lat] = utils.xyzToLonLat(x, y, z);

    let point = {
      geometry: {
        type: 'Point',
        coordinates: [lon, lat]
      }
    };

    // Get the N nearest points.
    let nn = knn(this.tree, [lon, lat], 20);
    let country = null;

    // Probe for a parent country.
    for (let n of nn) {
      if (turf.inside(point, n.feature)) {
        country = n.feature;
        break;
      }
    }

    return country;

  }
github funkeinteraktiv / cogran / lib / methods / attribute-weighting-relative.js View on Github external
intersects.forEach((d,i) => {
    const At = Turf.area(feature);
    const Ast = Turf.area(d);
    const Qt = feature.properties[options.weight];
    const Qst = (Ast / At) * Qt;

    const attributeValue = parseFloat(sourceFeatures[i].properties[options.attr]);

    // wenn komplett im source feature,
    const sb = Turf.extent(sourceFeatures[i]);
    let isInside = true;

    if(!Turf.inside(Turf.point([sb[0], sb[1]]), d)) { isInside = false };
    if(!Turf.inside(Turf.point([sb[2], sb[3]]), d)) { isInside = false };

    if(isInside) {
      if(!isNaN(attributeValue)) {
        result += Ps;
      }
      return;
    }


    if(!isNaN(attributeValue)) {
      result += (Qst / sourceFeatures[i].properties["Qs"]) * attributeValue;
    }
  });
github jpwright / subway / tools / demanderator.js View on Github external
}
                demand.push(dim);
            }
            
            var landmark_polygons_of_interest = {"JFK Airport": 0, "LaGuardia Airport": 0, "Grand Central": 0, "Port Authority Bus Terminal": 0, "Penn Station": 0};
            var landmark_scalers = {"JFK Airport": 11000.0, "LaGuardia Airport": 9000.0, "Grand Central": 2000.0, "Port Authority Bus Terminal": 1000.0, "Penn Station": 2000.0};
            
            for (landmark_index = 0; landmark_index < landmarks_data["features"].length; landmark_index++) {
                var landmark = landmarks_data["features"][landmark_index];
                var landmark_name = landmark["properties"]["name"];
                if (landmark_name in landmark_polygons_of_interest) {
                    //console.log(landmark["geometry"]["coordinates"]);
                    var landmark_polygon = turf.polygon(landmark["geometry"]["coordinates"]);
                    landmark_polygons_of_interest[landmark_name] = landmark_polygon;
                    var landmark_centroid = turf.centroid(landmark_polygon);
                    console.log("Landmark "+landmark_name+" centroid in polygon: "+turf.inside(landmark_centroid, landmark_polygon));
                }
            }
            
            
            console.log("Calculating centroids");
            var centroids = [];
            for (tract_index = 0; tract_index < data.features.length; tract_index++) {
                var turf_centroid = turf.centroid(data.features[tract_index]);
                //var tract_area = turf.area(turf_polygons[tract_index]);
                centroids[tract_index] = turf_centroid;
            }
            
            console.log("Calculating voxels");
            for (i = 0; i < voxels_dim; i++) {
                var lat = lat_min + voxels_res_lat*i;
                for (j = 0; j < voxels_dim; j++) {
github jpwright / subway / tools / demanderator.js View on Github external
var overlap_area = turf.area(overlap_polygon);
                                var tract_area = turf.area(tract);
                                if (ct2010 in populations) {
                                    d += populations[ct2010] * overlap_area/tract_area;
                                } else {
                                    d += 1000.0 * overlap_area/tract_area;
                                }
                            }
                            
                        }
                    }
                    
                    var voxel_center = turf.point([lon + voxels_res_lon/2.0, lat + voxels_res_lat/2.0]);
                    for (lpoi in landmark_polygons_of_interest) {
                        if (turf.inside(voxel_center, landmark_polygons_of_interest[lpoi])) {
                            console.log("Inside "+lpoi);
                            d += 500.0;
                        }
                    }
                    
                    
                    //console.log(d);
                    demand[i][j] = d;
                    //console.log("Finished voxel "+(j+(i*voxels_dim))+" of "+voxels_total);
                    bar.tick();
                    if (bar.complete) {
                        console.log('complete!');
                    }
                }
            }
github fidelthomet / WHERE / scripts / inquire.js View on Github external
feature = turf.polygon([arr2])
	}

	var result = !expect

	if (obj.geometry.type == "Point" && type == "Point") {
		result = (obj.geometry.coordinates[0] == feature.geometry.coordinates[0] && obj.geometry.coordinates[1] == feature.geometry.coordinates[1])
	}
	if (obj.geometry.type == "Polygon" && type == "Polygon") {
		result = (turf.intersect(obj, feature) != undefined)
	}
	if (obj.geometry.type == "Point" && type == "Polygon") {
		result = (turf.inside(obj, feature))
	}
	if (obj.geometry.type == "Polygon" && type == "Point") {
		result = (turf.inside(feature, obj))
	}

	if (obj.geometry.type == "LineString" && type == "Polygon"){
		result = false
		var linestring = turf.linestring(feature.geometry.coordinates[0])
		if(lineIntersect(linestring.geometry, obj.geometry)){
			result = true
		} else {
			for (var i = 0; i < obj.geometry.coordinates.length; i++) {
				point = turf.point(obj.geometry.coordinates[i])
				if(turf.inside(point, feature)){
					result = true
					break
				}
			}
		}
github fidelthomet / WHERE / scripts / inquire.js View on Github external
result = true
					break
				}
			}
		}
	}

	if (obj.geometry.type == "Polygon" && type == "LineString"){
		result = false
		var linestring = turf.linestring(obj.geometry.coordinates[0])
		if(lineIntersect(linestring.geometry, feature.geometry)){
			result = true
		} else {
			for (var i = 0; i < feature.geometry.coordinates.length; i++) {
				point = turf.point(feature.geometry.coordinates[i])
				if(turf.inside(point, obj)){
					result = true
					break
				}
			}
		}
	}

	if (obj.geometry.type == "LineString" && type == "LineString"){
		if(lineIntersect(obj.geometry, feature.geometry)){
			result = true
		}
	}
	return (expect == result)

}
github frankrowe / iso / src / utils / VectorTools.js View on Github external
var updates = this.editFeatures(layers, function(bbox, gj, layer) {
      if (gj.geometry.type === 'Point') {
        if (turf.inside(gj, bbox)) {
          gj.selected = true
        }
      } else if (gj.geometry.type === 'LineString') {
        for (var i = 0; i < gj.geometry.coordinates.length; i++) {
          var pt = turf.point(gj.geometry.coordinates[i])
          if (turf.inside(pt, bbox)) {
            gj.selected = true
          }
        }
      } else if (gj.geometry.type === 'Polygon') {
        if (turf.intersect(gj, bbox)) {
          gj.selected = true
        }
      }
      return gj
    }.bind(null, bbox))
    LayerActions.updateList(updates)
github mapbox / cheap-ruler / bench / bench-inside-bbox.js View on Github external
'turf.inside + turf.bboxPolygon': function () {
        for (var i = 0; i < points.length; i++) {
            turf.inside(turf.point(points[i]), turf.bboxPolygon(bboxes[i]));
        }
    },
    'ruler.insideBBox': function () {