/
actionsQGIS.py
99 lines (71 loc) · 2.37 KB
/
actionsQGIS.py
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/usr/bin/env python
#-*- coding: utf-8 -*-
"""
This file is intented to implent selected specific comand-line tools for using it with QGIS.
This will be an interfce between biospatial and QGIS
"""
__author__ = "Juan Escamilla M�lgora"
__copyright__ = "Copyright 2015, JEM"
__license__ = "GPL"
__version__ = "2.2.1"
__mantainer__ = "Juan"
__email__ ="molgor@gmail.com"
__status__ = "Prototype"
import logging
import sys
import getopt
from mesh.models import NestedMesh,initMesh
from django.contrib.gis.db.models.query import GeoQuerySet
from gbif.models import Occurrence, Specie
from gbif.taxonomy import GriddedTaxonomy
from django.core.management.base import BaseCommand, CommandError
import os
import sys
#sys.path.append('/home/username/www/site_folder')
os.environ['DJANGO_SETTINGS_MODULE'] = 'biospatial.settings'
from django.utils import unittest
from django.test.client import Client
logger = logging.getLogger('biospatial.actionsQGIS')
from ete2 import Tree, TreeStyle
def showTreeInGrid(gid,biome,grid_level=14,taxonomic_level='sp'):
"""
Performs a selection, spatial filter and returns an image.
grid_level is the grid layer.
taxonomic_level is the taxonomic level to be shown. Options are:
sp, gns, fam, ord, cls, phy, king
"""
mesh = initMesh(grid_level)
try:
cell = mesh.objects.get(id=id)
except:
logger.error("Selected id does not exist in selected grid")
return None
gb=GriddedTaxonomy(biome,cell,generate_tree_now=True)
forest = gb.taxonomies[0].forest
ts = TreeStyle()
ts.show_leaf_name = True
ts.mode = "c"
ts.arc_start = -180 # 0 degrees = 3 o'clock
ts.arc_span = 360
forest[taxonomic_level].show(tree_style=ts)
return 'Parece que se tiene que ver algo'
class Usage(Exception):
def __init__(self, msg):
self.msg = msg
def main(argv=None):
if argv is None:
argv = sys.argv
try:
try:
opts, args = getopt.getopt(argv[1:], "h", ["help"])
except getopt.error, msg:
raise Usage(msg)
# more code, unchanged
except Usage, err:
print >>sys.stderr, err.msg
print >>sys.stderr, "for help use --help"
return 2
biosphere = Occurrence.objects.all()
showTreeInGrid(argv[1],biosphere,taxonomic_level='sp')
if __name__ == "__main__":
sys.exit(main())