Example #1
0
    def transform(source_cordinate: CrsCoordinate,
                  target_crs_projection: CrsProjection) -> CrsCoordinate:
        if (source_cordinate.get_crs_projection() == target_crs_projection):
            return source_cordinate

        _transFormStrategy: _TransformStrategy = None

        # Transform FROM wgs84:
        if (source_cordinate.get_crs_projection().is_wgs84()
                and (target_crs_projection.is_sweref99()
                     or target_crs_projection.is_rt90())):
            _transFormStrategy = _Transformer.transformStrategy_From_WGS84_to_SWEREF99_or_RT90

        # Transform TO wgs84:
        elif (target_crs_projection.is_wgs84()
              and (source_cordinate.get_crs_projection().is_sweref99()
                   or source_cordinate.get_crs_projection().is_rt90())):
            _transFormStrategy = _Transformer.transformStrategy_From_SWEREF99_or_RT90_to_WGS84

        # Transform between two non-wgs84:
        elif ((source_cordinate.get_crs_projection().is_sweref99()
               or source_cordinate.get_crs_projection().is_rt90())
              and (target_crs_projection.is_sweref99()
                   or target_crs_projection.is_rt90())):
            # the only direct transform supported is to/from WGS84, so therefore first transform to wgs84
            _transFormStrategy = _Transformer.transFormStrategy_From_Sweref99OrRT90_to_WGS84_andThenToRealTarget

        return _Transformer._transform_with_explicit_strategy(
            _transFormStrategy, source_cordinate, target_crs_projection)
Example #2
0
    def transform(self,
                  source_coordinate: CrsCoordinate,
                  final_target_crs_projection: CrsProjection
                  ) -> CrsCoordinate:
        from sweden_crs_transformations.transformation._transformer import _Transformer
        source_coordinate_projection: CrsProjection = source_coordinate.get_crs_projection()
        if (not (
            (source_coordinate_projection.is_sweref99() or source_coordinate_projection.is_rt90())
            and
            (final_target_crs_projection.is_sweref99() or final_target_crs_projection.is_rt90())
        )):
            _Transformer._throwExceptionMessage(source_coordinate.get_crs_projection(), final_target_crs_projection)

        intermediate_crs_projection = CrsProjection.WGS84
        intermediate_wgs84_coordinate = _Transformer.transform(source_coordinate, intermediate_crs_projection)
        return _Transformer.transform(intermediate_wgs84_coordinate, final_target_crs_projection)
    def test_get_crs_projection_by_epsg_number(self):
        self.assertEqual(
            CrsProjection.SWEREF_99_TM,
            CrsProjection.get_crs_projection_by_epsg_number(
                CrsProjectionTest.epsgNumberForSweref99tm))

        self.assertEqual(
            CrsProjection.SWEREF_99_23_15,
            CrsProjection.get_crs_projection_by_epsg_number(
                3018)  # https://epsg.io/3018
        )

        self.assertEqual(
            CrsProjection.RT90_5_0_GON_O,
            CrsProjection.get_crs_projection_by_epsg_number(
                3024)  # https://epsg.io/3018
        )
Example #4
0
 def transform_by_epsg_number(self, target_epsg_number: int) -> CrsCoordinate:
     """
     | Transforms the coordinate to another coordinate reference system
     :param target_epsg_number: the coordinate reference system that you want to transform to
     :return: a coordinate (CrsCoordinate)
     """
     target_crs_projection: CrsProjection = CrsProjection.get_crs_projection_by_epsg_number(target_epsg_number)
     return self.transform(target_crs_projection)
    def transform(self, source_coordinate: CrsCoordinate,
                  target_crs_projection: CrsProjection) -> CrsCoordinate:
        source_coordinate_projection: CrsProjection = source_coordinate.get_crs_projection(
        )
        if (not ((source_coordinate_projection.is_wgs84()) and
                 (target_crs_projection.is_sweref99()
                  or target_crs_projection.is_rt90()))):
            from sweden_crs_transformations.transformation._transformer import _Transformer
            _Transformer._throwExceptionMessage(
                source_coordinate.get_crs_projection(), target_crs_projection)

        gaussKreugerParameterObject = _GaussKreugerParameterObject(
            target_crs_projection)
        gaussKreuger = _GaussKreuger(gaussKreugerParameterObject)
        lat_lon: _LatLon = gaussKreuger.geodetic_to_grid(
            source_coordinate.get_latitude_y(),
            source_coordinate.get_longitude_x())
        return CrsCoordinate.create_coordinate(target_crs_projection,
                                               lat_lon.latitude_y,
                                               lat_lon.longitude_x)
Example #6
0
 def create_coordinate_by_epsg_number(cls,
                                      epsg_number: int,
                                      y_latitude: float,
                                      x_longitude: float
                                      ) -> CrsCoordinate:
     """
     | Factory method for creating an instance.
     :param epsg_number: represents the coordinate reference system that defines the location together with the other two parameters
     :param y_latitude: the coordinate position value representing the latitude or Y or Northing
     :param x_longitude: the coordinate position value representing the longitude or X or Easting
     :return: a coordinate (CrsCoordinate)
     """
     crs_projection: CrsProjection = CrsProjection.get_crs_projection_by_epsg_number(epsg_number)
     return cls.create_coordinate(crs_projection, y_latitude, x_longitude)
    def setUp(self):
        self._wgs84Projections = {CrsProjection.WGS84}

        self._sweref99Projections = {
            CrsProjection.SWEREF_99_12_00, CrsProjection.SWEREF_99_13_30,
            CrsProjection.SWEREF_99_14_15, CrsProjection.SWEREF_99_15_00,
            CrsProjection.SWEREF_99_15_45, CrsProjection.SWEREF_99_16_30,
            CrsProjection.SWEREF_99_17_15, CrsProjection.SWEREF_99_18_00,
            CrsProjection.SWEREF_99_18_45, CrsProjection.SWEREF_99_20_15,
            CrsProjection.SWEREF_99_21_45, CrsProjection.SWEREF_99_23_15,
            CrsProjection.SWEREF_99_TM
        }

        self._rt90Projections = {
            CrsProjection.RT90_0_0_GON_V, CrsProjection.RT90_2_5_GON_O,
            CrsProjection.RT90_2_5_GON_V, CrsProjection.RT90_5_0_GON_O,
            CrsProjection.RT90_5_0_GON_V, CrsProjection.RT90_7_5_GON_V
        }

        self._allCrsProjections: list[
            CrsProjection] = CrsProjection.get_all_crs_projections()
Example #8
0
    def example(self):  # rename this method with test_ prefix as in the above row, if/when you want to execute it
        stockholmWGS84: CrsCoordinate = CrsCoordinate.create_coordinate(
            CrsProjection.WGS84,
            CrsCoordinateTest.stockholmCentralStation_WGS84_latitude,
            CrsCoordinateTest.stockholmCentralStation_WGS84_longitude
        )

        stockholmSweref99tm: CrsCoordinate = stockholmWGS84.transform(CrsProjection.SWEREF_99_TM)
        print(f"stockholmSweref99tm X: {stockholmSweref99tm.get_longitude_x()}")  # Python 3.6+
        print(f"stockholmSweref99tm Y: {stockholmSweref99tm.get_latitude_y()}")
        print(f"stockholmSweref99tm as string: {str(stockholmSweref99tm)}")
        '''
        Output from the above:
        stockholmSweref99tm X: 674032.357
        stockholmSweref99tm Y: 6580821.991
        stockholmSweref99tm as string: CrsCoordinate [ Y: 6580821.991 , X: 674032.357 , CRS: SWEREF_99_TM(EPSG:3006) ]
        '''

        all_projections = CrsProjection.get_all_crs_projections()
        for crs_projection in all_projections:
            print(stockholmWGS84.transform(crs_projection))
        '''
 def test_verify_that_all_projections_can_be_retrieved_by_its_epsg_number(
         self):
     for crsProjection in self._allCrsProjections:
         crsProj: CrsProjection = CrsProjection.get_crs_projection_by_epsg_number(
             crsProjection.get_epsg_number())
         self.assertEqual(crsProjection, crsProj)