是否可以在 GeoDjango 或 PostGIS 中通过查询选择具有最大面积的多边形? [英] Is it possible to select the polygon with the maximum area with a query in GeoDjango or PostGIS?

查看:77
本文介绍了是否可以在 GeoDjango 或 PostGIS 中通过查询选择具有最大面积的多边形?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有很多市区多边形,我需要选择面积最大的多边形.目前我遍历每个对象并计算每个对象的面积,但这效率低下.做这个的最好方式是什么?

I have lots of urban area multipolygons and I need to select the one with the largest area. At the moment I iterate through each object and calculate the area for each but this is inefficient. What is the best way to do this?

推荐答案

我不确定你是否可以在 GeoDjango 中直接调用 ST_Area,结合聚合查询,但你可以使用 原始 SQL 查询.例如,使用@MikeT 发布的正确 Postgres 查询,

I am not sure if you can call ST_Area directly in GeoDjango, in conjunction with an aggregate query, but you could use a raw SQL query. For example, using the correct Postgres query, as posted by @MikeT,

top_area = ModelName.objects.raw('SELECT * FROM sometable ORDER BY ST_Area(geom) DESC LIMIT 1')[0]

这篇关于是否可以在 GeoDjango 或 PostGIS 中通过查询选择具有最大面积的多边形?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆