Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SplitPolygonExample.cs does split, but only returns one part of the result #114

Closed
chau-intl opened this issue Aug 2, 2016 · 13 comments
Closed

Comments

@chau-intl
Copy link

chau-intl commented Aug 2, 2016

Looking a the samples I have found the SplitPolygonExample.cs which simple splits a polygon using a line.
nts_split_polygon_bug

At the moment it seems like something has changed in NetTopologySuite.Operation.Polygonize, since the split using the line cuts the polygon but only return the left hand part. I would expect both parts to be returned.

@FObermaier do you know something about this?

@DGuidi
Copy link
Contributor

DGuidi commented Aug 2, 2016

can be related to #87? other changes are at least one year old...

@chau-intl
Copy link
Author

I haven't tried the sample before, so I cannot tell when (or if?) it actually worked.

@FObermaier
Copy link
Member

FObermaier commented Aug 2, 2016

This example does not work with current JTS either. I'm sure it did work at the time I added it.

@DGuidi
Copy link
Contributor

DGuidi commented Aug 2, 2016

This example does not work with current JTS either

So we can close this issue. thanks @chau-intl for this report.

@DGuidi DGuidi closed this as completed Aug 2, 2016
@FObermaier
Copy link
Member

I think it broke with cd319e6 or one of the subsequent.
The new algorithm tries to take advantage of the knowing which rings are adjacent to each other. If one of the adjacent rings is included in the result set, all others are not. This is valid as long as the linework causing adjacency is not the line that shall split the polygon.
This is why we only get one.

Maybe @dr-jts has a clue on how to handle that.

@FObermaier FObermaier reopened this Aug 2, 2016
@am2222
Copy link

am2222 commented Aug 10, 2016

Any Idea how to fix this problem?I tried to use difference but it returns an empty polygon

@jholt456
Copy link

I just hit this issue also. Sample I wrote a bit ago using 1.13.3.2 worked correctly, new project using 1.14.0 gave unexpected results. I dropped back to 1.13.3.2 for now.

v1.13.3.2 Result:
nts-poly-1 13 3 2

v1.14.0 Result:
nts-poly-1 14

@FObermaier
Copy link
Member

@jholt456 Could you post a unit test for the sample pictures?
I have a broad idea how to fix this issue.

FObermaier added a commit that referenced this issue Aug 17, 2016
@jholt456
Copy link

Sure thing @FObermaier. The images were captured from an application I am working on, but this test replicates the issue. It returns 64 polys on v1.13.3.2, and 32 on v1.14. Please let me know if I can send anything else over.

[TestMethod]
public void Should_Find_Correct_Number_Of_Polygons_From_Lines()
{
    var paths = new List<IGeometry>();

    for (int x = 1; x < 10; x++)
    {
        var startPoint = new Coordinate(x * 40, 30);
        var endPoint = new Coordinate(x * 40, 440);
        paths.Add(new LineString(new[] { startPoint, endPoint }));
    }

    for (int y = 1; y < 10; y++)
    {
        var startPoint = new Coordinate(30, y * 40);
        var endPoint = new Coordinate(450, y * 40);

        paths.Add(new LineString(new[] { startPoint, endPoint }));
    }

    var noder = new NetTopologySuite.Noding.Snapround.GeometryNoder(new PrecisionModel(1.0d));

    var geomFactory = GeometryFactory.Default;
    var nodedLines = noder.Node(paths);

    var nodedDedupedLinework = geomFactory.BuildGeometry(nodedLines.ToArray()).Union();

    Polygonizer polygonizer = new Polygonizer();
    polygonizer.Add(nodedDedupedLinework);

    var polygons = polygonizer.GetPolygons();
    Assert.AreEqual(64, polygons.Count);
}

@FObermaier
Copy link
Member

Your issue can be resolved using the new Polygonizer(false) constructor.

@FObermaier
Copy link
Member

In fact it turned out that the split polygon example will continue to work when using the constructor mentioned above. Sorry!

FObermaier added a commit that referenced this issue Aug 18, 2016
Changing default Polygonizer constructor to initialize ExtractOnlyPolygonal with false.
@am2222
Copy link

am2222 commented Aug 18, 2016

@jholt456 a not related question, Can you say what library are you using to draw shapes?thanks

@jholt456
Copy link

@am2222 Not using a library in the images I posted due to interactivity requirements for this project. I use NTS for the heavy lifting behind the scenes, but the view just binds an ItemsControl to a Shapes collection on the view model. Each shape type has a DataTemplate to specify how it will be rendered. In the case of a Polygon, the data template renders a standard WPF polygon, all points from the shape (used as drag handles), and a label.

In the past I have used the WpfPathGeometryWriter provided by NTS, and it worked great for quickly displaying shapes.

Hope that helps, let me know if I can give you anymore info.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants