Django GEOS中的PostGIS ST_MakeValid等效项 [英] Equivalent of PostGIS ST_MakeValid in Django GEOS

查看:230
本文介绍了Django GEOS中的PostGIS ST_MakeValid等效项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Objects.polygon.valid检查多边形对象的有效性时,抛出了GEOS_NOTICE: Self-intersection错误.

Upon checking a polygon object's validity using Objects.polygon.valid, it thrown a GEOS_NOTICE: Self-intersection error.

我知道可以使用PostGIS的ST_MakeValid方法解决此问题.
我正在使用具有GEOS支持的Django 1.11,但在Django文档中找不到与之等效的版本.

I know this can be fixed by using the ST_MakeValid method of PostGIS.
I'm using Django 1.11 with GEOS support and can't find its equivalent in Django docs.

Django中的ST_MakeValid是否有等效的功能?

Is there any equivalent function for ST_MakeValid in Django?

推荐答案

Django版本> = 1.10:

存在数据库方法: MakeValid

Exists the database method: MakeValid

Django版本< 1.10:

您可以通过扩展 GeoFunc 类,该类本身扩展了 Func() 类:

You can create a custom database function by extending GeoFunc class which by itself extends the Func() class:

from django.contrib.gis.db.models.functions import GeoFunc

class MakeValid(GeoFunc):
    function='ST_MakeValid'

MakeValid(field_name)ST_MakeValid应用于具有field_name的字段.

The MakeValid(field_name) applies the ST_MakeValid to the field with field_name.

用法:

YourModel.objects.get(id=an_id).update(the_geom=MakeValid('the_geom'))

以下是使用 F()的等效查询表达式以执行更新:

The following is an equivalent query using F() expression to execute the update:

YourModel.objects.get(id=an_id)
                 .update(the_geom=GeoFunc(
                     F('the_geom'), 
                     function='ST_MakeValid'
                 ))

注意: the_geom代表您的几何字段(点,多边形等)

Note: the_geom represents your geometry field (point, polygon, etc.)

这篇关于Django GEOS中的PostGIS ST_MakeValid等效项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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