Turfjs / Turfjs/turf

booleanContains gives false positive for another polygon in the inner ring

Open
#1,882 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

@turf/boolean-contains
Dominant language
TypeScript
Stars
10.5k
Forks
1k
Avg merge
1h 11m
Merged PRs (30d)
4

Description

I am using Turf for a masterthesis about GeoSPARQL and during the preparation of a demo, I found a bug. In the demo, I'm testing which Geo objects are inside several others, with the example of my own country. In my country there's a small part of our country that's inside another part. This should say that "VlaamsBrabant" is not containing "Brussel", but the response is telling me it is containing it. The Geo data for these parts are available at https://gist.githubusercontent.com/dreeki/b0fd0ea3d75ea58adebab55c36566988/raw/428912374d67af18493444e769011a3c6fcfa87c/inner-ring-polygon.ttl

The polygons are visualised in the screenshot below.
Schermafbeelding 2020-04-10 om 17 51 49

Snippet of the code is the following:

import { Geometries as GeometryType } from '@turf/helpers';
import booleanDisjoint from '@turf/boolean-disjoint';

const firstGeometryObject: GeometryType = giveGeoObject(first.value);
const secondGeometryObject: GeometryType = giveGeoObject(second.value);
result = booleanContains(firstGeometryObject, secondGeometryObject);

and:

import { geometry, Geometries as GeometryType } from '@turf/helpers';
import * as Wkt from 'terraformer-wkt-parser';
import * as Terraformer from 'terraformer';

export const giveGeoObject: (text: string) => GeometryType = (text: string) => {
    const geoJSON = Wkt.parse(text);
    if(geoJSON instanceof Terraformer.Point || 
        geoJSON instanceof Terraformer.MultiPoint ||
        geoJSON instanceof Terraformer.LineString || 
        geoJSON instanceof Terraformer.MultiLineString ||
        geoJSON instanceof Terraformer.Polygon || 
        geoJSON instanceof Terraformer.MultiPolygon){
        return geometry(geoJSON.type, geoJSON.coordinates);
    }
    return null;
}

P.S. I love Turf, keep up the great work!

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the booleanContains entry point and reproduce the result with the linked inner-ring polygon Geo data and the example geometries. Trace how containment is determined for the nested polygon, then add a regression test showing that VlaamsBrabant does not contain Brussel and verify the corrected result.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
data
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.