TransWikia.com

OpenLayers : intersect between polygon and circle not accurate

Geographic Information Systems Asked by Thomas Vanneuville on June 23, 2021

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'));
  }
}

One Answer

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.

Correct answer by Mike on June 23, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP