0

我有一个名为geodf. 该数据框中每一行的几何图形是一个多面体。例如,如果我们通过地理数据框考虑几何列中的第一行:

bound = geodf['geometry'].iloc[0]
print(bound)

它看起来像这样:

MULTIPOLYGON (((-86.46228799973933 34.31021100007911, -86.46447100007661 34.31018399970606, -86.46447800010341 34.31197299998977, -86.4623920000716 34.31198799958079

多面体本身很大,所以我尝试为它创建一个盒子

box = shapely.geometry.box(*geodf.bounds)

然后我box通过我们的 Crate DB 服务器通过了以下查询:

query = """
                 SELECT geohash, grid,shape 
                 FROM geo 
                 WHERE layer = 'pop' 
                AND MATCH(shape, '{}') USING within;
          """.format(box)
geoCursor.execute(query)
results = geoCursor.fetchall()
District = gpd.GeoDataFrame(results, columns = ['geohash', 'grid','shape'])

box我在上面的查询中通过多边形传递.format(box)

我想做的是通过bound而不是box在上面的查询中(请注意,上面的查询适用于box)。但是,当我尝试通过时,bound出现以下错误:

ProgrammingError: SQLActionException[UnhandledServerException: java.lang.IllegalArgumentException: Cannot convert Map "{type=MultiPolygon, coordinates=[[[[D@2b59d486}" to shape]

我无法诊断出上述错误。我想知道为什么bounds不起作用以及如何使它起作用?我们不想使用边界框,因为在我们的多面体边界中没有包含很多多余的区域

4

1 回答 1

0

您可以将多面体表示为类似于 geoJSON 格式的 dict,然后使用参数替换。我不熟悉 shapely,所以我无法评论您如何获得 dict 表示,但使用手动制作的字典,它看起来如下:

multipolygon = {
    "type": "MultiPolygon",
    "coordinates": [
        [
            [
                [ 40.0, 40.0 ],
                [ 20.0, 45.0 ],
                [ 45.0, 30.0 ],
                [ 40.0, 40.0 ]
            ]
        ],
        [
            [
                [ 20.0, 35.0 ],
                [ 10.0, 30.0 ],
                [ 10.0, 10.0 ],
                [ 30.0, 5.0 ],
                [ 45.0, 20.0 ],
                [ 20.0, 35.0 ]
            ],
            [
                [ 30.0, 20.0 ],
                [ 20.0, 15.0 ],
                [ 20.0, 25.0 ],
                [ 30.0, 20.0 ]
            ]
        ]
    ]
}

c.execute('select * from t where match(x, ?) using within', (multipolygon, ))
print(c.fetchall())
于 2018-02-12T10:28:27.273 回答