Exemplo n.º 1
0
def google_extent_from_geotransform(shape, rd_geotransform):
    minx, miny, maxx, maxy = extent_geotransform(shape, rd_geotransform)

    wgs84_nw = rd_to_wgs84(minx, maxy)
    wgs84_se = rd_to_wgs84(maxx, miny)

    return {"north": wgs84_nw[1], "west": wgs84_nw[0], "south": wgs84_se[1], "east": wgs84_se[0]}
Exemplo n.º 2
0
    def extent(self, identifiers=None):
        "Return the extent in Google projection"
        north = None
        south = None
        east = None
        west = None
        wgs0coord_x, wgs0coord_y = coordinates.rd_to_wgs84(0.0, 0.0)
        for point in self.measurement.points.all():
            x = point.location.x
            y = point.location.y
            if (abs(x - wgs0coord_x) > EPSILON or
                abs(y - wgs0coord_y) > EPSILON):

                if x > east or east is None:
                    east = x
                if x < west or west is None:
                    west = x
                if y < south or south is None:
                    south = y
                if y > north or north is None:
                    north = y
        if north is None:
            logger.warn("Data points are all at (0, 0) RD, cannot calculate "
                        "extent!")
            return

        west_transformed, north_transformed = coordinates.wgs84_to_google(
            west, north)
        east_transformed, south_transformed = coordinates.wgs84_to_google(
            east, south)
        return  {
            'north': north_transformed,
            'west': west_transformed,
            'south': south_transformed,
            'east': east_transformed}
Exemplo n.º 3
0
    def extent(self, identifiers=None):
        """Return extent."""
        north = None
        south = None
        east = None
        west = None

        wgs0coord_x, wgs0coord_y = coordinates.rd_to_wgs84(0.0, 0.0)
        for info in self._timeseries():
            x = info['rd_x']
            y = info['rd_y']
            # Ignore rd coordinates (0, 0).
            if (abs(x - wgs0coord_x) > EPSILON or
                abs(y - wgs0coord_y) > EPSILON):

                if x > east or east is None:
                    east = x
                if x < west or west is None:
                    west = x
                if y < south or south is None:
                    south = y
                if y > north or north is None:
                    north = y

        west_transformed, north_transformed = coordinates.rd_to_google(
            west, north)
        east_transformed, south_transformed = coordinates.rd_to_google(
            east, south)
        return {
            'north': north_transformed,
            'west': west_transformed,
            'south': south_transformed,
            'east': east_transformed}
Exemplo n.º 4
0
    def extent(self, identifiers=None):
        """
        TODO: filter on identifiers.
        """
        cache_key = 'extent:{}:{}:{}'.format(self.jdbc_source_slug,
                                             self.filterkey, self.parameterkey)
        result = cache.get(cache_key)
        if not result:
            logger.debug("Started calculating extent")
            north = None
            south = None
            east = None
            west = None
            named_locations = self._locations()
            wgs0coord_x, wgs0coord_y = coordinates.rd_to_wgs84(0.0, 0.0)

            for named_location in named_locations:
                x = named_location['longitude']
                y = named_location['latitude']
                # Ignore rd coordinates (0, 0).
                if (abs(x - wgs0coord_x) > EPSILON or
                        abs(y - wgs0coord_y) > EPSILON):

                    if x > east or east is None:
                        east = x
                    if x < west or west is None:
                        west = x
                    if y < south or south is None:
                        south = y
                    if y > north or north is None:
                        north = y
                else:
                    logger.warn("Location (%s, %s) at RD coordinates 0,0",
                                named_location['location'],
                                named_location['locationid'])
            west_transformed, north_transformed = coordinates.wgs84_to_google(
                west, north)
            east_transformed, south_transformed = coordinates.wgs84_to_google(
                east, south)
            logger.debug("Finished calculating extent")

            result = {
                'north': north_transformed,
                'west': west_transformed,
                'south': south_transformed,
                'east': east_transformed}
            cache.set(cache_key, result, 60 * 30)
        return result
Exemplo n.º 5
0
    def post(self, request, *args, **kwargs):
        post = request.POST
        message_list = ["result: ", ]
        try:
            google_x = float(post['google_x'])
            google_y = float(post['google_y'])
            c_rd = coordinates.google_to_rd(google_x, google_y)
            message_list.append('Google (%s, %s) = RD (%s, %s)' % (
                    google_x, google_y, c_rd[0], c_rd[1]))
            c_wgs84 = coordinates.google_to_wgs84(google_x, google_y)
            message_list.append('Google (%s, %s) = WGS84 (%s, %s)' % (
                    google_x, google_y, c_wgs84[0], c_wgs84[1]))
        except:
            pass

        try:
            rd_x = float(post['rd_x'])
            rd_y = float(post['rd_y'])
            c_google = coordinates.rd_to_google(rd_x, rd_y)
            message_list.append('RD (%s, %s) = Google (%s, %s)' % (
                    rd_x, rd_y, c_google[0], c_google[1]))
            c_wgs84 = coordinates.rd_to_wgs84(rd_x, rd_y)
            message_list.append('RD (%s, %s) = WGS84 (%s, %s)' % (
                    rd_x, rd_y, c_wgs84[0], c_wgs84[1]))
        except:
            pass

        try:
            wgs84_x = float(post['wgs84_x'])
            wgs84_y = float(post['wgs84_y'])
            c_google = coordinates.wgs84_to_google(wgs84_x, wgs84_y)
            message_list.append('WGS84 (%s, %s) = Google (%s, %s)' % (
                    wgs84_x, wgs84_y, c_google[0], c_google[1]))
            c_rd = coordinates.wgs84_to_rd(wgs84_x, wgs84_y)
            message_list.append('WGS84 (%s, %s) = RD (%s, %s)' % (
                    wgs84_x, wgs84_y, c_rd[0], c_rd[1]))
        except:
            pass

        self.message = '<br/>'.join(message_list)
        return super(ConvertView, self).get(request, *args, **kwargs)