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

Exception when checking if a point is within a multipolygon #166

Closed
pedwik opened this issue Apr 24, 2017 · 2 comments
Closed

Exception when checking if a point is within a multipolygon #166

pedwik opened this issue Apr 24, 2017 · 2 comments

Comments

@pedwik
Copy link

pedwik commented Apr 24, 2017

This test for checking whether a point is within a multi polygon raises an exception "Additional information: side location conflict [ (869265.15260738449, 7384168.8403524822, NaN) ]"

using NetTopologySuite.IO;
using NUnit.Framework;

namespace mynamespace
    [TestFixture]
    public class PointWithinPolygonTestFixture
    {
[Test]  // This test fails
        public void IsPointWithinMultiPolygonTest()
        {
            var wktPolygon =
                 "MULTIPOLYGON (((869422.4860859740000000 7384179.2207220300000000, 869430.3855629770000000 7384174.2529539200000000, " +
                 "869439.6733623450000000 7384168.8424349900000000, 69449.9364426460000000 7384159.2963781300000000, " +
                 "869462.4499704040000000 7384153.9274891600000000, 869468.4167669550000000 7384155.8482485300000000, " +
                 "869478.0938589940000000 7384155.9734178100000000, 869487.8187279450000000 7384152.4120398200000000, " +
                 "869503.5579840930000000 7384147.0847808100000000, 869521.0511065190000000 7384148.6937328300000000, " +
                 "869538.5859522510000000 7384147.0768628500000000, 869551.5365495900000000 7384143.5572079500000000, " +
                 "869560.3813188970000000 7384136.7581802200000000, 869571.5542080660000000 7384128.1456810600000000, " +
                 "869582.2602252880000000 7384119.9880398700000000, 869583.6626107380000000 7384113.4190491700000000, " +
                 "869592.4448882880000000 7384107.7266189200000000, 869584.5918845780000000 7384096.9678878400000000, " +
                 "869577.2442163070000000 7384092.2423574700000000, 869566.1815959520000000 7384088.3964614500000000, " +
                 "869555.0830264980000000 7384087.3260929600000000, 869535.6876780410000000 7384083.3708600900000000, " +
                 "869517.2653753350000000 7384075.7246095500000000, 869502.5364179950000000 7384069.0514046600000000, " +
                 "869486.8552765620000000 7384064.2189588700000000, 869469.3844128870000000 7384054.7327874100000000, " +
                 "869464.0076093290000000 7384040.7725417300000000, 869464.1109436090000000 7384032.7823439300000000, " +
                 "869457.9519178680000000 7384032.3908413100000000, 869450.8395834610000000 7384029.6339024300000000, " +
                 "869444.8896674810000000 7384024.8605899000000000, 869440.6560929450000000 7384018.5152877600000000, " +
                 "869438.5329955700000000 7384011.1887285200000000, 869437.8610232330000000 7384006.0044134500000000, " +
                 "869437.1555095960000000 7384000.5647160700000000, 869435.7937370200000000 7383999.0116828400000000, " +
                 "869416.0260591940000000 7383984.6225551400000000, 869409.7603962180000000 7383978.0083357000000000, " +
                 "869404.5310905290000000 7383969.9408111900000000, 869399.4194868230000000 7383965.6471635000000000, " +
                 "869396.8194258890000000 7383964.0319615800000000, 869391.9888987660000000 7383958.5382812700000000, " +
                 "869388.9554063060000000 7383951.8815223700000000, 869387.9786859170000000 7383944.6316580400000000, " +
                 "869388.0108859170000000 7383942.1391580400000000, 869388.5680711190000000 7383938.8932558800000000, 869388.0998985040000000 7383935.2897120000000000, 869389.0670604760000000 7383928.5741977300000000, 869390.2013304010000000 7383924.6170172800000000, 869380.5386767670000000 7383901.0381179500000000, 869353.4916761430000000 7383904.6892762800000000, 869320.2647920880000000 7383922.2606339900000000, 869319.2651105840000000 7383922.2477817900000000, 869319.2134221130000000 7383926.2457633300000000, 869320.0966881420000000 7383935.2573336100000000, 869315.8644792510000000 7383953.2029884500000000, 869303.4652242670000000 7383984.0433634700000000, 869292.3119859330000000 7383995.8996591400000000, 869283.1338030510000000 7384009.7804637200000000, 869282.7070704860000000 7384042.7753598000000000, 869289.3694713120000000 7384068.8621703500000000, 869295.2519830500000000 7384077.9377222500000000, 869339.6232563990000000 7384126.5128045700000000, 869357.4646932250000000 7384138.7432110900000000, 869381.4343250050000000 7384141.0537280900000000, 869393.3545070230000000 7384147.2077207900000000, 869403.1459651570000000 7384163.3342225600000000, 869403.1071289540000000 7384166.3341057000000000, 869403.0941835530000000 7384167.3337873400000000, 869400.5721623810000000 7384168.0190546100000000, 869402.2386705500000000 7384178.5570625600000000, 869403.5985875730000000 7384178.5155255100000000, 869422.4860859740000000 7384179.2207220300000000), (869380.5386767670000000 7383901.0381179500000000, 869384.3762098420000000 7383910.4025026700000000, 869382.7652346470000000 7383908.7493181100000000, 869378.9848134330000000 7383903.4247041600000000, 869375.2249637270000000 7383901.7554325200000000, 869380.5386767670000000 7383901.0381179500000000)), ((869287.2782769060000000 7384227.7095726600000000, 869299.3070513060000000 7384224.1779968800000000, 869314.5021356400000000 7384225.2963282900000000, 869328.3087113430000000 7384226.8575036300000000, 869336.6094019660000000 7384226.5039731800000000, 869347.7702770650000000 7384218.8130177100000000, 869359.9481564030000000 7384203.7611679800000000, 869368.8049397920000000 7384196.0404103000000000, 869374.9057537480000000 7384192.4863899300000000, 869371.8731817800000000 7384184.4864223300000000, 869371.8803529730000000 7384183.9306090200000000, 869371.9191891760000000 7384180.9308190200000000, 869359.1407937410000000 7384163.7650545400000000, 869357.2578462080000000 7384154.7405389100000000, 869319.3421266720000000 7384148.2503400400000000, 869302.4356443430000000 7384141.0319390100000000, 869292.5544065900000000 7384131.9039538400000000, 869283.8143184260000000 7384111.7908326200000000, 869265.2059379080000000 7384081.5492995300000000, 869258.4903584950000000 7384059.4627056800000000, 869258.6766232550000000 7384045.0007562500000000, 869254.7003421530000000 7384042.6955468200000000, 869238.9121916010000000 7384046.1957372100000000, 869233.2256297390000000 7384056.3085036300000000, 869224.8441933960000000 7384059.9045267500000000, 869222.4814283760000000 7384059.6914402600000000, 869225.3942322920000000 7384067.0342666700000000, 869231.3543233040000000 7384070.1116355500000000, 869258.7286827910000000 7384118.4661815100000000, 869259.9387498300000000 7384129.2857282900000000, 869262.8214721420000000 7384130.7736090900000000, 869266.3816382120000000 7384141.9320640300000000, 869266.2498558940000000 7384152.1167282800000000, 869265.0964127230000000 7384169.6968388600000000, 869264.9528025930000000 7384180.8074240100000000, 869262.0193229530000000 7384192.8079811400000000, 869250.8489484240000000 7384197.2932311900000000, 869243.3104518960000000 7384207.3820627100000000, 869235.7472752900000000 7384219.3227360300000000, 869224.5050025620000000 7384229.3636046200000000, 869218.6820951800000000 7384235.0386189900000000, 869218.6410238600000000 7384235.0463489700000000, 869216.3375840280000000 7384237.6357983600000000, 869223.4949831480000000 7384241.6333138800000000, 869248.8398056860000000 7384241.9611381900000000, 869274.2621143620000000 7384236.2982300500000000, 869287.2782769060000000 7384227.7095726600000000)))";
            var wktReader = new WKTReader();
            var geom = wktReader.Read(wktPolygon);

            var wktPoint = "POINT (869223.6377253330000000 7383915.0789977000000000)";
            var point = wktReader.Read(wktPoint);
            
           var isWithin = geom.Contains(point);
            Assert.IsFalse(isWithin);
}

This is how it looks in QGIS:
image

@pedwik
Copy link
Author

pedwik commented Apr 25, 2017

For some reason the polygon is considered invalid.

@pedwik
Copy link
Author

pedwik commented Apr 25, 2017

Turns out the right part of the figure has an invalid hole.

@pedwik pedwik closed this as completed Apr 25, 2017
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

1 participant