首页 > 解决方案 > 从 postgresql django 获取 Topojson

问题描述

我已经完成输入并运行所有 geodjango 代码,它工作。但是我的数据一次又一次地变大,导致geojson的大小变大。我使用此代码从 postgresql (postgis) 中读取数据库作为 geojson 并在传单中查看:

def testcrud_datasets(request):
    testcrud = serialize('geojson', Testcrud.objects.all())
    return HttpResponse(testcrud, content_type='json')

我读到的一些解决方案建议我应该使用 topojson,如何从我的 postgresql 数据库中获取 topojson 格式,因为序列化不支持 topojson 类型?

标签: pythondjangogeodjangotopojson

解决方案


看起来您可以使用此库在客户端转换为 Topojson。

https://github.com/topojson/topojson

<script src="https://unpkg.com/topojson@3"></script>
<script>

var topology = topojson.topology({foo: geojson});

</script>

推荐阅读