GeoDjango:如何根据点和半径创建圆
我有以下(简化)模型:
class Zone(gismodels.Model):
name = gismodels.CharField()
poly = gismodels.PolygonField()
我想根据给定的点和半径创建并保存代表圆的多边形。
我能弄清楚如何实现这一点的唯一方法是使用原始 SQL 调用 postgis ST_Buffer 函数。我真的希望还有另一种方法。
是否可以访问 GEOS 缓冲区方法?
I have the following (simplified) Model:
class Zone(gismodels.Model):
name = gismodels.CharField()
poly = gismodels.PolygonField()
I want to create and save a polygon that represents a circle, based upon a given point and radius.
The only way I can figure out how to achieve this, is to call the postgis ST_Buffer function using raw SQL. I'm really hoping that there is another way.
Is it possible to access the GEOS buffer methods?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,可以使用 geos 缓冲方法:
这里的半径与点的坐标单位相同。这适用于某些坐标系(例如 UTM),但不适用于其他坐标系。
另外,虽然这适合构建圆形几何图形,但 PostGIS 文档 指出,对于半径搜索
ST_DWithin
效率更高。Yes, it is possible to use the geos buffer method:
The radius here is in the same units as the coordinates of the points. This will work for some coordinate systems like UTM, but not as well for others.
Also, while this is appropriate for constructing a circular geometry, the PostGIS documentation notes that for doing radius searches
ST_DWithin
is more efficient.我花了很多时间试图让这个工作正常进行。由于这是排名第一的谷歌搜索结果,因此这对我有用:
奖励:如果您这样做是为了在谷歌静态地图上获得一个圆圈,请抓住 折线:
I spent a ridiculous amount of time trying to get this working. Since this is the number one google search result, here's what worked for me:
Bonus: If you're doing this so you can get a circle on a google static map, grab polyline: