sorl / django-mockups

Can create auto-generated test data.
Other
74 stars 12 forks source link

GIS fields #12

Open ouhouhsami opened 13 years ago

ouhouhsami commented 13 years ago

It could be interesting to have generator for geographic fields.

GeometryField PointField LineStringField PolygonField MultiPointField MultiLineStringField MultiPolygonField GeometryCollectionField

Could you give me a way to add support to these types of field ?

Thx

ouhouhsami commented 13 years ago

a first generator for pointfield, (we should ad srid value, this example is for google srid) :

class GeoPointGenerator(generators.Generator):
    def __init__(self, *args, **kwargs):
        super(GeoPointGenerator, self).__init__(*args, **kwargs)

    def generate(self):
        coord_0 = decimal.Decimal(str(random.randrange(2003750834)/100 - 20037508.34/2))
        coord_1 = decimal.Decimal(str(random.randrange(2003750834)/100 - 20037508.34/2))
        value = 'POINT(%s %s)' % (coord_0, coord_1)
        return value