Example #1
0
def test_read_write_ground_control_points() -> None:
    text = """
{
  "points": [
    {
      "id": "1",
      "observations": [
        {
          "shot_id": "01.jpg",
          "projection": [0.7153, 0.5787]
        },
        {
          "shot_id": "02.jpg",
          "projection": [0.8085, 0.3831]
        }
      ]
    },
    {
      "id": "2",
      "position": {
        "latitude": 52.519251158,
        "longitude": 13.400502446,
        "altitude": 16.7021233002
      },
      "observations": [
        {
          "shot_id": "01.jpg",
          "projection": [0.2346, 0.4628]
        }
      ]
    }
  ]
}
    """

    def check_points(points):
        assert len(points) == 2
        p1, p2 = points
        if p1.id != "1":
            p1, p2 = p2, p1

        assert len(p1.observations) == 2
        assert np.allclose(p2.lla["latitude"], 52.519251158)
        assert np.allclose(p2.lla["longitude"], 13.400502446)
        assert np.allclose(p2.lla["altitude"], 16.7021233002)
        assert len(p2.observations) == 1

    # Read json
    fp = StringIO(text)
    points = io.read_ground_control_points(fp)
    check_points(points)

    # Write json and re-read
    fwrite = StringIO()
    io.write_ground_control_points(points, fwrite)
    freread = StringIO(fwrite.getvalue())
    points_reread = io.read_ground_control_points(freread)
    check_points(points_reread)
Example #2
0
def test_read_ground_control_points():
    text = """
{
  "points": [
    {
      "id": "1",
      "position": {
        "latitude": 52.519134104,
        "longitude": 13.400740745,
        "altitude": 12.0792090446
      },
      "observations": [
        {
          "shot_id": "01.jpg",
          "projection": [0.7153, 0.5787]
        },
        {
          "shot_id": "02.jpg",
          "projection": [0.8085, 0.3831]
        }
      ]
    },
    {
      "id": "2",
      "position": {
        "latitude": 52.519251158,
        "longitude": 13.400502446,
        "altitude": 16.7021233002
      },
      "observations": [
        {
          "shot_id": "01.jpg",
          "projection": [0.2346, 0.4628]
        }
      ]
    }
  ]
}    
    """
    fp = StringIO(text)
    reference = geo.TopocentricConverter(52.51913, 13.4007, 0)

    points = io.read_ground_control_points(fp, reference)
    assert len(points) == 2

    a, b = (len(point.observations) for point in points)
    assert min(a, b) == 1
    assert max(a, b) == 2
Example #3
0
    def load_ground_control_points(self) -> List[pymap.GroundControlPoint]:
        """Load ground control points."""
        exif = {image: self.load_exif(image) for image in self.images()}

        gcp = []
        if self.io_handler.isfile(self._gcp_list_file()):
            with self.io_handler.open_rt(self._gcp_list_file()) as fin:
                gcp = io.read_gcp_list(fin, exif)

        pcs = []
        if self.io_handler.isfile(self._ground_control_points_file()):
            with self.io_handler.open_rt(
                    self._ground_control_points_file()) as fin:
                pcs = io.read_ground_control_points(fin)

        return gcp + pcs
Example #4
0
    def load_ground_control_points(self):
        """Load ground control points.

        It uses reference_lla to convert the coordinates
        to topocentric reference frame.
        """
        exif = {image: self.load_exif(image) for image in self.images()}
        reference = self.load_reference()

        gcp = []
        if os.path.isfile(self._gcp_list_file()):
            with io.open_rt(self._gcp_list_file()) as fin:
                gcp = io.read_gcp_list(fin, reference, exif)

        pcs = []
        if os.path.isfile(self._ground_control_points_file()):
            with io.open_rt(self._ground_control_points_file()) as fin:
                pcs = io.read_ground_control_points(fin, reference)

        return gcp + pcs
Example #5
0
    def _load_ground_control_points(self, reference):
        """Load ground control points.

        It might use reference to convert the coordinates
        to topocentric reference frame.
        If reference is None, it won't initialize topocentric data,
        thus allowing loading raw data only.
        """
        exif = {image: self.load_exif(image) for image in self.images()}

        gcp = []
        if os.path.isfile(self._gcp_list_file()):
            with io.open_rt(self._gcp_list_file()) as fin:
                gcp = io.read_gcp_list(fin, reference, exif)

        pcs = []
        if os.path.isfile(self._ground_control_points_file()):
            with io.open_rt(self._ground_control_points_file()) as fin:
                pcs = io.read_ground_control_points(fin, reference)

        return gcp + pcs
Example #6
0
    def load_ground_control_points_impl(
        self, reference: Optional[geo.TopocentricConverter]
    ) -> List[pymap.GroundControlPoint]:
        """Load ground control points.

        It might use reference to convert the coordinates
        to topocentric reference frame.
        If reference is None, it won't initialize topocentric data,
        thus allowing loading raw data only.
        """
        exif = {image: self.load_exif(image) for image in self.images()}

        gcp = []
        if self.io_handler.isfile(self._gcp_list_file()):
            with self.io_handler.open_rt(self._gcp_list_file()) as fin:
                gcp = io.read_gcp_list(fin, reference, exif)

        pcs = []
        if self.io_handler.isfile(self._ground_control_points_file()):
            with self.io_handler.open_rt(self._ground_control_points_file()) as fin:
                pcs = io.read_ground_control_points(fin, reference)

        return gcp + pcs
Example #7
0
def test_read_write_ground_control_points():
    text = """
{
  "points": [
    {
      "id": "1",
      "observations": [
        {
          "shot_id": "01.jpg",
          "projection": [0.7153, 0.5787]
        },
        {
          "shot_id": "02.jpg",
          "projection": [0.8085, 0.3831]
        }
      ]
    },
    {
      "id": "2",
      "position": {
        "latitude": 52.519251158,
        "longitude": 13.400502446,
        "altitude": 16.7021233002
      },
      "observations": [
        {
          "shot_id": "01.jpg",
          "projection": [0.2346, 0.4628]
        }
      ]
    }
  ]
}
    """

    def check_points(points):
        assert len(points) == 2
        p1, p2 = points
        if p1.id != "1":
            p1, p2 = p2, p1

        assert p1.coordinates.has_value is False
        assert len(p1.observations) == 2
        assert np.allclose(p2.lla["latitude"], 52.519251158)
        assert np.allclose(p2.lla["longitude"], 13.400502446)
        assert np.allclose(p2.coordinates.value[2], 16.7021233002)
        assert len(p2.observations) == 1

    reference = geo.TopocentricConverter(52.51913, 13.4007, 0)

    # Read json
    fp = StringIO(text)
    points = io.read_ground_control_points(fp, reference)
    check_points(points)

    # Write json and re-read
    fwrite = StringIO()
    io.write_ground_control_points(points, fwrite, reference)
    freread = StringIO(fwrite.getvalue())
    points_reread = io.read_ground_control_points(freread, reference)
    check_points(points_reread)