У меня есть коллекция полигонов в гео json. Я хочу проверить, существует ли точка в коллекции. Когда я использую функцию ST_CONTAINS, я получаю ошибку - [22001][3037] Data truncation: Invalid GIS data provided to function st_equals.
Вот SQL, который используется для этого -
set @lengthyPolygon = '{"type": "FeatureCollection", "features": [{"type": "Feature", "id": "022025", "properties": {"polygon": ""}, "geometry": {"type": "Polygon", "coordinates": [[[-91.57581301323287, 31.882569251472027], [-91.54530428802416, 31.752149550720354], [-91.69461757845744, 31.735283082006998], [-91.70753892089878, 31.63988547552637], [-91.8066025462824, 31.630700233010494], [-91.80696147246134, 31.438777007810444], [-91.86331288255275, 31.354444664243672], [-91.83459878823865, 31.266352279880927], [-91.92684281622267, 31.294767445324766], [-91.99109060225047, 31.225206690599304], [-92.00831905883892, 31.325760924457263], [-92.00544764940751, 31.92731373694408], [-91.88951449361436, 31.971467358862476], [-91.7804009352208, 31.871772562900738], [-91.59698965778952, 31.969748483070035], [-91.57581301323287, 31.882569251472027]]]}}, {"type": "Feature", "id": "022029", "properties": {"polygon": ""}, "geometry": {"type": "Polygon", "coordinates": [[[-91.54530428802416, 31.752149550720354], [-91.37948039336025, 31.73431621437375], [-91.40137489027475, 31.620279548518806], [-91.49469569679556, 31.644988388035188], [-91.41214267564254, 31.564684659606954], [-91.51120630102616, 31.532563168235658], [-91.5047456298055, 31.36497277847239], [-91.57832549648536, 31.405205214989277], [-91.51551341517327, 31.278169550953976], [-91.65477677259663, 31.250184104458253], [-91.58945220803207, 31.19115146396151], [-91.62606267828254, 31.116863800806833], [-91.56396844932831, 31.066801543351907], [-91.63683046365033, 30.999389383367003], [-91.66267314853302, 30.97027592463248], [-91.65836603438589, 30.9943401857267], [-91.72404952512939, 31.044241298576082], [-91.67738912186898, 31.18798228671919], [-91.83459878823865, 31.266352279880927], [-91.86331288255275, 31.354444664243672], [-91.80696147246134, 31.438777007810444], [-91.8066025462824, 31.630700233010494], [-91.70753892089878, 31.63988547552637], [-91.69461757845744, 31.735283082006998], [-91.54530428802416, 31.752149550720354]]]}}, {"type": "Feature", "id": "022041", "properties": {"polygon": ""}, "geometry": {"type": "Polygon", "coordinates": [[[-91.47674938784925, 32.40580578566562], [-91.52915260997247, 32.299289201402615], [-91.492542139722, 32.20330073136833], [-91.4896707302906, 32.09028464801516], [-91.57581301323287, 31.882569251472027], [-91.59698965778952, 31.969748483070035], [-91.7804009352208, 31.871772562900738], [-91.88951449361436, 31.971467358862476], [-91.89489838629825, 32.15151959812096], [-91.77142778074764, 32.24799150197187], [-91.76101892155879, 32.335331878175424], [-91.63503583275569, 32.40537606671751], [-91.47674938784925, 32.40580578566562]]]}}, {"type": "Feature", "id": "022065", "properties": {"polygon": ""}, "geometry": {"type": "MultiPolygon", "coordinates": [[[[-91.03096307362294, 32.120526118988465], [-91.05321649671636, 32.12423244491592], [-91.03096307362294, 32.120526118988465], [-91.03096307362294, 32.120526118988465]]], [[[-91.12392495396482, 32.211035672434335], [-91.492542139722, 32.20330073136833], [-91.52915260997247, 32.299289201402615], [-91.47674938784925, 32.40580578566562], [-91.45772630036616, 32.53778321760419], [-91.13361596079582, 32.53789064734122], [-91.07080387948375, 32.562223482778], [-91.08982696696683, 32.45441774167067], [-90.97999555621541, 32.447810812843464], [-91.0044025363824, 32.361491019141674], [-90.9125174345773, 32.33946792305099], [-91.0029668316667, 32.22301408811292], [-91.12392495396482, 32.211035672434335]]]]}}]}';
select ST_CONTAINS(ST_GeomFromGeoJSON(@lengthyPolygon), ST_GeomFromText('POINT(-91.8535746 31.6140366)', 4326));
Интересно, если я уменьшу длину Гео json для удаления нескольких полигонов, запрос работает нормально.
set @polygn = '{"type": "FeatureCollection", "features": [{"type": "Feature", "id": "022025", "properties": {"polygon": ""}, "geometry": {"type": "Polygon", "coordinates": [[[-91.57581301323287, 31.882569251472027], [-91.54530428802416, 31.752149550720354], [-91.69461757845744, 31.735283082006998], [-91.70753892089878, 31.63988547552637], [-91.8066025462824, 31.630700233010494], [-91.80696147246134, 31.438777007810444], [-91.86331288255275, 31.354444664243672], [-91.83459878823865, 31.266352279880927], [-91.92684281622267, 31.294767445324766], [-91.99109060225047, 31.225206690599304], [-92.00831905883892, 31.325760924457263], [-92.00544764940751, 31.92731373694408], [-91.88951449361436, 31.971467358862476], [-91.7804009352208, 31.871772562900738], [-91.59698965778952, 31.969748483070035], [-91.57581301323287, 31.882569251472027]]]}}, {"type": "Feature", "id": "022029", "properties": {"polygon": ""}, "geometry": {"type": "Polygon", "coordinates": [[[-91.54530428802416, 31.752149550720354], [-91.37948039336025, 31.73431621437375], [-91.40137489027475, 31.620279548518806], [-91.49469569679556, 31.644988388035188], [-91.41214267564254, 31.564684659606954], [-91.51120630102616, 31.532563168235658], [-91.5047456298055, 31.36497277847239], [-91.57832549648536, 31.405205214989277], [-91.51551341517327, 31.278169550953976], [-91.65477677259663, 31.250184104458253], [-91.58945220803207, 31.19115146396151], [-91.62606267828254, 31.116863800806833], [-91.56396844932831, 31.066801543351907], [-91.63683046365033, 30.999389383367003], [-91.66267314853302, 30.97027592463248], [-91.65836603438589, 30.9943401857267], [-91.72404952512939, 31.044241298576082], [-91.67738912186898, 31.18798228671919], [-91.83459878823865, 31.266352279880927], [-91.86331288255275, 31.354444664243672], [-91.80696147246134, 31.438777007810444], [-91.8066025462824, 31.630700233010494], [-91.70753892089878, 31.63988547552637], [-91.69461757845744, 31.735283082006998], [-91.54530428802416, 31.752149550720354]]]}}, {"type": "Feature", "id": "022041", "properties": {"polygon": ""}, "geometry": {"type": "Polygon", "coordinates": [[[-91.47674938784925, 32.40580578566562], [-91.52915260997247, 32.299289201402615], [-91.492542139722, 32.20330073136833], [-91.4896707302906, 32.09028464801516], [-91.57581301323287, 31.882569251472027], [-91.59698965778952, 31.969748483070035], [-91.7804009352208, 31.871772562900738], [-91.88951449361436, 31.971467358862476], [-91.89489838629825, 32.15151959812096], [-91.77142778074764, 32.24799150197187], [-91.76101892155879, 32.335331878175424], [-91.63503583275569, 32.40537606671751], [-91.47674938784925, 32.40580578566562]]]}}]}';
select ST_CONTAINS(ST_GeomFromGeoJSON(@polygn), ST_GeomFromText('POINT(-91.8535746 31.6140366)', 4326));
По-видимому, MySQL, кажется, ограничивает длину переменной. Согласно этому thread , тип данных пользовательской переменной должен быть LONGTEXT. Но это не похоже на это. Какой тип данных по умолчанию для определенной пользователем строки? Есть ли способ задать для него очень длинный текст?
Это проверено в MySQL 5.7