python - 从 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 类型?
解决方案
看起来您可以使用此库在客户端转换为 Topojson。
https://github.com/topojson/topojson
<script src="https://unpkg.com/topojson@3"></script>
<script>
var topology = topojson.topology({foo: geojson});
</script>
推荐阅读
- r - 使用非标准评估取消嵌套许多列
- python - 使用 Django 中的按钮增加整数(模型变量或 view.py 字典值)
- docker - Docker compose 什么都不做
- android - Android - 两个带有填充颜色、描边和图标的圆形 ImageButton
- javascript - 在 iOS 版 Safari 中禁用 Scroll-Rails
- node.js - 如何在没有对象'_text'道具的情况下使用xml-js
- mysql - 用sql简化
- android - 有条件的许可声明
- python - csv到动态html刷新
- octave - 从 Octave 数据帧访问数据时出现问题