TL,DR; I want to get a random point from a polygon (potentially) using ST_GeneratePoints.
I'm making a GeoDjango webservice and have a collection of UK Postcodes with respective boundaries like so:
from django.db import models as dj_models from django.contrib.gis.db import models as gis_models class Postcode(gis_models.Model): pretty_postcode = dj_models.CharField( max_length=8 ) coords = gis_models.PolygonField( default='POLYGON EMPTY' )
I've found a delightful little PostGis function ST_GeneratePoints, it can find me random points in my
Your mission if you so choose it, is to show how to use this function from within my python django app (or suggest a better way). Ideally ending up with a function like so:
from django.contrib.gis import geos # ... other imports ... class Postcode(gis_models.Model): # ... fields ... def get_random_point(self): rand_point = # code that executes ST_GeneratePoints # and returns a geos.Point instance return rand_point