Turf: Polygons with area less than 1 won't be used on difference.

Created on 15 Jan 2019  路  1Comment  路  Source: Turfjs/turf

Looking at the difference code found that the following function is being used to remove "empty" polygons:

/**
 * Detect Empty Polygon
 *
 * @private
 * @param {Geometry<Polygon|MultiPolygon>} geom Geometry Object
 * @returns {Geometry<Polygon|MultiPolygon>|null} removed any polygons with no areas
 */
function removeEmptyPolygon(geom) {
    switch (geom.type) {
    case 'Polygon':
        if (area(geom) > 1) return geom;
        return null;
    case 'MultiPolygon':
        var coordinates = [];
        flattenEach(geom, function (feature) {
            if (area(feature) > 1) coordinates.push(feature.geometry.coordinates);
        });
        if (coordinates.length) return {type: 'MultiPolygon', coordinates: coordinates};
    }
}

Now, in our use case we every now and then subtract polygons with areas smaller than one square foot, thus we have the following questions:

  • There is any specific reason to use the area of a polygon to decide if its empty?
  • There is any reason to use 1 as this threshold?
  • If there is a strong reason to use the area to check for empty polygons and not a good one to use specifically 1 as a threshold, could the threshold be passed as an argument (perhaps in a options object) to the difference function? (I could open a PR for this if needed).

Thanks in advance for your help and keep the amazing work.

need-review

Most helpful comment

Hi @jesus-deepblocks

That does seem curious, I suspect it was probably put there to help handle errors.

In my v7 branch we're replacing the dependency that manages the difference operation and so we might be able to relook at whether that check is still required, I'll try and run a check and report back.

Cheers

>All comments

Hi @jesus-deepblocks

That does seem curious, I suspect it was probably put there to help handle errors.

In my v7 branch we're replacing the dependency that manages the difference operation and so we might be able to relook at whether that check is still required, I'll try and run a check and report back.

Cheers

Was this page helpful?
0 / 5 - 0 ratings