Commit 5c619dc4 authored by Jay's avatar Jay
Browse files

Adds geofootprint methods to network/node and associated tests.

parent 43e66902
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -882,3 +882,7 @@ class CandidateGraph(nx.Graph):
                return False

        return True

    def footprints(self):
        geoms = [n.footprint for i, n in self.nodes_iter(data=True)]
        return gpd.GeoDataFrame(geometry=geoms)
+11 −15
Original line number Diff line number Diff line
@@ -9,6 +9,7 @@ from plio.io.io_gdal import GeoDataset
from plio.io.isis_serial_number import generate_serial_number
from scipy.misc import bytescale, imresize
from shapely.geometry import Polygon
from shapely import wkt

from autocnet.cg import cg
from autocnet.control.control import Correspondence, Point
@@ -145,6 +146,16 @@ class Node(dict, MutableMapping):
        boolean_mask = v[1]
        self.masks[column_name] = boolean_mask
    """

    @property
    def footprint(self):
        if not getattr(self, '_footprint', None):
            try:
                self._footprint = wkt.loads(self.geodata.footprint.GetGeometryRef(0).ExportToWkt())
            except:
                return None
        return self._footprint

    @property
    def isis_serial(self):
        """
@@ -161,14 +172,7 @@ class Node(dict, MutableMapping):

    @property
    def nkeypoints(self):
<<<<<<< HEAD
        if hasattr(self, '_keypoints'):
            return len(self._keypoints)
        else:
            return 0
=======
        return len(self.keypoints)
>>>>>>> f2242f97db63cfc288581d950d1e506e6d9edc16

    def coverage(self):
        """
@@ -236,18 +240,10 @@ class Node(dict, MutableMapping):
         : dataframe
           A pandas dataframe of keypoints
        """
<<<<<<< HEAD
        if hasattr(self, '_keypoints'):
            if index is not None:
                return self._keypoints.ix[index]
            else:
                return self._keypoints
=======
        if index is not None:
            return self.keypoints.loc[index]
        else:
            return self.keypoints
>>>>>>> f2242f97db63cfc288581d950d1e506e6d9edc16

    def get_keypoint_coordinates(self, index=None, homogeneous=False):
        """
+19 −5
Original line number Diff line number Diff line
@@ -5,13 +5,12 @@ import sys
import pytest
import unittest

from unittest.mock import patch
from unittest.mock import PropertyMock
from osgeo import ogr
from unittest.mock import MagicMock
from plio.io import io_gdal
from unittest.mock import patch, PropertyMock, MagicMock

import geopandas as gpd
import numpy as np
from osgeo import ogr
from plio.io import io_gdal

from autocnet.examples import get_path

@@ -27,6 +26,17 @@ def graph():
    return network.CandidateGraph.from_adjacency(get_path('three_image_adjacency.json'),
                                                      basepath=basepath)

@pytest.fixture()
def geo_graph():
    basepath = get_path('Apollo15')
    a = 'AS15-M-0297_crop.cub'
    b = 'AS15-M-0298_crop.cub'
    c = 'AS15-M-0299_crop.cub'
    adjacency = {a:[b,c],
                 b:[a,c],
                 c:[a,b]}
    return network.CandidateGraph.from_adjacency(adjacency, basepath=basepath)

@pytest.fixture()
def disconnected_graph():
    return network.CandidateGraph.from_adjacency(get_path('adjacency.json'))
@@ -247,3 +257,7 @@ def test_is_complete(graph):

    assert False == incomplete_graph.is_complete()
    assert True == graph.is_complete()

def test_footprints(geo_graph):
    # This is just testing the interface - should get a geodataframe back
    assert isinstance(geo_graph.footprints(), gpd.GeoDataFrame)
+11 −0
Original line number Diff line number Diff line
@@ -8,6 +8,7 @@ import warnings
import numpy as np
import pandas as pd
import pytest
from shapely.geometry import Polygon


from autocnet.examples import get_path
@@ -26,6 +27,11 @@ class TestNode(object):
        return node.Node(image_name='AS15-M-0295_SML',
                              image_path=img)

    @pytest.fixture
    def geo_node(self):
        img = get_path('AS15-M-0297_crop.cub')
        return node.Node(image_name='AS15-M-0297_crop.cub', image_path=img)

    def test_get_handle(self, node):
        assert isinstance(node.geodata, GeoDataset)

@@ -125,3 +131,8 @@ class TestNode(object):
                                   columns=['a', 'b'])
        matches, mask = node._clean(clean_keys=['a'])
        assert mask.equals(pd.Series([True, True, True, False, False]))

    def test_footprint(self, geo_node):
        # Esnure that a shapely compliant poly is being returned
        assert isinstance(geo_node.footprint, Polygon)