0

私はgeodjangoアプリを作ろうとしています。SQLite と SpatialLite を使用しています。ショップを追加して、自分の場所から最も近いものから最も遠いものへと並べ替えることができるようにしたいと考えています。

私のモデルで私が持っているとき:

location = gis_models.PointField(srid=4326, blank=True, null=True)

その後、追加は機能しますが、距離による並べ替えは機能しません。次のようになります。

SQLite does not support linear distance calculations on geodetic coordinate systems.

私が持っているとき:

location = gis_models.PointField(srid=3857, blank=True, null=True)

追加が機能せず、並べ替えが機能するよりも、次のようになります。

geo_shop.location violates Geometry constraint [geom-type or SRID not allowed]

両方を同時に機能させるにはどうすればよいですか?

4

1 に答える 1

-1

ロケーションの追加中のエラーは、srid の不一致に関連しています。

並べ替えには srid=3857 を使用しますが、場所を追加する場合は、次の方法を使用して 4326 から 3857 に変換します (この回答から)。

>>> from django.contrib.gis.gdal import SpatialReference, CoordTransform
>>> from django.contrib.gis.geos import Point
>>> gcoord = SpatialReference(4326)
>>> mycoord = SpatialReference(22186)
>>> trans = CoordTransform(gcoord, mycoord)

>>> pnt = Point(30, 50, srid=4326)
>>> print 'x: %s; y: %s; srid: %s' % (pnt.x, pnt.y, pnt.srid)
x: 30.0; y: 50.0; srid: 4326
>>> pnt.transform(trans)
>>> print 'x: %s; y: %s; srid: %s' % (pnt.x, pnt.y, pnt.srid)
x: 11160773.5712; y: 19724623.9117; srid: 22186
于 2015-10-20T19:08:37.013 に答える