Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compute lat and long from utm information #75

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ gunicorn = "*"
social-auth-app-django = "*"
libtiff = "*"
lxml = "*"
pyproj = "*"

[requires]
python_version = "3.7"
Expand Down
34 changes: 30 additions & 4 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

50 changes: 50 additions & 0 deletions tests/operations/gis_operations/sample.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
x,y,utm_left,utm_top,utm_right,utm_bottom,utm_zone
0,0,213300.0,2034900.0,252292.85471248726,1995900.0,15
1,0,213377.98570942497,2034900.0,252370.8404219122,1995900.0,15
2,0,213455.97141884995,2034900.0,252448.8261313372,1995900.0,15
3,0,213533.95712827492,2034900.0,252526.81184076215,1995900.0,15
4,0,213611.9428376999,2034900.0,252604.79755018716,1995900.0,15
5,0,213689.92854712487,2034900.0,252682.7832596121,1995900.0,15
6,0,213767.91425654985,2034900.0,252760.7689690371,1995900.0,15
0,1,213300.0,2034822.0,252292.85471248726,1995822.0,15
1,1,213377.98570942497,2034822.0,252370.8404219122,1995822.0,15
2,1,213455.97141884995,2034822.0,252448.8261313372,1995822.0,15
3,1,213533.95712827492,2034822.0,252526.81184076215,1995822.0,15
4,1,213611.9428376999,2034822.0,252604.79755018716,1995822.0,15
5,1,213689.92854712487,2034822.0,252682.7832596121,1995822.0,15
6,1,213767.91425654985,2034822.0,252760.7689690371,1995822.0,15
0,2,213300.0,2034744.0,252292.85471248726,1995744.0,15
1,2,213377.98570942497,2034744.0,252370.8404219122,1995744.0,15
2,2,213455.97141884995,2034744.0,252448.8261313372,1995744.0,15
3,2,213533.95712827492,2034744.0,252526.81184076215,1995744.0,15
4,2,213611.9428376999,2034744.0,252604.79755018716,1995744.0,15
5,2,213689.92854712487,2034744.0,252682.7832596121,1995744.0,15
6,2,213767.91425654985,2034744.0,252760.7689690371,1995744.0,15
0,3,213300.0,2034666.0,252292.85471248726,1995666.0,15
1,3,213377.98570942497,2034666.0,252370.8404219122,1995666.0,15
2,3,213455.97141884995,2034666.0,252448.8261313372,1995666.0,15
3,3,213533.95712827492,2034666.0,252526.81184076215,1995666.0,15
4,3,213611.9428376999,2034666.0,252604.79755018716,1995666.0,15
5,3,213689.92854712487,2034666.0,252682.7832596121,1995666.0,15
6,3,213767.91425654985,2034666.0,252760.7689690371,1995666.0,15
0,4,213300.0,2034588.0,252292.85471248726,1995588.0,15
1,4,213377.98570942497,2034588.0,252370.8404219122,1995588.0,15
2,4,213455.97141884995,2034588.0,252448.8261313372,1995588.0,15
3,4,213533.95712827492,2034588.0,252526.81184076215,1995588.0,15
4,4,213611.9428376999,2034588.0,252604.79755018716,1995588.0,15
5,4,213689.92854712487,2034588.0,252682.7832596121,1995588.0,15
6,4,213767.91425654985,2034588.0,252760.7689690371,1995588.0,15
0,5,213300.0,2034510.0,252292.85471248726,1995510.0,15
1,5,213377.98570942497,2034510.0,252370.8404219122,1995510.0,15
2,5,213455.97141884995,2034510.0,252448.8261313372,1995510.0,15
3,5,213533.95712827492,2034510.0,252526.81184076215,1995510.0,15
4,5,213611.9428376999,2034510.0,252604.79755018716,1995510.0,15
5,5,213689.92854712487,2034510.0,252682.7832596121,1995510.0,15
6,5,213767.91425654985,2034510.0,252760.7689690371,1995510.0,15
0,6,213300.0,2034432.0,252292.85471248726,1995432.0,15
1,6,213377.98570942497,2034432.0,252370.8404219122,1995432.0,15
2,6,213455.97141884995,2034432.0,252448.8261313372,1995432.0,15
3,6,213533.95712827492,2034432.0,252526.81184076215,1995432.0,15
4,6,213611.9428376999,2034432.0,252604.79755018716,1995432.0,15
5,6,213689.92854712487,2034432.0,252682.7832596121,1995432.0,15
6,6,213767.91425654985,2034432.0,252760.7689690371,1995432.0,15
48 changes: 48 additions & 0 deletions tests/operations/gis_operations/test_compute_lat_long.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
from unittest import TestCase
from unittest.mock import call, patch, MagicMock, Mock, PropertyMock, ANY

from theia.operations.gis_operations import ComputeLatLong
from theia.api.models import ImageryRequest, JobBundle, PipelineStage

class TestComputeLatLong(TestCase):
def setUp(self):
self.request = ImageryRequest(adapter_name='dummy')
self.stage = PipelineStage(
select_images=['composite'],
sort_order=3,
config={
'output_filename': 'foo.csv',
},
)
self.bundle = JobBundle(current_stage=self.stage, imagery_request=self.request)
self.operation = ComputeLatLong(self.bundle)

@patch('theia.operations.gis_operations.ComputeLatLong.convert_to_lat_long', side_effect=[(5.0, 6.0), (7.0, 8.0)])
def test_commit_lat_long_values_for_row(self, mock_object):
row_with_lat_long = self.operation.add_lat_long_values_to_row(
{
'x' : 1.0,
'y' : 2.0,
'utm_left' : 3.0,
'utm_top' : 3.0,
'utm_right' : 3.0,
'utm_bottom' : 3.0,
'utm_zone': 15,
}
)
assert all(expected in row_with_lat_long.keys() for expected in ["x","y","utm_left","utm_top","utm_right","utm_bottom"])
assert row_with_lat_long.get('top_left_latitude')==5.0
assert row_with_lat_long.get('top_left_longitude')==6.0
assert row_with_lat_long.get('bottom_right_latitude')==7.0
assert row_with_lat_long.get('bottom_right_longitude')==8.0

@patch('pyproj.proj.Proj.__call__', return_value=('latitude_number', 'longitude_number'))
@patch('pyproj.proj.Proj.__init__', return_value=None)
def test_convert_to_lat_long(self, mock_init, mock_call):
latitude, longitude = self.operation.convert_to_lat_long(1.0, 2.0, 15)

mock_init.assert_called_once_with(proj='utm', zone=15, ellps='WGS84')
mock_call.assert_called_once_with(1.0, 2.0, inverse=True)

assert latitude == 'latitude_number'
assert longitude == 'longitude_number'
1 change: 1 addition & 0 deletions theia/operations/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

operations = {
'gis_operations.compute_corners': gis_operations.ComputeCorners,
'gis_operations.compute_lat_long': gis_operations.ComputeLatLong,

'image_operations.resize_image': image_operations.ResizeImage,
'image_operations.remap_image': image_operations.RemapImage,
Expand Down
1 change: 1 addition & 0 deletions theia/operations/gis_operations/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from .compute_corners import ComputeCorners
from .compute_lat_long import ComputeLatLong
35 changes: 35 additions & 0 deletions theia/operations/gis_operations/compute_lat_long.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import csv
from pyproj import Proj

from ..abstract_operation import AbstractOperation

class ComputeLatLong(AbstractOperation):
def apply(self, filenames):
pass

# TODO: parse csv from string to integer

def convert_to_lat_long(self, utm_x: float, utm_y: float, utm_zone: int):
conversion_method = Proj(proj='utm', zone=utm_zone, ellps='WGS84')
return conversion_method(utm_x, utm_y, inverse=True)

def add_lat_long_values_to_row(self, utm_row_as_dictionary):
top_left_lat, top_left_long = self.convert_to_lat_long(
utm_row_as_dictionary['utm_left'],
utm_row_as_dictionary['utm_top'],
utm_row_as_dictionary['utm_zone'],
)
utm_row_as_dictionary.update({
'top_left_latitude': top_left_lat,
'top_left_longitude': top_left_long,
})
bottom_right_lat, bottom_right_long = self.convert_to_lat_long(
utm_row_as_dictionary['utm_right'],
utm_row_as_dictionary['utm_bottom'],
utm_row_as_dictionary['utm_zone'],
)
utm_row_as_dictionary.update({
'bottom_right_latitude': bottom_right_lat,
'bottom_right_longitude': bottom_right_long,
})
return utm_row_as_dictionary