Git Product home page Git Product logo

Comments (4)

twelch avatar twelch commented on June 2, 2024

These two polygons don't seem to be valid geojson, the first and last coordinates should have the same values to close the polygon ring.

Is the input to your earlier steps to produce the masks valid?

Separately, the difference function can be used to subtract out polygons from a larger polygon to produce holes but I'm not sure what your use case is.

from turf.

rjbrockbundy avatar rjbrockbundy commented on June 2, 2024

These are two polygons each with a hole cut out it, with the "base" polygon remaining the same and then two different "cut" polygons. The base polygon is the same in both in geometry.coordinates[1]:

[[-75.786602,45.296747],[-75.722062,45.296747],[-75.722062,45.329341],[-75.786602,45.329341],[-75.786602,45.296747]]

The actual geoJSON is a FeatureCollection:

{"type":"FeatureCollection","features":[{"type":"Feature","properties":{},"geometry":{"type":"Polygon","coordinates":[[[-75.748839,45.300249],[-75.730129,45.300249],[-75.730129,45.31534],[-75.748839,45.31534],[-75.748839,45.300249]],[[-75.777677,45.293486],[-75.717599,45.293486],[-75.717599,45.320289],[-75.777677,45.320289],[-75.777677,45.293486]]]}}]}
{"type":"FeatureCollection","features":[{"type":"Feature","properties":{},"geometry":{"type":"Polygon","coordinates":[[[-75.777677,45.307251],[-75.755534,45.307251],[-75.755534,45.320289],[-75.777677,45.320289],[-75.777677,45.307251]],[[-75.777677,45.293486],[-75.717599,45.293486],[-75.717599,45.320289],[-75.777677,45.320289],[-75.777677,45.293486]]]}}]}

The masks are correct as I am displaying them propely on my leaflet map, just these two are seperate and I wish to merge them into one.

from turf.

smallsaucepan avatar smallsaucepan commented on June 2, 2024

Hi @rjbrockbundy. Ran your geojson through a validator and get an error about the "right hand rule". So it might be that the direction of one of your rectangles is incorrect (these both run clockwise):

two-rectangles

Tools like Turf use the direction (or winding) of the polygon to figure out which side is meant to be the outside. It might look ok in Leaflet because they have some extra checks to try to give you something that looks good.

Try running your polygons through turf-rewind, and it should change it to the below (outer ring is now anticlockwise):

donut

Give that a try and let us know if it helps. If not, we can dig a little further.

A good (strict) geojson validator: https://geojsonlint.com/

from turf.

smallsaucepan avatar smallsaucepan commented on June 2, 2024

Closing for now in lieu of further feedback. Feel free to reopen if the suggestion above doesn't solve the problem.

from turf.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.