Clickhouse: The result of pointInPolygon is not correct

Created on 8 Oct 2019  路  3Comments  路  Source: ClickHouse/ClickHouse

Found some abnormal result when I used function pointInPolygon to check if the point belongs to the polygon.

Below is one sample and the point does not belong to this polygon but the result is true.
CH version : 19.13.2
Point:(106.784534,-6.301819)
Polygon:
[(106.396667,-6.97889),(106.391403,-6.90002),(106.418701,-6.881078),(106.438408,-6.81564),(106.487457,-6.794578),(106.511497,-6.765959),(106.429398,-6.69578),(106.4319,-6.58653),(106.400299,-6.527179),(106.403702,-6.455621),(106.441002,-6.449611),(106.458298,-6.421798),(106.428001,-6.348768),(106.472282,-6.31181),(106.502007,-6.356301),(106.531693,-6.35331),(106.519547,-6.32599),(106.577698,-6.34261),(106.595253,-6.363669),(106.761696,-6.36268),(106.775948,-6.316749),(106.805023,-6.31454),(106.794601,-6.361689),(106.846298,-6.34686),(106.909447,-6.375459),(106.922676,-6.316119),(106.907608,-6.267298),(106.945259,-6.255381),(106.970306,-6.19889),(106.972839,-6.09111),(107.01722,-6.078333),(106.986115,-6.046944),(107.015556,-6.033612),(107.006386,-6.018888),(106.993057,-6.028611),(106.998886,-6.010834),(106.987778,-6.00778),(107.016113,-5.973889),(107.008331,-5.942777),(106.989723,-5.942777),(107.007774,-5.918055),(107.09639,-5.93583),(107.164719,-5.98778),(107.28186,-5.95887),(107.339996,-5.968889),(107.394669,-6.024244),(107.431114,-6.08889),(107.453613,-6.098334),(107.444717,-6.107779),(107.466347,-6.14317),(107.539352,-6.177455),(107.623055,-6.189167),(107.666542,-6.244673),(107.696106,-6.223329),(107.7192,-6.23663),(107.744446,-6.229444),(107.820557,-6.18333),(107.850281,-6.187779),(107.855621,-6.211535),(107.8909,-6.18976),(107.890266,-6.237501),(108.128067,-6.33466),(108.20977,-6.273844),(108.185402,-6.233223),(108.199173,-6.234169),(108.183754,-6.227846),(108.221146,-6.250309),(108.299057,-6.246679),(108.336662,-6.27466),(108.348618,-6.239379),(108.384048,-6.355161),(108.45208,-6.434005),(108.538109,-6.483586),(108.558609,-6.673333),(108.59861,-6.759443),(108.630066,-6.771299),(108.652496,-6.74944),(108.681999,-6.767789),(108.690903,-6.803061),(108.750053,-6.814699),(108.805466,-6.785109),(108.808304,-6.766012),(108.78923,-6.760084),(108.801781,-6.743726),(108.830612,-6.744647),(108.825981,-6.826869),(108.754517,-6.914639),(108.761108,-6.983061),(108.798851,-7.005829),(108.780296,-7.04129),(108.777687,-7.10483),(108.729866,-7.113669),(108.696846,-7.15117),(108.625366,-7.13698),(108.567177,-7.16577),(108.563629,-7.194781),(108.584663,-7.229239),(108.555428,-7.2864),(108.560173,-7.335101),(108.583191,-7.3496),(108.6614,-7.343176),(108.682167,-7.36908),(108.685913,-7.398278),(108.719513,-7.43226),(108.71711,-7.484769),(108.753296,-7.56022),(108.733803,-7.61757),(108.800278,-7.674238),(108.776482,-7.700318),(108.777496,-7.68722),(108.763046,-7.697499),(108.712776,-7.676939),(108.67363,-7.682003),(108.658646,-7.701118),(108.678352,-7.721672),(108.670181,-7.731625),(108.641808,-7.687838),(108.539795,-7.690876),(108.489311,-7.716899),(108.489037,-7.74571),(108.496391,-7.720375),(108.507729,-7.76412),(108.482323,-7.802709),(108.44091,-7.820901),(108.300041,-7.814594),(108.083336,-7.773059),(108.002617,-7.741906),(107.846878,-7.737311),(107.838112,-7.703628),(107.812683,-7.68903),(107.682068,-7.661919),(107.676102,-7.629168),(107.601654,-7.571306),(107.482368,-7.539161),(107.473412,-7.518377),(107.399536,-7.493769),(107.277748,-7.492119),(107.130775,-7.456499),(106.867699,-7.431205),(106.796669,-7.436666),(106.790276,-7.410278),(106.788452,-7.43691),(106.560959,-7.417106),(106.436943,-7.35972),(106.409447,-7.366388),(106.405556,-7.382778),(106.398277,-7.33253),(106.372856,-7.307386),(106.384903,-7.262221),(106.373055,-7.237223),(106.390831,-7.22861),(106.400558,-7.186389),(106.4627,-7.181409),(106.448891,-7.15333),(106.456551,-7.12988),(106.544044,-7.055977),(106.551666,-7.023889),(106.543053,-6.985556),(106.511948,-6.965001),(106.440208,-6.952566),(106.396667,-6.97889)]

Here is the query.
select ((pointInPolygon((106.784534,-6.301819), [(106.396667,-6.97889),(106.391403,-6.90002),(106.418701,-6.881078),(106.438408,-6.81564),(106.487457,-6.794578),(106.511497,-6.765959),(106.429398,-6.69578),(106.4319,-6.58653),(106.400299,-6.527179),(106.403702,-6.455621),(106.441002,-6.449611),(106.458298,-6.421798),(106.428001,-6.348768),(106.472282,-6.31181),(106.502007,-6.356301),(106.531693,-6.35331),(106.519547,-6.32599),(106.577698,-6.34261),(106.595253,-6.363669),(106.761696,-6.36268),(106.775948,-6.316749),(106.805023,-6.31454),(106.794601,-6.361689),(106.846298,-6.34686),(106.909447,-6.375459),(106.922676,-6.316119),(106.907608,-6.267298),(106.945259,-6.255381),(106.970306,-6.19889),(106.972839,-6.09111),(107.01722,-6.078333),(106.986115,-6.046944),(107.015556,-6.033612),(107.006386,-6.018888),(106.993057,-6.028611),(106.998886,-6.010834),(106.987778,-6.00778),(107.016113,-5.973889),(107.008331,-5.942777),(106.989723,-5.942777),(107.007774,-5.918055),(107.09639,-5.93583),(107.164719,-5.98778),(107.28186,-5.95887),(107.339996,-5.968889),(107.394669,-6.024244),(107.431114,-6.08889),(107.453613,-6.098334),(107.444717,-6.107779),(107.466347,-6.14317),(107.539352,-6.177455),(107.623055,-6.189167),(107.666542,-6.244673),(107.696106,-6.223329),(107.7192,-6.23663),(107.744446,-6.229444),(107.820557,-6.18333),(107.850281,-6.187779),(107.855621,-6.211535),(107.8909,-6.18976),(107.890266,-6.237501),(108.128067,-6.33466),(108.20977,-6.273844),(108.185402,-6.233223),(108.199173,-6.234169),(108.183754,-6.227846),(108.221146,-6.250309),(108.299057,-6.246679),(108.336662,-6.27466),(108.348618,-6.239379),(108.384048,-6.355161),(108.45208,-6.434005),(108.538109,-6.483586),(108.558609,-6.673333),(108.59861,-6.759443),(108.630066,-6.771299),(108.652496,-6.74944),(108.681999,-6.767789),(108.690903,-6.803061),(108.750053,-6.814699),(108.805466,-6.785109),(108.808304,-6.766012),(108.78923,-6.760084),(108.801781,-6.743726),(108.830612,-6.744647),(108.825981,-6.826869),(108.754517,-6.914639),(108.761108,-6.983061),(108.798851,-7.005829),(108.780296,-7.04129),(108.777687,-7.10483),(108.729866,-7.113669),(108.696846,-7.15117),(108.625366,-7.13698),(108.567177,-7.16577),(108.563629,-7.194781),(108.584663,-7.229239),(108.555428,-7.2864),(108.560173,-7.335101),(108.583191,-7.3496),(108.6614,-7.343176),(108.682167,-7.36908),(108.685913,-7.398278),(108.719513,-7.43226),(108.71711,-7.484769),(108.753296,-7.56022),(108.733803,-7.61757),(108.800278,-7.674238),(108.776482,-7.700318),(108.777496,-7.68722),(108.763046,-7.697499),(108.712776,-7.676939),(108.67363,-7.682003),(108.658646,-7.701118),(108.678352,-7.721672),(108.670181,-7.731625),(108.641808,-7.687838),(108.539795,-7.690876),(108.489311,-7.716899),(108.489037,-7.74571),(108.496391,-7.720375),(108.507729,-7.76412),(108.482323,-7.802709),(108.44091,-7.820901),(108.300041,-7.814594),(108.083336,-7.773059),(108.002617,-7.741906),(107.846878,-7.737311),(107.838112,-7.703628),(107.812683,-7.68903),(107.682068,-7.661919),(107.676102,-7.629168),(107.601654,-7.571306),(107.482368,-7.539161),(107.473412,-7.518377),(107.399536,-7.493769),(107.277748,-7.492119),(107.130775,-7.456499),(106.867699,-7.431205),(106.796669,-7.436666),(106.790276,-7.410278),(106.788452,-7.43691),(106.560959,-7.417106),(106.436943,-7.35972),(106.409447,-7.366388),(106.405556,-7.382778),(106.398277,-7.33253),(106.372856,-7.307386),(106.384903,-7.262221),(106.373055,-7.237223),(106.390831,-7.22861),(106.400558,-7.186389),(106.4627,-7.181409),(106.448891,-7.15333),(106.456551,-7.12988),(106.544044,-7.055977),(106.551666,-7.023889),(106.543053,-6.985556),(106.511948,-6.965001),(106.440208,-6.952566),(106.396667,-6.97889)])));

point
point1

bug

Most helpful comment

I've found out that your polygon has self-intersection.

image

My geojson.

All 3 comments

I've found out that your polygon has self-intersection.

image

My geojson.

@KochetovNicolai Does it work as expected if you remove self-intersection?

PS. Can we throw an exception if self-intersection is found?

Yes, when I remove point (108.199173,-6.234169) I have correct result:

SELECT pointInPolygon((106.784534, -6.301819), [(106.396667, -6.97889), (106.391403, -6.90002), (106.418701, -6.881078), (106.438408, -6.81564), (106.487457, -6.794578), (106.511497, -6.765959), (106.429398, -6.69578), (106.4319, -6.58653), (106.400299, -6.527179), (106.403702, -6.455621), (106.441002, -6.449611), (106.458298, -6.421798), (106.428001, -6.348768), (106.472282, -6.31181), (106.502007, -6.356301), (106.531693, -6.35331), (106.519547, -6.32599), (106.577698, -6.34261), (106.595253, -6.363669), (106.761696, -6.36268), (106.775948, -6.316749), (106.805023, -6.31454), (106.794601, -6.361689), (106.846298, -6.34686), (106.909447, -6.375459), (106.922676, -6.316119), (106.907608, -6.267298), (106.945259, -6.255381), (106.970306, -6.19889), (106.972839, -6.09111), (107.01722, -6.078333), (106.986115, -6.046944), (107.015556, -6.033612), (107.006386, -6.018888), (106.993057, -6.028611), (106.998886, -6.010834), (106.987778, -6.00778), (107.016113, -5.973889), (107.008331, -5.942777), (106.989723, -5.942777), (107.007774, -5.918055), (107.09639, -5.93583), (107.164719, -5.98778), (107.28186, -5.95887), (107.339996, -5.968889), (107.394669, -6.024244), (107.431114, -6.08889), (107.453613, -6.098334), (107.444717, -6.107779), (107.466347, -6.14317), (107.539352, -6.177455), (107.623055, -6.189167), (107.666542, -6.244673), (107.696106, -6.223329), (107.7192, -6.23663), (107.744446, -6.229444), (107.820557, -6.18333), (107.850281, -6.187779), (107.855621, -6.211535), (107.8909, -6.18976), (107.890266, -6.237501), (108.128067, -6.33466), (108.20977, -6.273844), (108.185402, -6.233223), (108.183754, -6.227846), (108.221146, -6.250309), (108.299057, -6.246679), (108.336662, -6.27466), (108.348618, -6.239379), (108.384048, -6.355161), (108.45208, -6.434005), (108.538109, -6.483586), (108.558609, -6.673333), (108.59861, -6.759443), (108.630066, -6.771299), (108.652496, -6.74944), (108.681999, -6.767789), (108.690903, -6.803061), (108.750053, -6.814699), (108.805466, -6.785109), (108.808304, -6.766012), (108.78923, -6.760084), (108.801781, -6.743726), (108.830612, -6.744647), (108.825981, -6.826869), (108.754517, -6.914639), (108.761108, -6.983061), (108.798851, -7.005829), (108.780296, -7.04129), (108.777687, -7.10483), (108.729866, -7.113669), (108.696846, -7.15117), (108.625366, -7.13698), (108.567177, -7.16577), (108.563629, -7.194781), (108.584663, -7.229239), (108.555428, -7.2864), (108.560173, -7.335101), (108.583191, -7.3496), (108.6614, -7.343176), (108.682167, -7.36908), (108.685913, -7.398278), (108.719513, -7.43226), (108.71711, -7.484769), (108.753296, -7.56022), (108.733803, -7.61757), (108.800278, -7.674238), (108.776482, -7.700318), (108.777496, -7.68722), (108.763046, -7.697499), (108.712776, -7.676939), (108.67363, -7.682003), (108.658646, -7.701118), (108.678352, -7.721672), (108.670181, -7.731625), (108.641808, -7.687838), (108.539795, -7.690876), (108.489311, -7.716899), (108.489037, -7.74571), (108.496391, -7.720375), (108.507729, -7.76412), (108.482323, -7.802709), (108.44091, -7.820901), (108.300041, -7.814594), (108.083336, -7.773059), (108.002617, -7.741906), (107.846878, -7.737311), (107.838112, -7.703628), (107.812683, -7.68903), (107.682068, -7.661919), (107.676102, -7.629168), (107.601654, -7.571306), (107.482368, -7.539161), (107.473412, -7.518377), (107.399536, -7.493769), (107.277748, -7.492119), (107.130775, -7.456499), (106.867699, -7.431205), (106.796669, -7.436666), (106.790276, -7.410278), (106.788452, -7.43691), (106.560959, -7.417106), (106.436943, -7.35972), (106.409447, -7.366388), (106.405556, -7.382778), (106.398277, -7.33253), (106.372856, -7.307386), (106.384903, -7.262221), (106.373055, -7.237223), (106.390831, -7.22861), (106.400558, -7.186389), (106.4627, -7.181409), (106.448891, -7.15333), (106.456551, -7.12988), (106.544044, -7.055977), (106.551666, -7.023889), (106.543053, -6.985556), (106.511948, -6.965001), (106.440208, -6.952566), (106.396667, -6.97889)])

0

Suppose we can add self-intersection check.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

vixa2012 picture vixa2012  路  3Comments

amonakhov picture amonakhov  路  3Comments

bseng picture bseng  路  3Comments

jangorecki picture jangorecki  路  3Comments

vvp83 picture vvp83  路  3Comments