2

enter image description here

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'));
  }
}
2
  • Constructing a circle in a projection that doesn't honor distance (3857) is probably less than useful for analysis.
    – Vince
    Mar 30, 2021 at 13:56
  • Does this return the BBOX/Envelope of the circle var circleExtent = circleFeature.getGeometry().getExtent();?
    – user30184
    Mar 30, 2021 at 13:59

1 Answer 1

6

That is the correct result, the extents do intersect

enter image description here

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.

2
  • With circle.intersectsCoordinate() ? Mar 30, 2021 at 14:12
  • Yes (or you could calculate the distance using Pythagoras)
    – Mike
    Mar 30, 2021 at 14:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.