我正在尝试使用South创建迁移以将我的数据从使用4326 SRID转换为900913.迁移后,坐标保持为4326格式。 (很容易区分出4326和900913的预测,因为900913中的数字要大得多)
以下是该迁移的forward()和backward()函数:
class Migration(SchemaMigration):
def forwards(self, orm):
# Changing field 'ZipCoords.point'
zips = orm.ZipCoords.objects.all()
db.alter_column('itinerary_generator_zipcoords', 'point', self.gf('django.contrib.gis.db.models.fields.PointField')(srid=900913, null=True))
for zip in zips:
zip.point.transform(900913)
zip.save()
def backwards(self, orm):
# Changing field 'ZipCoords.point'
zips = orm.ZipCoords.objects.all()
db.alter_column('itinerary_generator_zipcoords', 'point', self.gf('django.contrib.gis.db.models.fields.PointField')(null=True))
for zip in zips:
zip.point.transform(4326)
zip.save()
我正在使用Django Admin检查它们的值。另外,有趣的是,这种迁移“相反”,它将我的坐标转换为更小(但不正确)的数字。
答案 0 :(得分:2)
问题似乎是我转换的数据没有SRID。 (或者SRID是900913,导致转换()没有操作,我没有测试。)。这个更新的forward()函数有效:
def forwards(self, orm):
# Changing field 'ZipCoords.point'
zips = orm.ZipCoords.objects.all()
db.alter_column('itinerary_generator_zipcoords', 'point', self.gf('django.contrib.gis.db.models.fields.PointField')(srid=900913, null=True))
for zip in zips:
zip.point.srid = 4326
zip.point.transform(900913)
zip.save()