Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

import os 

from django.contrib.gis.db import models 

from django.conf import settings 

 

class Layer(models.Model): 

    name = models.CharField(max_length=50,unique=True) 

 

    def __unicode__(self): 

        return u"%s" % (self.name) 

 

class Feature(models.Model): 

    fid = models.AutoField(primary_key=True) 

    layer = models.ForeignKey(Layer) 

    geom = models.PolygonField(srid=4326) 

    objects = models.GeoManager() 

 

    def __unicode__(self): 

        return u"Feature %d of layer %s" % (self.fid, self.layer) 

 

class Attribute(models.Model): 

    key = models.CharField(max_length=50) 

    value = models.TextField() 

    feature = models.ForeignKey(Feature) 

 

    def __unicode__(self): 

        return u"%s::%s" % (self.key,self.value) 

 

rastdir = os.path.abspath(os.path.join(settings.MEDIA_ROOT, "xyquery_rasters")) 

if not os.path.exists(rastdir): 

    os.mkdir(rastdir) 

 

class Raster(models.Model): 

    layer = models.ForeignKey(Layer) 

    filepath = models.FilePathField(path=rastdir, recursive=True) 

 

    def __unicode__(self): 

        return u"Raster layer %s" % (self.layer)