Commit ca84deda authored by kberry's avatar kberry
Browse files

basic functionality working with projected images

parent 99493571
Loading
Loading
Loading
Loading
+14 −2
Original line number Diff line number Diff line
@@ -6,6 +6,7 @@ import gdal
import osr

from autocnet.fileio import extract_metadata
from pysal import cg

gdal.UseExceptions()

@@ -207,6 +208,19 @@ class GeoDataset(object):

        return self._xy_extent

    @property
    def bounding_box(self):
        """
        A bounding box in lat/lon space
        Returns
        -------

        """
        if not getattr(self, '_bounding_box', None):
            latlons = self.latlon_extent # Will fail without geospatial data
            self._bounding_box = cg.standalone.get_bounding_box([cg.shapes.LineSegment(latlons[0], latlons[1])])
        return self._bounding_box

    @property
    def pixel_polygon(self):
        """
@@ -324,8 +338,6 @@ class GeoDataset(object):
        geotransform = self.geotransform
        x = geotransform[0] + (x * geotransform[1]) + (y * geotransform[2])
        y = geotransform[3] + (x * geotransform[4]) + (y * geotransform[5])
        print("X: ", x)
        print("Y: ", y)
        lon, lat, _ = self.coordinate_transformation.TransformPoint(x, y)

        return lat, lon
+16 −15
Original line number Diff line number Diff line
@@ -104,22 +104,23 @@ class CandidateGraph(nx.Graph):

        # TODO: Reject unsupported file formats (pngs, cubes, anything without usable geospatial data?)

        bblist = []
        dataset_list = []
        for file in filelst:
            # try to open the file, extract its bounding box.
            dataset = GeoDataset(file)
            latlons = dataset.latlon_extent # This is the step that fails without geospatial data.
            bb = cg.standalone.get_bounding_box([cg.shapes.LineSegment(latlons[0], latlons[1])]) #should move at least some of this into GeoDataset
            bblist += bb
        print(bblist)
        #for b in bblist:
        #    templist = bblist.copy()
        #    templist.remove(b)
        #    for other in templist:
        #        print("COMPARING", b, other)
        #        print(cg.standalone.bbcommon(b, other))

        return cls()
            dataset_list.append(dataset)

        adjacency_dict = {}
        for data in dataset_list:
            adjacent_images = []
            other_datasets = dataset_list.copy()
            other_datasets.remove(data)
            for other in other_datasets:
                if(cg.standalone.bbcommon(data.bounding_box, other.bounding_box)):
                    adjacent_images.append(other.base_name)
            adjacency_dict[data.base_name] = adjacent_images
        print(adjacency_dict)
        return cls(adjacency_dict)


    @classmethod
    def from_adjacency(cls, input_adjacency, basepath=None):
@@ -149,7 +150,7 @@ class CandidateGraph(nx.Graph):
                for k, v in input_adjacency.items():
                    input_adjacency[k] = [os.path.join(basepath, i) for i in v]
                    input_adjacency[os.path.join(basepath, k)] = input_adjacency.pop(k)

#        print(input_adjacency)
        return cls(input_adjacency)

    def get_name(self, node_index):
+4 −4
Original line number Diff line number Diff line
@@ -71,10 +71,10 @@ class TestFromList(unittest.TestCase):
    def setUpClass(cls):
        #cls.graph = network.CandidateGraph.from_filelist('/scratch/autocnet/autocnet/examples/Apollo15/fromlist.txt')
        #cls.graph = network.CandidateGraph.from_filelist(['/scratch/autocnet/autocnet/examples/Apollo15/AS15-M-0297_SML.png'])
         cls.grpah = network.CandidateGraph.from_filelist(
             ['/scratch/autocnet/autocnet/examples/Projections/Mars_MGS_MOLA_ClrShade_MAP2_0.0N0.0_MERC.tif',
              '/scratch/autocnet/autocnet/examples/Projections/Lunar_LRO_LOLA_Shade_MAP2_90.0N20.0_LAMB.tif',
              '/scratch/autocnet/autocnet/examples/Projections/Mars_MGS_MOLA_ClrShade_MAP2_90.0N0.0_POLA.tif'])
         cls.graph = network.CandidateGraph.from_filelist(
             ['/home/kree/usgs/autocnet/autocnet/examples/Projections/Mars_MGS_MOLA_ClrShade_MAP2_0.0N0.0_MERC.tif',
              '/home/kree/usgs/autocnet/autocnet/examples/Projections/Lunar_LRO_LOLA_Shade_MAP2_90.0N20.0_LAMB.tif',
              '/home/kree/usgs/autocnet/autocnet/examples/Projections/Mars_MGS_MOLA_ClrShade_MAP2_90.0N0.0_POLA.tif'])

    def testfail(self):
        self.assertTrue(False)