Commit 3e1c9604 authored by Benjamin Herfort's avatar Benjamin Herfort
Browse files

fix filenames #6

parent 5fe6a731
No preview for this file type
......@@ -6,6 +6,7 @@
import os
import sys
import math
import ntpath
class Point:
......@@ -58,18 +59,20 @@ def create_tiles_grid(infile, zoomlevel, feedback):
# Get filename and extension
try:
infile_name = infile.split(".")[0]
infile_extension = infile.split(".")[-1]
infile_dir = os.path.dirname(os.path.realpath(infile))
infile_name = os.path.basename(os.path.realpath(infile))
infile_extension = os.path.splitext(os.path.realpath(infile))[1]
print(infile_name)
except:
print("check input file")
feedback.pushInfo("check input file: %s" % infile)
sys.exit()
# Get the driver --> supported formats: Shapefiles, GeoJSON, kml
if infile_extension == "shp":
if infile_extension == ".shp":
driver = ogr.GetDriverByName("ESRI Shapefile")
elif infile_extension == "geojson":
elif infile_extension == ".geojson":
driver = ogr.GetDriverByName("GeoJSON")
elif infile_extension == "kml":
elif infile_extension == ".kml":
driver = ogr.GetDriverByName("KML")
else:
print("Check input file format for " + infile)
......@@ -107,9 +110,9 @@ def create_tiles_grid(infile, zoomlevel, feedback):
zoom = float(zoomlevel)
# create output file
outputGridfn = infile_name + "_tiles." + infile_extension
outputGridfn = infile_dir + '/' + infile_name.replace(infile_extension, "_tiles"+infile_extension)
outfile = infile_name + "_tiles.csv"
outfile = infile_dir + '/' + infile_name.replace(infile_extension, "_tiles.csv")
l = 0
if os.path.exists(outfile):
os.remove(outfile)
......@@ -210,7 +213,7 @@ def create_tiles_grid(infile, zoomlevel, feedback):
outFeature = ogr.Feature(featureDefn)
outFeature.SetGeometry(poly)
if infile_extension == "kml":
if infile_extension == ".kml":
col_row_zoom = str(TileX) + "_" + str(TileY) + "_" + str(int(zoom))
outFeature.SetField("name", col_row_zoom)
outFeature.SetField("description", "TileX_TileY_TileZ")
......@@ -224,7 +227,7 @@ def create_tiles_grid(infile, zoomlevel, feedback):
# Close DataSources
outDataSource.Destroy()
feedback.pushInfo('Created tiles grid: %s.' % outfile)
feedback.pushInfo('Created tiles grid: %s' % outfile)
feedback.setProgress(25)
return outfile, outputGridfn
......@@ -43,27 +43,26 @@ def get_tiles(infile, tms_url, feedback):
# Get filename and extension
try:
infile_name = infile.split(".")[0]
infile_extension = infile.split(".")[-1]
infile_dir = os.path.dirname(os.path.realpath(infile))
infile_name = os.path.basename(os.path.realpath(infile))
infile_extension = os.path.splitext(os.path.realpath(infile))[1]
except:
print("check input file")
feedback.pushInfo("check input file: %s" % infile)
sys.exit()
# Create output directory from input file name
#if not os.path.exists(outDirectory):
# os.makedirs(outDirectory)
print(infile_extension)
# Get the driver --> supported formats: Shapefiles, GeoJSON, kml
if infile_extension == "csv":
if infile_extension == ".csv":
csv = np.genfromtxt(infile, delimiter=";")
num_features = np.size(csv, 0) - 1
else:
if infile_extension == "shp":
if infile_extension == ".shp":
driver = ogr.GetDriverByName("ESRI Shapefile")
elif infile_extension == "geojson":
elif infile_extension == ".geojson":
driver = ogr.GetDriverByName("GeoJSON")
elif infile_extension == "kml":
elif infile_extension == ".kml":
driver = ogr.GetDriverByName("KML")
else:
print("Check input file format for " + infile)
......@@ -91,7 +90,7 @@ def get_tiles(infile, tms_url, feedback):
feedback.pushInfo('There are %s tiles to download.' % num_features)
for i in range(0, num_features):
# in_geometry= input_feature.GetGeometryRef()
if infile_extension == "csv":
if infile_extension == ".csv":
TileX = int(csv[i + 1][2])
TileY = int(csv[i + 1][3])
TileZ = int(csv[i + 1][4])
......
......@@ -370,7 +370,8 @@ def stitch_tiles(infile, tms_name, zoomlevel, image_size, feedback):
end_time = time.time()
run_time = end_time - start_time
feedback.pushInfo('Created Stitched Tiles Raster: %s.' % out_file)
feedback.pushInfo('############ YEAH #################')
feedback.pushInfo('Created Output Raster: %s' % out_file)
feedback.setProgress(75)
print('stitched tiles together')
......
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