Created
February 5, 2019 23:47
-
-
Save lclpedro/7a1bbc1dd1a43190f10f294063a3be1d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from server import db, app, jsonify, Blueprint, request,\ | |
datetime, os, func, wkt, json,\ | |
secure_filename, shapefile, zipfile, glob | |
ALLOWED_EXTENSIONS = set(['zip']) | |
def allowed_file(filename): | |
return '.' in filename and \ | |
filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS | |
def limpar_pasta(): | |
try: | |
path=app.config['UPLOAD_FOLDER'] | |
dir = os.listdir(path) | |
for file in dir: | |
os.system('rm -rf *') | |
return jsonify(data='Executado com Sucesso'), 200 | |
except: | |
return jsonify(data='Falha ao deletar arquivo'), 400 | |
def gerar_geom_shp(filename): | |
_zip=zipfile.ZipFile(app.config['UPLOAD_FOLDER']+filename,'r') | |
_zip.extractall(app.config['UPLOAD_FOLDER']) | |
try: | |
os.chdir(app.config['UPLOAD_FOLDER']) | |
for file in glob.glob('*.shp') and glob.glob('*.dbf') and glob.glob('*.prj'): | |
shape = shapefile.Reader(app.config['UPLOAD_FOLDER']+glob.glob('*.shp')[0]) | |
feature = shape.shapeRecords()[0] | |
first = feature.shape.__geo_interface__ | |
wkt_geom=wkt.dumps(first) | |
json=dict( | |
geom_save=wkt_geom, | |
geojson_shape=dict( | |
type='Feature', | |
geometry=first | |
), | |
data='Shapefile Válido' | |
) | |
return json | |
except: | |
return jsonify(data='Shapefile Inválido'), 400 | |
def gerar_wkt(filename): | |
_zip=zipfile.ZipFile(app.config['UPLOAD_FOLDER']+filename,'r') | |
_zip.extractall(app.config['UPLOAD_FOLDER']) | |
# try: | |
os.chdir(app.config['UPLOAD_FOLDER']) | |
for file in glob.glob('*.shp') and glob.glob('*.dbf') and glob.glob('*.prj'): | |
shape = shapefile.Reader(app.config['UPLOAD_FOLDER']+glob.glob('*.shp')[0]) | |
valores=[] | |
for und in shape.shapeRecords(): | |
geom_wkt = wkt.dumps(und.shape.__geo_interface__) | |
valores.append(geom_wkt) | |
return valores |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment