gpt4 book ai didi

python - GeoDjango 将 MultiPolygon 解释为 LinearRing

转载 作者:太空宇宙 更新时间:2023-11-03 15:47:16 33 4
gpt4 key购买 nike

我正在从 Trimble 导入一些 OSM 数据到 PostGIS 数据库中,将其作为 Django 应用程序的一部分进行处理。这适用于点和线,但我正在努力处理多边形。

导入似乎工作正常:

shp2pgsql -d -I aeroway_polygon_polygon.shp aeroway_polygon | psql

Django InspectDB 以合理的方式解释数据:

./manage.py inspectdb > models.py

models.py 内容:

class AerowayPolygon(models.Model):
gid = models.AutoField(primary_key=True)
id = models.FloatField(blank=True, null=True)
osm_id = models.DecimalField(max_digits=65535, decimal_places=65535, blank=True, null=True)
z_order = models.FloatField(blank=True, null=True)
aeroway = models.CharField(max_length=80, blank=True, null=True)
name = models.CharField(max_length=80, blank=True, null=True)
name_en = models.CharField(db_column='name:en', max_length=80, blank=True, null=True) # Field renamed to remove unsuitable characters.
operator = models.CharField(max_length=80, blank=True, null=True)
ref = models.CharField(max_length=80, blank=True, null=True)
faa = models.CharField(max_length=80, blank=True, null=True)
iata = models.CharField(max_length=80, blank=True, null=True)
icao = models.CharField(max_length=80, blank=True, null=True)
website = models.CharField(max_length=80, blank=True, null=True)
contact_we = models.CharField(db_column='contact:we', max_length=80, blank=True, null=True) # Field renamed to remove unsuitable characters.
phone = models.CharField(max_length=80, blank=True, null=True)
contact_ph = models.CharField(db_column='contact:ph', max_length=80, blank=True, null=True) # Field renamed to remove unsuitable characters.
ele = models.CharField(max_length=80, blank=True, null=True)
tower_type = models.CharField(db_column='tower:type', max_length=80, blank=True, null=True) # Field renamed to remove unsuitable characters.
geom = models.MultiPolygonField(srid=0, dim=4, blank=True, null=True)

class Meta:
managed = False
db_table = 'aeroway_polygon'

任何从数据库访问对象的尝试都会导致 GEOS 提示 LinearRing。

>>> from data.models import AerowayPolygon
>>> AerowayPolygon.objects.all()[0]
GEOS_ERROR: IllegalArgumentException: Points of LinearRing do not form a closed linestring

错误没有错,点没有关闭LineString。但是我很困惑,因为我认为该类型应该是 MultiPolygon,因此应该可以正常工作。给了什么?


我通过手动尝试从 PostGIS 中获取几何图形进行了更深入的挖掘。

作为众所周知的二进制十六进制字符串,我得到了相同的行为:

>>> from django.contrib.gis.geos import GEOSGeometry
>>> wkb ='01060000C00100000001030000C0020000008E0000000064931E4F47DDBF4020B11AB5BC49400000000000000000FFFFFFFFFFFFEFFF006493B23347DDBF442075F9B7BC494 ... 003C9368871FDDBF4020B193B4BC49400000000000000000FFFFFFFFFFFFEFFF'
>>> GEOSGeometry(wkb)
GEOS_ERROR: IllegalArgumentException: Points of LinearRing do not form a closed linestring

但是,如果我使用 ST_AsEWKT 预先转换为众所周知的文本,则一切看起来都很好:

>>> wkt = 'MULTIPOLYGON(((-0.45747735963738 51.4742768635629 0 -1.79769313486232e+308,-0.457470821752906 51.474364454451 0 -1.79769313486232e+308, ... ,-0.455049373745112 51.4742607703088 0 -1.79769313486232e+308)))'
>>> GEOSGeometry(wkt)
<MultiPolygon object at 0x7f0948769098>

最佳答案

MultiPolygon 的每个多边形仍应形成闭合线串。您的数据可能格式不正确或已损坏。

您可以尝试使用 ST_MakeValid 来解决这个问题.

UPDATE aeroway_polygon
SET geom = ST_Multi(ST_CollectionExtract(ST_Makevalid(geom), 3))
WHERE ST_IsValid(geom) = false;

请注意,我没有测试这个查询,我找到了它 here on gis.stackexchange .

关于python - GeoDjango 将 MultiPolygon 解释为 LinearRing,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49307272/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com