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

pointInPolygon not supported MultiPolygon #9403

Closed
vicchen7 opened this issue Feb 27, 2020 · 11 comments
Closed

pointInPolygon not supported MultiPolygon #9403

vicchen7 opened this issue Feb 27, 2020 · 11 comments
Assignees
Labels
bug Confirmed user-visible misbehaviour in official release comp-geo feature

Comments

@vicchen7
Copy link

Does pointInPolygon support MultiPolygon?
I tested this function and it seems not fully support.

Below is the test script.

  1. This location is in the first polygon of multipolygon and the result is correct.

SELECT pointInPolygon((97.66905, 16.5026053), [(97.66905, 16.5026053), (97.667878, 16.4979175), (97.661433, 16.4917645), (97.656745, 16.4859047), (97.656745, 16.4818029), (97.658796, 16.4785801), (97.665535, 16.4753572), (97.670808, 16.4730135), (97.676082, 16.4697907), (97.680477, 16.4677398), (97.68575, 16.4686189), (97.689559, 16.4727207), (97.69454, 16.4744788), (97.698055, 16.4747718), (97.702157, 16.4724279), (97.703036, 16.4683261), (97.703036, 16.4633453), (97.702451, 16.4594354), (97.699533, 16.4539205), (97.699106, 16.4521467), (97.699896, 16.4500714), (97.701852, 16.4474887), (97.701272, 16.4460233), (97.699896, 16.4439216), (97.699857, 16.4425297), (97.700705, 16.4417585), (97.699266, 16.4404319), (97.696817, 16.439585), (97.69468, 16.4391501), (97.690854, 16.439294), (97.686571, 16.4407665), (97.683728, 16.4428458), (97.680647, 16.444719), (97.678369, 16.445322), (97.675195, 16.4448526), (97.672627, 16.4435941), (97.670568, 16.4419727), (97.667276, 16.4410039), (97.666215, 16.439402), (97.66599, 16.43656), (97.664579, 16.435632), (97.66195, 16.4344612), (97.659174, 16.4324549), (97.658693, 16.4290256), (97.659289, 16.4246502), (97.660882, 16.422609), (97.663533, 16.4225057), (97.666402, 16.4210711), (97.67148, 16.4170395), (97.673433, 16.4146478), (97.674184, 16.4124121), (97.6742, 16.4085257), (97.674894, 16.4055148), (97.675906, 16.4019452), (97.675287, 16.3996593), (97.675062, 16.3963334), (97.675798, 16.3936434), (97.675676, 16.3909321), (97.67508, 16.386655), (97.679839, 16.386241), (97.689403, 16.3726191), (97.692011, 16.372909), (97.696359, 16.3679819), (97.699866, 16.360968), (97.697233, 16.3609438), (97.693077, 16.3596272), (97.686631, 16.3584552), (97.68165, 16.3558182), (97.674619, 16.3496653), (97.667588, 16.3482003), (97.664072, 16.3502511), (97.659384, 16.3540599), (97.652353, 16.3578686), (97.649716, 16.3625565), (97.650595, 16.3672443), (97.65206, 16.3701742), (97.65206, 16.3733971), (97.651181, 16.3760339), (97.646493, 16.3763268), (97.6462, 16.3801357), (97.646786, 16.3851165), (97.643563, 16.3883393), (97.638583, 16.3889252), (97.636239, 16.392148), (97.630379, 16.3933199), (97.629132, 16.3964903), (97.624347, 16.4056104), (97.615377, 16.4165245), (97.614779, 16.4229534), (97.611938, 16.4335685), (97.613882, 16.4410439), (97.619713, 16.4461272), (97.62375, 16.4542007), (97.62345, 16.4640683), (97.618965, 16.4793181), (97.617321, 16.4884382), (97.617747, 16.4985751), (97.623301, 16.5026416), (97.629303, 16.5016624), (97.63272, 16.4986048), (97.640862, 16.498226), (97.647134, 16.5006382), (97.650873, 16.5051263), (97.654987, 16.5089598), (97.65639, 16.5118583), (97.658166, 16.5160658), (97.660395, 16.5197566), (97.66612, 16.5140318), (97.668757, 16.507879), (97.66905, 16.5026053)], [(97.666491, 16.5599384), (97.665077, 16.5589283), (97.662417, 16.5607013), (97.659315, 16.5700096), (97.655104, 16.5821991), (97.654882, 16.5855235), (97.654593, 16.5931971), (97.659381, 16.5957754), (97.669927, 16.5995844), (97.683111, 16.6022215), (97.695123, 16.6028077), (97.704206, 16.5984131), (97.704499, 16.5825917), (97.70007, 16.5731793), (97.698976, 16.572997), (97.697211, 16.5717833), (97.692114, 16.5691237), (97.684358, 16.5691235), (97.675936, 16.567572), (97.66818, 16.5611446), (97.666491, 16.5599384)], [(97.653232, 16.574263), (97.652445, 16.5679244), (97.655949, 16.5683449), (97.659594, 16.5627383), (97.659734, 16.5585335), (97.662257, 16.5550293), (97.660855, 16.5512449), (97.658613, 16.5490023), (97.659173, 16.544517), (97.654407, 16.5408727), (97.641933, 16.5363874), (97.63086, 16.5303604), (97.628057, 16.5312014), (97.625954, 16.5415736), (97.63072, 16.5613367), (97.638569, 16.5820811), (97.645017, 16.5892294), (97.649743, 16.5887155), (97.653232, 16.574263)], [(97.625696, 16.5488739), (97.623579, 16.5396268), (97.620589, 16.5423678), (97.616353, 16.5530826), (97.611619, 16.5637974), (97.611
12, 16.5725187), (97.613339, 16.5792777), (97.635042, 16.5874696), (97.64152, 16.5981844), (97.643015, 16.605909), (97.645756, 16.6066565), (97.650989, 16.6034172), (97.644012, 16.5984335), (97.64219, 16.5877556), (97.636038, 16.5804926), (97.63252, 16.570307), (97.628314, 16.5603089), (97.625696, 16.5488739)], [(97.607902, 16.3798949), (97.604911, 16.3719709), (97.602519, 16.3749612), (97.601323, 16.3955933), (97.604014, 16.406059), (97.604762, 16.4084511), (97.607896, 16.4081673), (97.609397, 16.397537), (97.609397, 16.3882674), (97.607902, 16.3798949)], [(97.64902, 16.5107163), (97.645437, 16.5073734), (97.641933, 16.5076538), (97.641933, 16.5108776), (97.645717, 16.5160636), (97.651112, 16.5211243), (97.655721, 16.5238328), (97.656392, 16.5184349), (97.654359, 16.515696), (97.64902, 16.5107163)]) AS dd
┌─dd─┐
│ 1 │
└────┘

  1. this location is in the other polygon after first polygon and can't get correct result.

SELECT pointInPolygon((97.641933, 16.5076538), [(97.66905, 16.5026053), (97.667878, 16.4979175), (97.661433, 16.4917645), (97.656745, 16.4859047), (97.656745, 16.4818029), (97.658796, 16.4785801), (97.665535, 16.4753572), (97.670808, 16.4730135), (97.676082, 16.4697907), (97.680477, 16.4677398), (97.68575, 16.4686189), (97.689559, 16.4727207), (97.69454, 16.4744788), (97.698055, 16.4747718), (97.702157, 16.4724279), (97.703036, 16.4683261), (97.703036, 16.4633453), (97.702451, 16.4594354), (97.699533, 16.4539205), (97.699106, 16.4521467), (97.699896, 16.4500714), (97.701852, 16.4474887), (97.701272, 16.4460233), (97.699896, 16.4439216), (97.699857, 16.4425297), (97.700705, 16.4417585), (97.699266, 16.4404319), (97.696817, 16.439585), (97.69468, 16.4391501), (97.690854, 16.439294), (97.686571, 16.4407665), (97.683728, 16.4428458), (97.680647, 16.444719), (97.678369, 16.445322), (97.675195, 16.4448526), (97.672627, 16.4435941), (97.670568, 16.4419727), (97.667276, 16.4410039), (97.666215, 16.439402), (97.66599, 16.43656), (97.664579, 16.435632), (97.66195, 16.4344612), (97.659174, 16.4324549), (97.658693, 16.4290256), (97.659289, 16.4246502), (97.660882, 16.422609), (97.663533, 16.4225057), (97.666402, 16.4210711), (97.67148, 16.4170395), (97.673433, 16.4146478), (97.674184, 16.4124121), (97.6742, 16.4085257), (97.674894, 16.4055148), (97.675906, 16.4019452), (97.675287, 16.3996593), (97.675062, 16.3963334), (97.675798, 16.3936434), (97.675676, 16.3909321), (97.67508, 16.386655), (97.679839, 16.386241), (97.689403, 16.3726191), (97.692011, 16.372909), (97.696359, 16.3679819), (97.699866, 16.360968), (97.697233, 16.3609438), (97.693077, 16.3596272), (97.686631, 16.3584552), (97.68165, 16.3558182), (97.674619, 16.3496653), (97.667588, 16.3482003), (97.664072, 16.3502511), (97.659384, 16.3540599), (97.652353, 16.3578686), (97.649716, 16.3625565), (97.650595, 16.3672443), (97.65206, 16.3701742), (97.65206, 16.3733971), (97.651181, 16.3760339), (97.646493, 16.3763268), (97.6462, 16.3801357), (97.646786, 16.3851165), (97.643563, 16.3883393), (97.638583, 16.3889252), (97.636239, 16.392148), (97.630379, 16.3933199), (97.629132, 16.3964903), (97.624347, 16.4056104), (97.615377, 16.4165245), (97.614779, 16.4229534), (97.611938, 16.4335685), (97.613882, 16.4410439), (97.619713, 16.4461272), (97.62375, 16.4542007), (97.62345, 16.4640683), (97.618965, 16.4793181), (97.617321, 16.4884382), (97.617747, 16.4985751), (97.623301, 16.5026416), (97.629303, 16.5016624), (97.63272, 16.4986048), (97.640862, 16.498226), (97.647134, 16.5006382), (97.650873, 16.5051263), (97.654987, 16.5089598), (97.65639, 16.5118583), (97.658166, 16.5160658), (97.660395, 16.5197566), (97.66612, 16.5140318), (97.668757, 16.507879), (97.66905, 16.5026053)], [(97.666491, 16.5599384), (97.665077, 16.5589283), (97.662417, 16.5607013), (97.659315, 16.5700096), (97.655104, 16.5821991), (97.654882, 16.5855235), (97.654593, 16.5931971), (97.659381, 16.5957754), (97.669927, 16.5995844), (97.683111, 16.6022215), (97.695123, 16.6028077), (97.704206, 16.5984131), (97.704499, 16.5825917), (97.70007, 16.5731793), (97.698976, 16.572997), (97.697211, 16.5717833), (97.
692114, 16.5691237), (97.684358, 16.5691235), (97.675936, 16.567572), (97.66818, 16.5611446), (97.666491, 16.5599384)], [(97.653232, 16.574263), (97.652445, 16.5679244), (97.655949, 16.5683449), (97.659594, 16.5627383), (97.659734, 16.5585335), (97.662257, 16.5550293), (97.660855, 16.5512449), (97.658613, 16.5490023), (97.659173, 16.544517), (97.654407, 16.5408727), (97.641933, 16.5363874), (97.63086, 16.5303604), (97.628057, 16.5312014), (97.625954, 16.5415736), (97.63072, 16.5613367), (97.638569, 16.5820811), (97.645017, 16.5892294), (97.649743, 16.5887155), (97.653232, 16.574263)], [(97.625696, 16.5488739), (97.623579, 16.5396268), (97.620589, 16.5423678), (97.616353, 16.5530826), (97.611619, 16.5637974), (97.61112, 16.5725187), (97.613339, 16.5792777), (97.635042, 16.5874696), (97.64152, 16.5981844), (97.643015, 16.605909), (97.645756, 16.6066565), (97.650989, 16.6034172), (97.644012, 16.5984335), (97.64219, 16.5877556), (97.636038, 16.5804926), (97.63252, 16.570307), (97.628314, 16.5603089), (97.625696, 16.5488739)], [(97.607902, 16.3798949), (97.604911, 16.3719709), (97.602519, 16.3749612), (97.601323, 16.3955933), (97.604014, 16.406059), (97.604762, 16.4084511), (97.607896, 16.4081673), (97.609397, 16.397537), (97.609397, 16.3882674), (97.607902, 16.3798949)], [(97.64902, 16.5107163), (97.645437, 16.5073734), (97.641933, 16.5076538), (97.641933, 16.5108776), (97.645717, 16.5160636), (97.651112, 16.5211243), (97.655721, 16.5238328), (97.656392, 16.5184349), (97.654359, 16.515696), (97.64902, 16.5107163)]) as dd;
┌─dd─┐
│ 0 │
└────┘

If my format of script is not correct or pointInPolygon does not support MultiPolygon fully?

@vicchen7 vicchen7 added the bug Confirmed user-visible misbehaviour in official release label Feb 27, 2020
@nikitamikhaylov
Copy link
Member

ClickHouse doesn't support MultiPolygon's. But we support polygons with holes.

@vicchen7
Copy link
Author

I have new issue when used below polygon and some locations (see attached) and got wrong result.
polygon_test.txt

Does CH not support like this polygon as well?

Image_1583826596266

@qoega qoega added feature and removed bug Confirmed user-visible misbehaviour in official release labels Mar 12, 2020
@alexey-milovidov
Copy link
Member

Yes, ClickHouse supports these types of polygons (polygon with multiple holes).
But care should be taken as polygon should not have self-intersections. If there are self-intersections, the function may work incorrectly.

@vicchen7
Copy link
Author

Thanks for your reply.
For our case it's one polygon with 58 holes and the result of Mysql UDF is correct completely but CH not.
If there is different description of this type of polygon for CH?
Can you guide how to make better polygon string ?

@alexey-milovidov
Copy link
Member

@vicchen7 I'm trying to figure out why the result is not correct.
By the way, what tool did you use to draw this picture?

@alexey-milovidov
Copy link
Member

I found this fiddle:
http://jsfiddle.net/Lspz5k21/

But if I didn't missed something, it looks like that the polygon has multiple self-intersections.

@alexey-milovidov
Copy link
Member

No, it is the issue in this JavaScript.

alexey-milovidov added a commit that referenced this issue Mar 25, 2020
alexey-milovidov added a commit that referenced this issue Mar 25, 2020
@alexey-milovidov alexey-milovidov self-assigned this Mar 25, 2020
@alexey-milovidov alexey-milovidov added the bug Confirmed user-visible misbehaviour in official release label Mar 25, 2020
@vicchen7
Copy link
Author

@vicchen7 I'm trying to figure out why the result is not correct.
By the way, what tool did you use to draw this picture?

I used below URL to draw and I separate all polygons to draw one by one but not found self-intersections.

http://jsfiddle.net/asnyder14/9dxbcr4f/embedded/result/

@alexey-milovidov
Copy link
Member

Yes, I have also validated this polygon and added a test.

@alexey-milovidov
Copy link
Member

#9857

@alexey-milovidov
Copy link
Member

Fixed in master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Confirmed user-visible misbehaviour in official release comp-geo feature
Projects
None yet
Development

No branches or pull requests

4 participants