Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class ModelA(models.Model):
- pointid = models.CharField(max_length=25)
- name = models.CharField(max_length=200)
- geom - gismodels.PointField()
- object = gismodels.GeoManager()
- class ModelB(models.Model):
- name = models.CharField(max_length=200)
- line_geom = gismodels.LineStringField(null=True)
- color = RGBColorField(null=True)
- object = gismodels.GeoManager()
- >>> import psycopg2
- >>> conn = psycopg2.connect(dbname=..., port=..., user=...,
- password=..., host=...)
- >>> cur.execute("SELECT (???) (ST_MakeLine(ARRAY[ST_MakePoint(???)]);")
- >>> cur.fetchall()
- class ParentModel():
- name = models.CharField()
- geom = models.LinestringField()
- class ChildModel():
- parent = models.ForeignKey(ParentModel)
- order= models.IntegerField()
- geom = models.PointField()
- childs = parent.childmodel_set.all()
- childs = parent.childmodel_set.all().orderby('order')
- # there are many ways to achieve this. you can use a for, for example
- # or a list comprehension, shown below
- linestring = LineString([child.geom for child in childs])
- parent.geom = linestring
- parent.save()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement