sromku / polygon-contains-point Goto Github PK
View Code? Open in Web Editor NEWPoint in polygon - Check if the point inside the polygon
License: Other
Point in polygon - Check if the point inside the polygon
License: Other
@sromku Thanks for your PiP implementation.
Exactly what I needed (algorithm accounting for holes), so I did a quick conversion to C# (files below).
Usage is pretty much the same:
Polygon polygon = Polygon.GetBuilder
.addVertex(new Point(1, 3))
.addVertex(new Point(2, 8))
.addVertex(new Point(5, 4))
.addVertex(new Point(5, 9))
.addVertex(new Point(7, 5))
.addVertex(new Point(6, 1))
.addVertex(new Point(3, 1))
.build();
Polygon polygon = Polygon.GetBuilder
.addVertex(new Point(1, 2)) // polygon
.addVertex(new Point(1, 6))
.addVertex(new Point(8, 7))
.addVertex(new Point(8, 1))
.close()
.addVertex(new Point(2, 3)) // hole one
.addVertex(new Point(5, 5))
.addVertex(new Point(6, 2))
.close()
.addVertex(new Point(6, 6)) // hole two
.addVertex(new Point(7, 6))
.addVertex(new Point(7, 5))
.build();
Point point = new Point(4.5, 7);
bool contains = polygon.contains(point);
I'm using it like this to load GeoJSON files:
Polygon.Builder builder = Polygon.GetBuilder;
dynamic geojson = JObject.Parse(File.ReadAllText("my.geojson"));
// outer ring
IEnumerable<dynamic> coordinates = geojson.features[0].geometry.coordinates[0][0];
foreach (var coord in coordinates) {
double lng = (double)coord[0];
double lat = (double)coord[1];
builder.addVertex(new Point(lng, lat));
}
builder.close();
// hole
coordinates = geojson.features[0].geometry.coordinates[0][1];
foreach (var coord in coordinates) {
builder.addVertex(new Point((double)coord[0], (double)coord[1]));
}
Polygon polygon = builder.build();
Hello there,
Pardon me in advance, i am a newbie in github and eclipse.
i just want to run your project but don't know how to import it to my eclipse environment.
If you could help me in this, it will be of great help
Polygon p= Polygon.Builder().addVertex(new Point(0, 0)).addVertex(new Point(0,1)).addVertex(new Point(1,2)).addVertex(new Point(1,99)).addVertex(new Point(100,0)).build();
System.out.println(p.contains(new Point(3f,4f)));//false :error
System.out.println(p.contains(new Point(3f,4.1f)));//true
System.out.println(p.contains(new Point(3f,3.9f)));//true
Could you please tag a release so as to make inclusion in projects easier ?
Or, even better, add it to maven or jcenter ?
This is a good lib, and I don't want to ruin it by copying the files directly into my project.
Can I get the center of polygon?
Hi. I am trying to use polygon class in kotlin but when try to create a polygon object I am getting the error Overload resolution ambiguity. All these functions match
public constructor Builder() ..
public open fun Builder()..
I hope you can help me
Thanks
The point -122.36960897d, 47.66245331d is wrongly detected as NOT being in the below given polygon. It seems to be (again) some rounding issue, as simply rounding all values to e.g. 6 decimal places it works just fine.
Looking at the code I also saw that in the createRay
method the outside point uses a pretty small epsilon what might lead again to rounding errors. Increasing this fixed the first point but then another point (47.63642127d, -122.37500487d) was wrong...
{
"type": "Polygon",
"coordinates": [
[
[
-122.375671,
47.72352500000001
],
[
-122.376495,
47.722609
],
[
-122.376534,
47.720359
],
[
-122.376411,
47.71816199999999
],
[
-122.380531,
47.711463
],
[
-122.381004,
47.70866300000001
],
[
-122.387009,
47.704013
],
[
-122.401985,
47.69818000000001
],
[
-122.403463,
47.696668
],
[
-122.404319,
47.695113
],
[
-122.402046,
47.69430600000001
],
[
-122.400898,
47.69327300000001
],
[
-122.400695,
47.69279300000001
],
[
-122.399929,
47.691766
],
[
-122.399378,
47.69061399999999
],
[
-122.400786,
47.68730100000001
],
[
-122.402507,
47.68739900000001
],
[
-122.402802,
47.68741599999999
],
[
-122.404207,
47.687494
],
[
-122.404045,
47.68703
],
[
-122.404388,
47.686107
],
[
-122.403442,
47.685412
],
[
-122.405502,
47.681022
],
[
-122.405937,
47.680934
],
[
-122.407951,
47.67743599999999
],
[
-122.408768,
47.67700500000001
],
[
-122.410095,
47.67700500000001
],
[
-122.410744,
47.676425
],
[
-122.408897,
47.67500999999999
],
[
-122.408897,
47.674491
],
[
-122.408508,
47.67417
],
[
-122.409325,
47.671946
],
[
-122.415764,
47.670821
],
[
-122.418121,
47.66952100000001
],
[
-122.417399,
47.668424
],
[
-122.414596,
47.668462
],
[
-122.41392,
47.668562
],
[
-122.411662,
47.66783
],
[
-122.410745,
47.666996
],
[
-122.410076,
47.66559999999998
],
[
-122.410185,
47.66534
],
[
-122.409279,
47.664768
],
[
-122.408694,
47.66486800000001
],
[
-122.403764,
47.664638
],
[
-122.403758,
47.654194
],
[
-122.422258,
47.65429500000001
],
[
-122.419922,
47.651916
],
[
-122.417953,
47.648475
],
[
-122.418251,
47.64729200000001
],
[
-122.418938,
47.64495
],
[
-122.416489,
47.64078399999999
],
[
-122.404945,
47.633903
],
[
-122.400658,
47.63248699999999
],
[
-122.396111,
47.631244
],
[
-122.395378,
47.630374
],
[
-122.391945,
47.62988200000001
],
[
-122.390266,
47.630115
],
[
-122.387909,
47.631125
],
[
-122.385162,
47.63156
],
[
-122.384865,
47.63291799999999
],
[
-122.379196,
47.632918
],
[
-122.378082,
47.62644099999999
],
[
-122.373917,
47.625922
],
[
-122.369453,
47.624042
],
[
-122.361092,
47.616633
],
[
-122.344734,
47.60723400000001
],
[
-122.33963,
47.600753
],
[
-122.343109,
47.590823
],
[
-122.342979,
47.580344
],
[
-122.340553,
47.578727
],
[
-122.343323,
47.57908100000001
],
[
-122.345234,
47.571097
],
[
-122.3464028,
47.5686177
],
[
-122.3486014,
47.56735450000001
],
[
-122.353857,
47.571198
],
[
-122.356178,
47.57331000000001
],
[
-122.358627,
47.574251
],
[
-122.360796,
47.574026
],
[
-122.360851,
47.582019
],
[
-122.361309,
47.582774
],
[
-122.361968,
47.58454
],
[
-122.365216,
47.58472900000001
],
[
-122.366325,
47.585691
],
[
-122.368425,
47.58559399999999
],
[
-122.370537,
47.58368699999999
],
[
-122.372365,
47.584066
],
[
-122.375168,
47.586513
],
[
-122.377771,
47.588083
],
[
-122.380532,
47.5902
],
[
-122.381054,
47.592995
],
[
-122.383294,
47.59532700000001
],
[
-122.386969,
47.59583500000001
],
[
-122.390987,
47.594433
],
[
-122.393804,
47.59106299999999
],
[
-122.402027,
47.58392800000001
],
[
-122.409452,
47.58044
],
[
-122.421681,
47.57637200000001
],
[
-122.412072,
47.57083100000001
],
[
-122.410618,
47.56904300000001
],
[
-122.410168,
47.566655
],
[
-122.407625,
47.563608
],
[
-122.406793,
47.562141
],
[
-122.40596,
47.561789
],
[
-122.404419,
47.56059
],
[
-122.403134,
47.558717
],
[
-122.400196,
47.554946
],
[
-122.400319,
47.554196
],
[
-122.399432,
47.55288099999999
],
[
-122.398514,
47.54932899999999
],
[
-122.398946,
47.548168
],
[
-122.399849,
47.54637
],
[
-122.399199,
47.544377
],
[
-122.397648,
47.542558
],
[
-122.397355,
47.541105
],
[
-122.39805,
47.53962400000001
],
[
-122.396942,
47.539026
],
[
-122.397224,
47.537857
],
[
-122.396121,
47.535941
],
[
-122.398795,
47.532705
],
[
-122.401946,
47.530253
],
[
-122.395655,
47.525237
],
[
-122.395085,
47.521164
],
[
-122.400008,
47.517091
],
[
-122.397583,
47.515241
],
[
-122.394385,
47.51003
],
[
-122.387477,
47.502156
],
[
-122.384647,
47.50067299999999
],
[
-122.382909,
47.50008700000001
],
[
-122.377738,
47.49718200000001
],
[
-122.375058,
47.495747
],
[
-122.373408,
47.500777
],
[
-122.370193,
47.50387900000001
],
[
-122.370457,
47.50706799999999
],
[
-122.370642,
47.50805400000001
],
[
-122.371141,
47.517259
],
[
-122.365657,
47.51727799999999
],
[
-122.360678,
47.517275
],
[
-122.360657,
47.515433
],
[
-122.358307,
47.515382
],
[
-122.358296,
47.517258
],
[
-122.337281,
47.517214
],
[
-122.338194,
47.513805
],
[
-122.331758,
47.513775
],
[
-122.330897,
47.51341200000001
],
[
-122.329929,
47.512991
],
[
-122.328392,
47.513393
],
[
-122.330441,
47.516819
],
[
-122.331159,
47.519115
],
[
-122.317624,
47.51892299999999
],
[
-122.316094,
47.518867
],
[
-122.319896,
47.522307
],
[
-122.309952,
47.522549
],
[
-122.311761,
47.52624899999999
],
[
-122.314339,
47.528215
],
[
-122.313095,
47.534269
],
[
-122.319132,
47.537745
],
[
-122.318578,
47.53938900000001
],
[
-122.317807,
47.543744
],
[
-122.316646,
47.546163
],
[
-122.312762,
47.54678499999999
],
[
-122.297208,
47.533821
],
[
-122.290637,
47.51928
],
[
-122.284262,
47.509399
],
[
-122.277367,
47.501376
],
[
-122.268821,
47.50105
],
[
-122.269661,
47.502725
],
[
-122.269794,
47.50361700000001
],
[
-122.251921,
47.503715
],
[
-122.248833,
47.499174
],
[
-122.237224,
47.499431
],
[
-122.237812,
47.506083
],
[
-122.244244,
47.50613299999999
],
[
-122.244887,
47.50947899999999
],
[
-122.236345,
47.509695
],
[
-122.23939,
47.51147600000001
],
[
-122.244218,
47.511961
],
[
-122.247705,
47.513131
],
[
-122.253611,
47.516585
],
[
-122.25441,
47.518301
],
[
-122.261964,
47.52196200000001
],
[
-122.26248,
47.523073
],
[
-122.259564,
47.52367100000001
],
[
-122.260083,
47.52857800000001
],
[
-122.262666,
47.529698
],
[
-122.263198,
47.533793
],
[
-122.261859,
47.53595500000001
],
[
-122.26107,
47.54005
],
[
-122.258804,
47.54186499999999
],
[
-122.257019,
47.545147
],
[
-122.257557,
47.54704600000001
],
[
-122.256977,
47.548436
],
[
-122.259163,
47.551475
],
[
-122.26049,
47.55553
],
[
-122.261993,
47.55831
],
[
-122.264572,
47.561904
],
[
-122.265686,
47.561904
],
[
-122.266975,
47.56251000000001
],
[
-122.2677,
47.563292
],
[
-122.267792,
47.56436400000001
],
[
-122.26693,
47.56439499999999
],
[
-122.26693,
47.56540600000001
],
[
-122.269722,
47.56804199999999
],
[
-122.270279,
47.568129
],
[
-122.271996,
47.568156
],
[
-122.275429,
47.570559
],
[
-122.276329,
47.570907
],
[
-122.276375,
47.571807
],
[
-122.276978,
47.572009
],
[
-122.277657,
47.57189100000001
],
[
-122.278389,
47.570533
],
[
-122.279419,
47.570907
],
[
-122.279846,
47.57175
],
[
-122.280235,
47.57331000000001
],
[
-122.281822,
47.57576999999999
],
[
-122.284653,
47.581679
],
[
-122.286758,
47.58312500000001
],
[
-122.287315,
47.584254
],
[
-122.285088,
47.5866
],
[
-122.284912,
47.58781299999999
],
[
-122.285431,
47.59053299999999
],
[
-122.286888,
47.5932
],
[
-122.284401,
47.600345
],
[
-122.283325,
47.60332800000001
],
[
-122.281952,
47.609607
],
[
-122.279549,
47.617763
],
[
-122.279419,
47.620715
],
[
-122.281906,
47.622825
],
[
-122.282295,
47.62389699999999
],
[
-122.278687,
47.627772
],
[
-122.278564,
47.628901
],
[
-122.276627,
47.63072099999999
],
[
-122.27504,
47.63491300000001
],
[
-122.276115,
47.635379
],
[
-122.274872,
47.64087200000001
],
[
-122.275818,
47.64136400000001
],
[
-122.276588,
47.641856
],
[
-122.277878,
47.643012
],
[
-122.278862,
47.642955
],
[
-122.282211,
47.642898
],
[
-122.284401,
47.64321399999999
],
[
-122.284744,
47.643878
],
[
-122.28624,
47.645122
],
[
-122.286629,
47.646396
],
[
-122.290359,
47.647033
],
[
-122.294098,
47.64680000000001
],
[
-122.299248,
47.646132
],
[
-122.300491,
47.646888
],
[
-122.298454,
47.647811
],
[
-122.293991,
47.653476
],
[
-122.291908,
47.653594
],
[
-122.289848,
47.65457399999999
],
[
-122.288193,
47.65531400000001
],
[
-122.286911,
47.654735
],
[
-122.283698,
47.654669
],
[
-122.282207,
47.653724
],
[
-122.281006,
47.653307
],
[
-122.281436,
47.65276099999999
],
[
-122.281102,
47.65193099999999
],
[
-122.28006,
47.651224
],
[
-122.279231,
47.650846
],
[
-122.278928,
47.649957
],
[
-122.278282,
47.649097
],
[
-122.278624,
47.648978
],
[
-122.278344,
47.648527
],
[
-122.277358,
47.64800999999999
],
[
-122.276309,
47.648063
],
[
-122.275446,
47.648641
],
[
-122.275097,
47.649414
],
[
-122.275244,
47.650233
],
[
-122.275476,
47.650609
],
[
-122.276052,
47.65091300000001
],
[
-122.276492,
47.65203100000001
],
[
-122.276019,
47.652825
],
[
-122.274982,
47.653438
],
[
-122.273678,
47.654137
],
[
-122.272034,
47.65584
],
[
-122.270183,
47.656859
],
[
-122.26968,
47.656947
],
[
-122.268452,
47.658442
],
[
-122.267673,
47.660537
],
[
-122.267259,
47.663288
],
[
-122.267434,
47.664225
],
[
-122.267168,
47.664554
],
[
-122.26629,
47.66502000000001
],
[
-122.261873,
47.665995
],
[
-122.259562,
47.666905
],
[
-122.252127,
47.672306
],
[
-122.252292,
47.674105
],
[
-122.25321,
47.67595799999999
],
[
-122.263338,
47.67587799999999
],
[
-122.263255,
47.682361
],
[
-122.263529,
47.683537
],
[
-122.263728,
47.684108
],
[
-122.264737,
47.68645299999999
],
[
-122.265649,
47.688338
],
[
-122.266595,
47.68960300000001
],
[
-122.266418,
47.690352
],
[
-122.267273,
47.691073
],
[
-122.267746,
47.69214100000001
],
[
-122.271439,
47.69425099999999
],
[
-122.271439,
47.694598
],
[
-122.271484,
47.69560900000001
],
[
-122.272079,
47.69584200000001
],
[
-122.272079,
47.698642
],
[
-122.274185,
47.70421500000001
],
[
-122.274788,
47.706065
],
[
-122.274696,
47.706931
],
[
-122.276115,
47.71057
],
[
-122.276375,
47.712447
],
[
-122.278687,
47.719375
],
[
-122.280172,
47.72060100000001
],
[
-122.280284,
47.723097
],
[
-122.279135,
47.725665
],
[
-122.281128,
47.72918300000001
],
[
-122.280993,
47.731832
],
[
-122.283134,
47.73311000000001
],
[
-122.283644,
47.734041
],
[
-122.322761,
47.73429900000001
],
[
-122.348045,
47.73433200000001
],
[
-122.375322,
47.73451500000001
],
[
-122.374116,
47.731882
],
[
-122.37351,
47.72924899999999
],
[
-122.373973,
47.726263
],
[
-122.375671,
47.72352500000001
]
],
[
[
-122.325672,
47.645693
],
[
-122.325747,
47.645499
],
[
-122.325752,
47.636865
],
[
-122.325736,
47.636669
],
[
-122.325147,
47.634946
],
[
-122.325249,
47.634508
],
[
-122.325477,
47.633891
],
[
-122.325704,
47.63389
],
[
-122.325373,
47.63479
],
[
-122.325389,
47.634915
],
[
-122.326056,
47.63682
],
[
-122.326047,
47.645497
],
[
-122.325956,
47.645723
],
[
-122.322189,
47.650702
],
[
-122.321819,
47.650579
],
[
-122.325672,
47.645693
]
],
[
[
-122.318237,
47.612098
],
[
-122.329391,
47.607452
],
[
-122.32946300000002,
47.607533
],
[
-122.32062,
47.611233
],
[
-122.32061599999999,
47.611346
],
[
-122.318245,
47.612329
],
[
-122.318237,
47.612098
]
],
[
[
-122.285943,
47.644481
],
[
-122.288958,
47.644636
],
[
-122.289387,
47.644665
],
[
-122.289602,
47.644716
],
[
-122.29075,
47.644759
],
[
-122.291232,
47.64473
],
[
-122.291833,
47.644687
],
[
-122.29237,
47.644759
],
[
-122.292863,
47.644867
],
[
-122.293593,
47.644896
],
[
-122.295331,
47.644983
],
[
-122.296693,
47.644896
],
[
-122.298185,
47.644535
],
[
-122.298506,
47.644022
],
[
-122.29841,
47.643335
],
[
-122.298281,
47.642966
],
[
-122.298346,
47.642728
],
[
-122.298335,
47.642489
],
[
-122.29827,
47.642366
],
[
-122.29826,
47.64207
],
[
-122.298303,
47.641897
],
[
-122.298281,
47.641651
],
[
-122.298388,
47.641456
],
[
-122.29841,
47.641232
],
[
-122.298431,
47.641116
],
[
-122.298539,
47.640971
],
[
-122.298571,
47.639446
],
[
-122.298861,
47.639446
],
[
-122.298925,
47.637104
],
[
-122.298979,
47.633822
],
[
-122.29797,
47.633742
],
[
-122.297938,
47.633583
],
[
-122.297637,
47.633294
],
[
-122.29723,
47.632954
],
[
-122.297101,
47.632614
],
[
-122.297144,
47.632318
],
[
-122.297305,
47.631761
],
[
-122.297294,
47.63084
],
[
-122.297401,
47.630873
],
[
-122.297498,
47.630949
],
[
-122.297535,
47.631072
],
[
-122.297568,
47.631314
],
[
-122.298303,
47.631267
],
[
-122.298469,
47.630877
],
[
-122.298555,
47.630537
],
[
-122.29871,
47.630396
],
[
-122.298963,
47.63032
],
[
-122.298925,
47.629658
],
[
-122.298839,
47.628986
],
[
-122.29793,
47.628847
],
[
-122.297069,
47.628751
],
[
-122.29694,
47.628751
],
[
-122.29679,
47.628548
],
[
-122.296677,
47.628144
],
[
-122.296355,
47.627601
],
[
-122.296318,
47.627424
],
[
-122.295089,
47.62673
],
[
-122.294977,
47.626531
],
[
-122.295062,
47.625226
],
[
-122.294751,
47.625074
],
[
-122.294054,
47.624976
],
[
-122.292509,
47.626029
],
[
-122.292523,
47.626155
],
[
-122.292563,
47.626274
],
[
-122.292482,
47.626433
],
[
-122.292461,
47.627312
],
[
-122.292402,
47.627478
],
[
-122.292807,
47.627766
],
[
-122.293025,
47.627949
],
[
-122.293233,
47.628115
],
[
-122.293448,
47.628292
],
[
-122.293239,
47.628375
],
[
-122.292722,
47.628417
],
[
-122.292109,
47.628487
],
[
-122.290948,
47.628465
],
[
-122.290921,
47.62959
],
[
-122.289435,
47.629586
],
[
-122.289462,
47.628093
],
[
-122.285514,
47.630804
],
[
-122.284956,
47.643802
],
[
-122.285943,
47.644481
]
],
[
[
-122.2796988,
47.6903236
],
[
-122.2794414,
47.6832889
],
[
-122.26942060000002,
47.68330340000001
],
[
-122.27,
47.69019360000001
],
[
-122.2796988,
47.6903236
]
],
[
[
-122.342452,
47.588416
],
[
-122.341137,
47.588036
],
[
-122.341139,
47.588033
],
[
-122.341218,
47.587931
],
[
-122.341239,
47.587906
],
[
-122.341385,
47.587946
],
[
-122.342564,
47.587977
],
[
-122.342583,
47.588244
],
[
-122.342527,
47.588329
],
[
-122.342452,
47.588416
]
],
[
[
-122.32851500000001,
47.708505
],
[
-122.32840799999998,
47.703192
],
[
-122.325747,
47.703177
],
[
-122.32572599999999,
47.70143
],
[
-122.323236,
47.701401
],
[
-122.32343,
47.708462
],
[
-122.32851500000001,
47.708505
]
],
[
[
-122.300776,
47.665774
],
[
-122.300942,
47.684849
],
[
-122.300762,
47.684845
],
[
-122.300763,
47.684578
],
[
-122.300758,
47.684351
],
[
-122.300763,
47.683896
],
[
-122.300753,
47.682976
],
[
-122.300635,
47.682975
],
[
-122.30053,
47.676079
],
[
-122.300467,
47.66578
],
[
-122.300507,
47.665474
],
[
-122.300802,
47.66449
],
[
-122.300845,
47.664235
],
[
-122.296194,
47.664246
],
[
-122.296066,
47.66417
],
[
-122.295701,
47.664087
],
[
-122.295653,
47.663935
],
[
-122.295658,
47.663798
],
[
-122.295274,
47.663415
],
[
-122.293888,
47.662374
],
[
-122.292922,
47.661265
],
[
-122.296295,
47.66126
],
[
-122.296878,
47.661307
],
[
-122.300835,
47.661298
],
[
-122.300852,
47.663376
],
[
-122.301098,
47.663373
],
[
-122.301084,
47.664491
],
[
-122.300776,
47.665774
]
],
[
[
-122.38722320000001,
47.6333544
],
[
-122.3881567,
47.6333255
],
[
-122.38871460000001,
47.6331303
],
[
-122.38942270000001,
47.6326748
],
[
-122.38984639999998,
47.632492199999994
],
[
-122.3901495,
47.6323928
],
[
-122.390407,
47.6323314
],
[
-122.3912358,
47.63226989999999
],
[
-122.39120360000001,
47.6316264
],
[
-122.3956025,
47.6316554
],
[
-122.3957634,
47.6314891
],
[
-122.3956132,
47.6311709
],
[
-122.39549520000001,
47.630816700000004
],
[
-122.39515190000002,
47.6305275
],
[
-122.3944974,
47.630440699999994
],
[
-122.39362840000001,
47.6303901
],
[
-122.3928452,
47.630187600000006
],
[
-122.39169720000001,
47.6299924
],
[
-122.3908925,
47.6300719
],
[
-122.3903775,
47.630368399999995
],
[
-122.38928320000001,
47.6306287
],
[
-122.3886395,
47.6309034
],
[
-122.38861800000001,
47.6310263
],
[
-122.3882425,
47.6312939
],
[
-122.3866761,
47.631467400000005
],
[
-122.38677259999999,
47.63334720000001
],
[
-122.38722320000001,
47.6333544
]
],
[
[
-122.329524,
47.548152
],
[
-122.32617,
47.548131
],
[
-122.32623,
47.549066
],
[
-122.326962,
47.549977
],
[
-122.326987,
47.551004
],
[
-122.329506,
47.55045
],
[
-122.329524,
47.548152
]
],
[
[
-122.311563,
47.680891
],
[
-122.311853,
47.680418
],
[
-122.311904,
47.680197
],
[
-122.311834,
47.670748
],
[
-122.311838,
47.661304
],
[
-122.312108,
47.661306
],
[
-122.312163,
47.680201
],
[
-122.312074,
47.680448
],
[
-122.311804,
47.680945
],
[
-122.311772,
47.681772
],
[
-122.311828,
47.682291
],
[
-122.312146,
47.682885
],
[
-122.312185,
47.683034
],
[
-122.312177,
47.683931
],
[
-122.312024,
47.683925
],
[
-122.312003,
47.683025
],
[
-122.311882,
47.68275
],
[
-122.311686,
47.682468
],
[
-122.311611,
47.68224
],
[
-122.311563,
47.680891
]
],
[
[
-122.32827899999998,
47.5264493
],
[
-122.32826830000002,
47.5255745
],
[
-122.3282844,
47.5249741
],
[
-122.3282817,
47.5247572
],
[
-122.3282844,
47.5246562
],
[
-122.33183560000002,
47.5245729
],
[
-122.33275830000001,
47.5245801
],
[
-122.3329031,
47.5245765
],
[
-122.33298900000001,
47.5245657
],
[
-122.33299970000002,
47.5245983
],
[
-122.33297820000001,
47.525061900000004
],
[
-122.332828,
47.52542420000001
],
[
-122.33249550000001,
47.526011
],
[
-122.332077,
47.5268224
],
[
-122.3317981,
47.5268115
],
[
-122.33146550000001,
47.5267427
],
[
-122.33129380000001,
47.5266775
],
[
-122.3311865,
47.5266956
],
[
-122.33109,
47.5266956
],
[
-122.33059110000002,
47.5265743
],
[
-122.3300654,
47.5264964
],
[
-122.3298991,
47.526471
],
[
-122.329706,
47.5264565
],
[
-122.32891740000001,
47.5264421
],
[
-122.32827899999998,
47.5264493
]
],
[
[
-122.319578,
47.552064
],
[
-122.319723,
47.551933
],
[
-122.316982,
47.549142
],
[
-122.316826,
47.548952
],
[
-122.316617,
47.548791
],
[
-122.316327,
47.54862
],
[
-122.316037,
47.548483
],
[
-122.315077,
47.548143
],
[
-122.314956,
47.548081
],
[
-122.314814,
47.54803
],
[
-122.314015,
47.54723
],
[
-122.313485,
47.546693
],
[
-122.313076,
47.54674
],
[
-122.314643,
47.548161
],
[
-122.314911,
47.548295
],
[
-122.316059,
47.548693
],
[
-122.316424,
47.54891
],
[
-122.319578,
47.552064
]
],
[
[
-122.319851,
47.552082
],
[
-122.320182,
47.552417
],
[
-122.320264,
47.552489
],
[
-122.320357,
47.552586
],
[
-122.320515,
47.552737
],
[
-122.320677,
47.552921
],
[
-122.320859,
47.553101
],
[
-122.320917,
47.553168
],
[
-122.320991,
47.553229
],
[
-122.321136,
47.553325
],
[
-122.321199,
47.553364
],
[
-122.321136,
47.553403
],
[
-122.321101,
47.553468
],
[
-122.320822,
47.553292
],
[
-122.320356,
47.552839
],
[
-122.319695,
47.552158
],
[
-122.319772,
47.552129
],
[
-122.319851,
47.552082
]
],
[
[
-122.319366,
47.675888
],
[
-122.319337,
47.675836
],
[
-122.319342,
47.675776
],
[
-122.31217,
47.67573
],
[
-122.312164,
47.675863
],
[
-122.319366,
47.675888
]
],
[
[
-122.286381,
47.603872
],
[
-122.286413,
47.603852
],
[
-122.286622,
47.603812
],
[
-122.28741,
47.603925
],
[
-122.28809,
47.603971
],
[
-122.28839,
47.603786
],
[
-122.289832,
47.603653
],
[
-122.289883,
47.60344
],
[
-122.289549,
47.603244
],
[
-122.288714,
47.603067
],
[
-122.286048,
47.603604
],
[
-122.286381,
47.603872
]
]
]
}
hi , i want to use your library to check if a geo point is inside a polygon , and i want to know if your library is fit for this purpose
This would provide easier integration for both Maven and Gradle projects
/** insert this function in Tests.java and add it in main(..){ ..showBugTest();
* test Polygon with Geo coordinates point: north:42.508956 east:27.483328
*/
public static void showBugTest()
{ //KML
/*<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
<Placemark>
<name>Plygon</name>
<LineString>
<coordinates>
27.485196,42.499148,1
27.480000,42.498600,1
27.474680,42.503800,1
27.468270,42.510000,1
27.466904,42.510788,1
27.465350,42.512116,1
27.467000,42.512000,1
27.471027,42.513579,1
27.472668,42.512938,1
27.474922,42.511829,1
27.480124,42.507945,1
27.482892,42.509082,1
27.490519,42.536026,1
27.499703,42.534470,1
27.485196,42.499148,1
</coordinates>
</LineString>
</Placemark>
</Document>
</kml>*/
//you can view kml polygon here: http://display-kml.appspot.com/
//and here is the point: https://maps.google.bg/?q=42.508956,27.483328
Polygon polygon = Polygon.Builder()
.addVertex(new Point(42.499148f, 27.485196f))
.addVertex(new Point(42.498600f, 27.480000f))
.addVertex(new Point(42.503800f, 27.474680f))
.addVertex(new Point(42.510000f, 27.468270f))
.addVertex(new Point(42.510788f, 27.466904f))
.addVertex(new Point(42.512116f, 27.465350f))
.addVertex(new Point(42.512000f, 27.467000f))
.addVertex(new Point(42.513579f, 27.471027f))
.addVertex(new Point(42.512938f, 27.472668f))
.addVertex(new Point(42.511829f, 27.474922f))
.addVertex(new Point(42.507945f, 27.480124f))
.addVertex(new Point(42.509082f, 27.482892f))
.addVertex(new Point(42.536026f, 27.490519f))
.addVertex(new Point(42.534470f, 27.499703f))
.addVertex(new Point(42.499148f, 27.485196f))
.build();
//I have view on the map that point (42.508956,27.483328) is inside the polygon. But the result of execution show that: The point:(42.51,27.48) is not inside the polygon
isInside(polygon, new Point(42.508956f, 27.483328f)); //wrong results //function contains(..) -> intersection=0 why?
isInside(polygon, new Point(42.505f,27.48f)); //but with an other point result is ok..
}
Line#isInside()
checks whether point contains inside line's bounding box, not laying on the line.line (0;0) - (10;10)
points (0;10), (10;0)
line.containsPoint will return true
for them, however points are not actually lay on that line
For a given rect like
(-1, -1), (-1, 1), (1, 1), (1, -1)
the point (0,1) is not detected as inside of polygon.
How to detect it as insid of polygon?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.