wkt script with shapely

parent 65f57ac2
from django.core.management.base import BaseCommand, CommandError
from catalog.models import Polygon
import json
from shapely.geometry import shape
class Command(BaseCommand):
def handle(self, *args, **options):
polygons = self._ignore(Polygon.objects.all(), 'santa lucia aeropuerto')
for index, polygon in enumerate(polygons):
geometry = self._get_geometry(polygon)
shapely_geometry = shape(geometry)
polygon.wkt_polygon = shapely_geometry.wkt
polygon.save()
print('polygon %s updated c;'%index)
def _get_geometry(self, polygon):
info = json.loads(polygon.json_info)
return info['geometry']
def _ignore(self, polygons, names):
to_ignore = names.split(',')
return [p for p in polygons if p.name not in to_ignore]
...@@ -19,11 +19,6 @@ configfile = os.path.join(dirname, '../config/config.json') ...@@ -19,11 +19,6 @@ configfile = os.path.join(dirname, '../config/config.json')
with open(configfile, 'r') as f: with open(configfile, 'r') as f:
config = json.load(f) config = json.load(f)
print(config['PATHS']['PATH_GEOSENTINEL'])
print(config['PATHS']['PATH_NAS'])
print(config['API_SENTINEL']['SENTINEL_USER'])
print(config['API_SENTINEL']['SENTINEL_PASS'])
NAS_PATH = config['PATHS']['PATH_NAS'] NAS_PATH = config['PATHS']['PATH_NAS']
USERS_PATH = config['PATHS']['PATH_USERS'] USERS_PATH = config['PATHS']['PATH_USERS']
SENTINEL_PATH = config['PATHS']['PATH_GEOSENTINEL'] SENTINEL_PATH = config['PATHS']['PATH_GEOSENTINEL']
...@@ -237,7 +232,7 @@ def getFromCart(request): ...@@ -237,7 +232,7 @@ def getFromCart(request):
user = User.objects.get(id=request.user.id) user = User.objects.get(id=request.user.id)
prod_list = [] prod_list = []
product_list = Purchase.objects.values('user', 'productList', 'purchased', 'price', 'aggreg_date', 'id', product_list = Purchase.objects.values('user', 'productList', 'purchased', 'price', 'aggreg_date', 'id',
'search__process__name', 'search__startDate', 'search__endDate').filter(user=user, purchased=0) 'search__process__name', 'search__startDate', 'search__endDate').filter(user=user, purchased=0)
for products in product_list: for products in product_list:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment