开发者

How do I use Django to insert a Geometry Field into the database?

开发者 https://www.devze.com 2022-12-25 18:29 出处:网络
class LocationLog(models.Model): user = models.ForeignKey(User) utm = models.GeometryField(spatial_index=True)
class LocationLog(models.Model):
    user = models.ForeignKey(User)
    utm = models.GeometryField(spatial_index=True)

This is my database model. I would like to insert a row.

I want to insert a circle at point -55, 333. With a radius of 10. How can I put this circle into the geometry field?

Of course, then I would want to c开发者_如何学Pythonheck which circles overlap a given circle. (my select statement)


Solved.

I created a square.

from django.contrib.gis.geos import Polygon

s =  Polygon(( (x-rad,y+rad)
              ,(x+rad,y+rad)
              ,(x+rad,y-rad)
              ,(x-rad,y-rad)
              ,(x-rad,y+rad) )
            )

Then you insert s into the database as a GeometryField.

0

精彩评论

暂无评论...
验证码 换一张
取 消