SbM*_*olo 7 python django geodjango coordinates leaflet
首先感谢您的帮助。
我正在用 Django 创建一个表单,它使用 OSMWidget 将坐标(多边形、线和点)保存到 PostgreSQL 数据库中的几何字段。它运行良好,我可以毫无问题地将信息保存在数据库中。当我使用 PgAdmin 进行查询时,我可以正确地看到 Leaflet 地图中显示的几何字段数据。
.
以下是我在 forms.py 中的一些内容:
from django import forms
from django_select2 import forms as select2_forms
from django.contrib.gis import forms as osmforms
from django.forms import ModelForm
from .models import Dataset
class SessionForm(forms.ModelForm):
at_choices = [(item.title, item.title) for item in Dataset.objects.all()]
key_choices = [(item.keywords_d, item.keywords_d) for item in Dataset.objects.all()]
uuid = forms.CharField(label='', max_length=10 , widget=forms.TextInput(attrs={'class': "form-control left-half"}))
title = forms.CharField(label='Title', max_length=65536 , widget=forms.TextInput(attrs={'class': "form-control full-size-field"}))
abstract = forms.CharField(label='Abstract', max_length=65536 , widget=forms.Textarea(attrs={'class': "form-control full-size-field", 'title': 'Your name'}))
keywords_d = forms.MultipleChoiceField(label='Keywords', widget=select2_forms.Select2MultipleWidget(attrs={'class': "form-control left-half",'style': 'width:100%'}), choices=key_choices)
activity_type = forms.MultipleChoiceField(label='Activity type', widget=select2_forms.Select2MultipleWidget(attrs={'class': "form-control right-half",'style': 'width:100%'}), choices=at_choices)
related_site_we = forms.CharField(label='Related Site', max_length=256 , widget=forms.TextInput(attrs={'class': "form-control full-size-field"}))
bounding_box = osmforms.GeometryCollectionField(label='Bounding Box', widget=osmforms.OSMWidget(attrs={'class': "form-control full-size-field",'map_width': 992, 'map_height': 500}))
class Meta:
model = Dataset
fields = ['uuid','title','abstract','keywords_d','activity_type','related_site_we','bounding_box']
Run Code Online (Sandbox Code Playgroud)
这是views.py的一部分:
def editor(request):
if request.method == 'GET':
if request.GET['uuid'] != '0':
session = Dataset.objects.get(uuid=request.GET['uuid'])
form = SessionForm(instance=session)
else:
form = SessionForm()
return render(request, 'form.html',
{'form': form,})
Run Code Online (Sandbox Code Playgroud)
无需详细说明,表单的目的之一是部分填写,以便其他人以后可以对其进行编辑。编辑表单时,这会加载数据库中该条目的现有数据以及我们之前输入的坐标,这就是问题出现的地方,因为它似乎颠倒了纬度和经度的顺序,以这种方式出现:

刚才说了,坐标保存的很好,我觉得只是OSMWidget读取坐标的顺序有问题。有什么办法可以纠正这个问题吗?我已经阅读了几个小时的文档,并查看了 StackOverFlow 和其他论坛中的其他主题,但我找不到解决方案。
提前致谢
| 归档时间: |
|
| 查看次数: |
576 次 |
| 最近记录: |