Geographic Information Systems Asked by Thomas Vanneuville on June 23, 2021
When I look for intersect between circle and polygon. He finds intersect between these two, who are not visually intersected.
Everything should have the same projection (‘EPSG:3857’). But I don’t know how I can check the projection of each feature.
My code :
var circle = new Circle(transformedCoordinates, radius);
var circleFeature = new Feature(circle);
var circleSource = new VectorSource();
circleSource.addFeature(circleFeature);
var circleLayer = new VectorLayer({
source: circleSource
});
var features = this.neighbourhoodLayer.getSource().getFeatures();
var nisCodesInCircle = [];
var circleExtent = circleFeature.getGeometry().getExtent();
for(var i = 0; i < features.length; i ++) {
if(intersects(circleExtent, features[i].getGeometry().getExtent())) {
nisCodesInCircle.push(features[i].get('id'));
}
}
That is the correct result, the extents do intersect
To test if the geometries intersect you will need a third party utility such as turf https://turfjs.org/docs/#intersect
Or in this case you could find the closest point on the polygon to the center of the circle https://openlayers.org/en/latest/apidoc/module-ol_geom_Polygon-Polygon.html#getClosestPoint If that is within the radius of the circle they intersect.
Correct answer by Mike on June 23, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP