Advertisement
Guest User

Untitled

a guest
Nov 2nd, 2016
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. class ModelA(models.Model):
  2. pointid = models.CharField(max_length=25)
  3. name = models.CharField(max_length=200)
  4. geom - gismodels.PointField()
  5. object = gismodels.GeoManager()
  6.  
  7. class ModelB(models.Model):
  8. name = models.CharField(max_length=200)
  9. line_geom = gismodels.LineStringField(null=True)
  10. color = RGBColorField(null=True)
  11. object = gismodels.GeoManager()
  12.  
  13. >>> import psycopg2
  14. >>> conn = psycopg2.connect(dbname=..., port=..., user=...,
  15. password=..., host=...)
  16.  
  17. >>> cur.execute("SELECT (???) (ST_MakeLine(ARRAY[ST_MakePoint(???)]);")
  18. >>> cur.fetchall()
  19.  
  20. class ParentModel():
  21. name = models.CharField()
  22. geom = models.LinestringField()
  23.  
  24. class ChildModel():
  25. parent = models.ForeignKey(ParentModel)
  26. order= models.IntegerField()
  27. geom = models.PointField()
  28.  
  29. childs = parent.childmodel_set.all()
  30.  
  31. childs = parent.childmodel_set.all().orderby('order')
  32.  
  33. # there are many ways to achieve this. you can use a for, for example
  34. # or a list comprehension, shown below
  35. linestring = LineString([child.geom for child in childs])
  36. parent.geom = linestring
  37. parent.save()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement