Skip to content

Commit

Permalink
Fixed up bounding box
Browse files Browse the repository at this point in the history
  • Loading branch information
Mappboy committed Sep 18, 2016
1 parent 74b2053 commit 8cf7edf
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
20 changes: 13 additions & 7 deletions frisson/frisson.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# from osgeo import gdal
# from osgeo import ogr
from subprocess import call
from subprocess import call, check_output
from os import environ, path


Expand Down Expand Up @@ -120,12 +120,12 @@ def georeference(input_filename, output_filename, control_points, opts):
assert "RESAMPLE_OPTION" in opts
assert "MASK_OPTIONS" in opts
args = [
path.join(environ["GDAL_HOME"], "gdal_warp"),
path.join(environ["GDAL_HOME"], "gdalwarp"),
"-r",
opts["RESAMPLE_OPTION"],
"-srcnodata"] + opts["MASK_OPTIONS"] + [
"-dstalpha",
"s_srs",
"-srcnodata"] + opts["MASK_OPTIONS"] + [
"-s_srs",
"EPSG:4326",
"-co",
"TILED=YES",
Expand All @@ -134,20 +134,26 @@ def georeference(input_filename, output_filename, control_points, opts):
input_filename,
output_filename
]
print(" ".join(args))
return call(args)


def get_map_bbbox(filename):
"""
$GDAL_PATH/gdalinfo $INPUT_WARPED_TIF
$DO_STUFF_TO_PARSE "Lower Left" "Upper Right"
This is such a shitty hack but I think it's best to replace a lot of the functions with ogr.
So for consistancy I will keep it as is till we discuss further.
:param filename:
:return:
"""
args = [
path.join(environ["GDAL_HOME"], "gdalinfo"),
filename,
"Lower Left",
"Upper Right"
]
return call(args)
bbox = []
output = check_output(args)
for line in output.split("\n"):
if "Upper Right" in line or "Lower Left" in line:
bbox.append(line)
return bbox
14 changes: 8 additions & 6 deletions tests/unit/test_frisson.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,19 @@ def test_gcp_string(self):
)

def test_georeference(self):
opts = {"MASK_OPTIONS":["17", "17", "17"],
"RESAMPLE_OPTION":"near"}
opts = {"MASK_OPTIONS":["'17 17 17'"],
"RESAMPLE_OPTION": "near"}
self.assertEquals(
georeference("tests/test_output.vrt",
"tests/test_output_referenced.tif",
self.gcp_string,
opts)
opts), 0
)

def test_map_bbox(self):
self.assertEquals(get_map_bbbox("tests/test_output_referenced.tif"),
0)
['Lower Left (-9186967.204, 2427630.502) (Invalid angle,Invalid angle)',
'Upper Right (-9186247.194, 2428339.250) (Invalid angle,Invalid angle)'])

@classmethod
def tearDownClass(self):
Expand All @@ -86,8 +87,9 @@ def tearDownClass(self):
"tests/test_output.shp",
"tests/test_output.shx",
"tests/test_output.vrt",
"test_output_referenced.tif",
"test_output_referenced.tif.aux.xml"
]
for tf in test_files:
if path.isfile(tf):
pass
#remove(tf)
remove(tf)

0 comments on commit 8cf7edf

Please sign in to comment.