def test_translates_to_rd(self, patched_wgs84):
     with self.settings(
         COMPOSITE_EXTENT=(0, 200, 200, 0),
         COMPOSITE_CELLSIZE=(100, 100),
         COMPOSITE_CELLS=(2, 2)):
         projections.coordinate_to_composite_pixel(10, 10)
     patched_wgs84.assert_called_with(10, 10)
Example #2
0
    def extent_for_user(cls, user):
        if not user.is_authenticated():
            return None

        if user.has_perm('lizard_neerslagradar.view_entire_region'):
            # Setting these to None leads to entire extent being set below
            # Usually only superuser will have the permission
            topleft = bottomright = None
        else:
            regions = user.region_set.all()
            if not regions:
                return None

            wgs84extents = [region.geometry.extent for region in regions]

            extents = [{
                    'left': xmin,
                    'bottom': ymin,
                    'right': xmax,
                    'top': ymax
                    } for xmin, ymin, xmax, ymax in wgs84extents]

            extent = {
                'left': min(extent['left'] for extent in extents),
                'bottom': min(extent['bottom'] for extent in extents),
                'right': max(extent['right'] for extent in extents),
                'top': max(extent['top'] for extent in extents)
                }

            # Now we want to translate the topleft and bottomright to
            # grid cells, and use their topleft and bottomright as the
            # _actual_ extent, so that it will contain whole grid
            # cells.
            topleft = projections.coordinate_to_composite_pixel(
                extent['left'], extent['top'])
            bottomright = (
                projections.coordinate_to_composite_pixel(
                    extent['right'], extent['bottom']))

        if topleft is None:
            topleft = (0, 0)
        if bottomright is None:
            cells_x, cells_y = settings.COMPOSITE_CELLS
            bottomright = (cells_x - 1, cells_y - 1)

        left, top = projections.topleft_of_composite_pixel(
            *topleft, to_projection=coordinates.google_projection)
        right, bottom = projections.bottomright_of_composite_pixel(
            *bottomright, to_projection=coordinates.google_projection)

        return {
            'left': str(left),
            'bottom':  str(bottom),
            'right': str(right),
            'top': str(top)
            }
Example #3
0
    def extent_for_user(cls, user):
        if not user.is_authenticated():
            return None

        regions = user.region_set.all()
        if not regions:
            return None

        wgs84extents = [region.geometry.extent for region in regions]

        extents = [{
                'left': xmin,
                'bottom': ymin,
                'right': xmax,
                'top': ymax
                } for xmin, ymin, xmax, ymax in wgs84extents]

        extent = {
            'left': min(extent['left'] for extent in extents),
            'bottom': min(extent['bottom'] for extent in extents),
            'right': max(extent['right'] for extent in extents),
            'top': max(extent['top'] for extent in extents)
            }

        # Now we want to translate the topleft and bottomright to grid cells,
        # and use their topleft and bottomright as the _actual_ extent, so that
        # it will contain whole grid cells.
        topleft = projections.coordinate_to_composite_pixel(
            extent['left'], extent['top'])
        bottomright = (
            projections.coordinate_to_composite_pixel(
                extent['right'], extent['bottom']))

        if topleft is None:
            topleft = (0, 0)
        if bottomright is None:
            cells_x, cells_y = settings.COMPOSITE_CELLS
            bottomright = (cells_x - 1, cells_y - 1)

        left, top = projections.topleft_of_composite_pixel(
            *topleft, to_projection=coordinates.google_projection)
        right, bottom = projections.bottomright_of_composite_pixel(
            *bottomright, to_projection=coordinates.google_projection)

        return {
            'left': str(left),
            'bottom':  str(bottom),
            'right': str(right),
            'top': str(top)
            }
    def search(self, google_x, google_y, radius=None):
        if not self._user_has_access(google_x, google_y):
            return []

        lon, lat = coordinates.google_to_wgs84(google_x, google_y)
        rd_x, rd_y = coordinates.google_to_rd(google_x, google_y)

        region = models.Region.find_by_point((lon, lat), user=self._user())
        pixel = projections.coordinate_to_composite_pixel(lon, lat)

        if region is None or pixel is None:
            logger.debug("Region is None or pixel is None.")
            return []

        name = self._grid_name(region.name, pixel)

        return [{
            'distance': 0,
            'name': name,
            'shortname': name,
            'workspace_item': self.workspace_item,
            'identifier': {
                'identifier': pixel,
                'region_name': region.name,
                'google_coords': (google_x, google_y),
            },
            'google_coords': (google_x, google_y),
            'object': None
        }]
 def test_x_outside_grid_returns_none(self, patched_wgs84):
     with self.settings(
         COMPOSITE_EXTENT=(0, 200, 200, 0),
         COMPOSITE_CELLSIZE=(100, 100),
         COMPOSITE_CELLS=(2, 2)):
         result = projections.coordinate_to_composite_pixel(10, 10)
     self.assertEquals(result, None)
    def search(self, google_x, google_y, radius=None):
        if not self._user_has_access(google_x, google_y):
            return []

        lon, lat = coordinates.google_to_wgs84(google_x, google_y)
        rd_x, rd_y = coordinates.google_to_rd(google_x, google_y)

        region = models.Region.find_by_point((lon, lat), user=self._user())
        pixel = projections.coordinate_to_composite_pixel(lon, lat)

        if region is None or pixel is None:
            logger.debug("Region is None or pixel is None.")
            return []

        name = self._grid_name(region.name, pixel)

        return [{
            'distance': 0,
            'name': name,
            'shortname': name,
            'workspace_item': self.workspace_item,
            'identifier': {
                'identifier': pixel,
                'region_name': region.name,
                'google_coords': (google_x, google_y),
            },
            'google_coords': (google_x, google_y),
            'object': None
        }]
    def test_returns_correct_cell(self, patched_wgs84):
        with self.settings(COMPOSITE_EXTENT=(0, 200, 200, 0),
                           COMPOSITE_CELLSIZE=(100, 100),
                           COMPOSITE_CELLS=(2, 2)):
            x, y = projections.coordinate_to_composite_pixel(10, 10)

        self.assertEquals(x, 1)
        self.assertEquals(y, 1)
    def test_returns_correct_cell(self, patched_wgs84):
        with self.settings(
            COMPOSITE_EXTENT=(0, 200, 200, 0),
            COMPOSITE_CELLSIZE=(100, 100)):
            x, y = projections.coordinate_to_composite_pixel(10, 10)

        self.assertEquals(x, 1)
        self.assertEquals(y, 1)
    def search(self, google_x, google_y, radius=None):
        lon, lat = coordinates.google_to_wgs84(google_x, google_y)

        region = models.Region.find_by_point((lon, lat))
        pixel = projections.coordinate_to_composite_pixel(lon, lat)

        if region is None or pixel is None:
            logger.debug("Region is None or pixel is None.")
            return []

        name = "{0}, cel ({1} {2})".format(region, *pixel)

        return [
            {
                "distance": 0,
                "name": name,
                "shortname": name,
                "workspace_item": self.workspace_item,
                "identifier": {"identifier": pixel, "region_name": region.name},
                "google_coords": (google_x, google_y),
                "object": None,
            }
        ]
 def test_x_outside_grid_returns_none(self, patched_wgs84):
     with self.settings(COMPOSITE_EXTENT=(0, 200, 200, 0),
                        COMPOSITE_CELLSIZE=(100, 100),
                        COMPOSITE_CELLS=(2, 2)):
         result = projections.coordinate_to_composite_pixel(10, 10)
     self.assertEquals(result, None)
 def test_translates_to_rd(self, patched_wgs84):
     with self.settings(COMPOSITE_EXTENT=(0, 200, 200, 0),
                        COMPOSITE_CELLSIZE=(100, 100),
                        COMPOSITE_CELLS=(2, 2)):
         projections.coordinate_to_composite_pixel(10, 10)
     patched_wgs84.assert_called_with(10, 10)