I'm a beginner in GIS developing and this might be a simple question. I'm using Python Django equipped with GeoDjango. Where I use Django-leaflet and database PostGreSQL with PostGIS.
I already have data in my model (Model A) where each element is a PointField. I now want to create a table that has a LineString. How do I create Model B that refers to my Model A?
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()
I assume it is mapped by FK, but I'm quite perplexed as how this must be created given that in a linestring it is a group of PointField from Model A?
The sequence of points are important. What I currently have is a file that states the sequence of these points (which refers to the id of those in Model A) and I'm not quite sure how to pass this data to the model as I read it.
Example:
id || sequence || pointFrom || pointTo
8801 || 1 || point01id || point02id
8801 || 2 || point02id || point03id
8801 || 3 || point03id
Edit: I'm looking at doing this code but yeah I still am missing what to do with the relationship on using the FK from Model A.
>>> import psycopg2
>>> conn = psycopg2.connect(dbname=..., port=..., user=...,
password=..., host=...)
>>> cur.execute("SELECT (???) (ST_MakeLine(ARRAY[ST_MakePoint(???)]);")
>>> cur.fetchall()