Skip to content

Commit

Permalink
added calculation for the Folder tag in kml file
Browse files Browse the repository at this point in the history
  • Loading branch information
gtsarik committed Nov 22, 2017
1 parent dfc97dc commit e3ce5f0
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 25 deletions.
2 changes: 2 additions & 0 deletions src/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@ def convert_size_file(size):
def get_type_file(mime_type):
"""**The method determines the mime-type of file: image, text, pdf, msword, doc, archive.**"""

type_file = 'bin'

if mime_type[0] == 'image':
type_file = mime_type[0]
elif mime_type[0] == 'text':
Expand Down
87 changes: 62 additions & 25 deletions src/customers/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import csv
from pykml import parser
from pykml.parser import Schema
from lxml import html
from lxml import html, etree
import numpy as np
import requests
from random import randint
Expand Down Expand Up @@ -4476,7 +4476,6 @@ def validation_kml(kml_name, kml_path):

try:
xml = html.parse(kml_path)

xml_extendeddata = len(xml.xpath("//extendeddata")) / 2
xml_coordinates = len(xml.xpath("//coordinates")) / 2
xml_point = len(xml.xpath("//point")) / 2
Expand Down Expand Up @@ -4507,9 +4506,65 @@ def validation_kml(kml_name, kml_path):
print '!!!!!!!!!!!!!!!!!! ERROR VALIDATION KML =========================== ', e
return e

# print '!!!!!!!!!!!!!!!!!!!!!! ERR MESG validation_kml ===================== ', error_msg

return error_msg


def is_calculation_aoi(doc_kml):
is_calculation = False

try:
if doc_kml.Document.Placemark.Polygon.outerBoundaryIs:
is_calculation = True
except Exception, e:
print '!!!!!!!!!!!!!!! ERROR KML Document ===================== ', e

# print '!!!!!!!!!!!!!!! 1 is_calculation_aoi ===================== ', is_calculation

try:
if doc_kml.Placemark.Polygon.outerBoundaryIs:
is_calculation = True
except Exception, e:
print '!!!!!!!!!!!!!!! ERROR KML Placemark ===================== ', e

# print '!!!!!!!!!!!!!!! 2 is_calculation_aoi ===================== ', is_calculation

return is_calculation


def get_info_window(doc_kml, file_name, path_to_file):
text = ''
count_color = get_count_color()
error = validation_kml(doc_kml, path_to_file)


info_window = '<h4 align="center" style="color:{0};"><b>Attribute report: {1}</b></h4>\n'.format(
COLOR_HEX_NAME[count_color], file_name)

if not error:
try:
text = doc_kml.Document.name
except Exception, e:
# print '!!!!!!!!!!!!!!! ERROR IW Document ===================== ', e
try:
text = doc_kml.Folder.name
except Exception, e:
# print '!!!!!!!!!!!!!!! ERROR IW Folder ===================== ', e
try:
text = doc_kml.Placemark.name
except Exception, e:
# print '!!!!!!!!!!!!!!! ERROR IW Placemark ===================== ', e
pass

if text:
info_window += '<p align="center">{0}</p>'.format(text);

print '!!!!!!!!!!!!!!! IW get_info_window ===================== ', info_window

return info_window


def getUploadListTifFiles(customer, dataset, *args):
# print '!!!!!!!!!!!!!!!!!!! args ====================== ', args
list_files_tif = []
Expand Down Expand Up @@ -5043,31 +5098,13 @@ def files_lister(request):
if not error:
count_color = get_count_color()
upload_file = file_name
calculation_aoi = is_calculation_aoi(doc_kml)
info_window = get_info_window(doc_kml, f_name[0], path_test_data)

try:
if doc_kml.Document.Placemark.Polygon.outerBoundaryIs:
calculation_aoi = True
except Exception, e:
print '!!!!!!!!!!!!!!! ERROR KML Document ===================== ', e

####################### write log file
files_lister_log.write('ERROR KML Document: {0}\n'.format(str(e)))
files_lister_log.write('\n')
#######################

try:
if doc_kml.Placemark.Polygon.outerBoundaryIs:
calculation_aoi = True
except Exception, e:
print '!!!!!!!!!!!!!!! ERROR KML Placemark ===================== ', e

####################### write log file
files_lister_log.write('ERROR PKML lacemark: {0}\n'.format(str(e)))
files_lister_log.write('\n')
#######################
print '!!!!!!!!!!!!!!! calculation_aoi ============================ ', calculation_aoi

info_window = '<h4 align="center" style="color:{0};"><b>Attribute report: {1}</b></h4>\n'.format(
COLOR_HEX_NAME[count_color], f_name)
# info_window = '<h4 align="center" style="color:{0};"><b>Attribute report: {1}</b></h4>\n'.format(
# COLOR_HEX_NAME[count_color], f_name)

except Exception, e:
print '!!!!!!!!!!!!!!! ERROR COPY KML ===================== ', e
Expand Down

0 comments on commit e3ce5f0

Please sign in to comment.