Beispiel #1
0
def test_WGS84toOSGB36():
    """Test WGS84toOSGB36."""
    lat_long_wgs = np.array([[geo.rad(52, 39, 28.71)], [geo.rad(1, 42,
                                                                57.79)]])
    lat_long_os = np.array([[geo.rad(52, 39, 27.2531)],
                            [geo.rad(1, 43, 4.5177)]])

    assert np.array(geo.WGS84toOSGB36(*lat_long_wgs,
                                      True)) == approx(lat_long_os, rel=1.0e-5)
Beispiel #2
0
    def __init__(self, postcode_file=None, risk_file=None, values_file=None):
        """

        Reads postcode and flood risk files and provides a postcode locator service.

        Parameters
        ---------

        postcode_file : str, optional
            Filename of a .csv file containing geographic location data for postcodes.
        risk_file : str, optional
            Filename of a .csv file containing flood risk data.
        postcode_file : str, optional
            Filename of a .csv file containing property value data for postcodes.
        """
        self.dfp = pd.read_csv(postcode_file)
        self.dff = pd.read_csv(risk_file)
        self.dfc = pd.read_csv(values_file)
        self.dfc['Postcode'] = self.dfc['Postcode'].str.replace(" ", "")
        self.dfp['Postcode'] = self.dfp['Postcode'].str.replace(" ", "")

        lat, lon = geo.WGS84toOSGB36(self.dfp.loc[:, 'Latitude'],
                                     self.dfp.loc[:, 'Longitude'])
        easting, northing = geo.get_easting_northing_from_lat_long(lat, lon)
        self.dfp['Easting'] = easting
        self.dfp['Northing'] = northing
        self.dfp = self.dfp.merge(self.dfc[['Postcode', 'Total Value']],
                                  how='left',
                                  left_on='Postcode',
                                  right_on='Postcode').fillna(0)
        self.dff['Numerical Risk'] = self.dff['prob_4band'].replace(
            ['High', 'Medium', 'Low', 'Very Low'], [4, 3, 2, 1])
        self.dfp['Postcode'] = self.dfp['Postcode'].apply(
            lambda x: x[0:3] + " " + x[3:6] if len(x) == 6 else x)
        self.dfp['Postcode'] = self.dfp['Postcode'].apply(
            lambda x: x[0:2] + "  " + x[4:6] if len(x) == 5 else x)