问题描述
我在 BigQuery 中使用已经定位的数据构建多边形时遇到问题。当我使用以下查询根据我对此事发布的其他问题的阅读来构建它时,我收到此错误,在阅读了与此相关的许多其他问题后,我无法解决该错误。我能得到这方面的帮助吗?我已经发布了我用作 Pandas 数据框的数据,以便为大家提供适当的参考点。
错误信息:
ST_Makepolygon 失败:多边形循环无效:边 1 与边 7 具有重复顶点
查询:
WITH Table as (SELECT disTINCT location,latitude,longitude FROM dataset.table
WHERE latitude is not null and longitude is not null)
SELECT County,PRECINCT_NAME,ST_MAKEpolyGON(ST_MAKELINE(ARRAY_AGG(ST_GEOGPOINT(longitude,latitude)))) as geom
FROM Table
Group By location
参考数据集:
import pandas as pd
df=pd.DataFrame(data=[('location','location','location'),(-84.2996966,-84.31496,-84.31463,-84.29973,-84.29918,-84.29949),(39.1699112,39.219543,39.21876,39.16986,39.17092,39.17686)],columns=['location','longitude','latitude'])
解决方法
而不是失败
ST_MAKEPOLYGON(ST_MAKELINE(ARRAY_AGG(ST_GEOGPOINT(longitude,latitude)))) as geom
你可以试试下面
ST_CONVEXHULL(ST_UNION_AGG(ST_GEOGPOINT(longitude,latitude))) as geom
如果在您的问题中为示例数据运行此程序 - 结果是
POLYGON((-84.31496 39.219543,-84.29973 39.16986,-84.2996966 39.1699112,-84.29918 39.17092,-84.29949 39.17686,-84.31463 39.21876,-84.31496 39.219543))