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 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
        }]
Esempio n. 3
0
    def search(self, google_x, google_y, radius=None):
        "Search by coordinates, return matching items as list of dicts"

        logger.debug("google_x " + str(google_x))
        logger.debug("google_y " + str(google_y))

        rd_point_clicked = Point(*google_to_rd(google_x, google_y))
        if not self.rainapp_config:
            return None

        geo_objects = GeoObject.objects.filter(
            geometry__contains=rd_point_clicked,
            config=self.rainapp_config)

        result = []
        for g in geo_objects:
            maxdate = CompleteRainValue.objects.filter(
                parameterkey=self.parameterkey,
                config=self.rainapp_config).aggregate(
                md=Max('datetime'))['md']

            logger.debug('SEARCH maxdate = '+str(maxdate))

            if maxdate is not None:
                # If there is a maxdate, there must be a value at that date,
                # the import script should take care of that. However,
                # it can be a negative value, which is actually a statuscode.
                maxdate_site_tz = UTC.localize(maxdate).astimezone(self.tz)
                # import pdb;pdb.set_trace()
                value = g.rainvalue_set.get(datetime=maxdate,
                    parameterkey=self.parameterkey).value
                if value > -0.5:
                    popup_text = '%s: %s: %.1f mm' % (
                        g.name,
                        _date(maxdate_site_tz, "j F Y H:i").lower(),
                        value)
                else:
                    popup_text = '%s: %s: Geen data; code %i' % (
                        g.name,
                        _date(maxdate_site_tz, "j F Y H:i").lower(),
                        value)
            else:
                popup_text = '%s (Geen data)' % g.name
            identifier = {
                'location': g.municipality_id,
            }
            result.append({
                'identifier': identifier,
                'distance': 0,
                'workspace_item': self.workspace_item,
                # 'name': g.name + ' (' + str(maxdate) + ')',
                'name': popup_text,
                'shortname': g.name,
                'google_coords': (google_x, google_y),
            })

        return result
Esempio n. 4
0
    def search(self, google_x, google_y, radius=None):
        """Return closest cell.

        What we return is in lizard-map's quite elaborate dict format,
        but the main goal is that we return the identifier: a dict
        with the cell id and the hydro model layer id.  The
        ``.graph()`` and ``.html()`` methods use that identifier data.

        """
        # x, y = coordinates.google_to_rd(google_x, google_y)
        radius = radius * 15
        logger.debug("Searching for cell near %s, %s with radius %s", google_x,
                     google_y, radius)
        # pt = Point(coordinates.rd_to_wgs84(x, y), 4326)
        # pt = Point((google_x, google_y), coordinates.GOOGLE)
        #pt = Point(coordinates.google_to_wgs84(google_x, google_y), 4326)
        pt = Point(coordinates.google_to_rd(google_x, google_y),
                   coordinates.RD)
        logger.debug(pt)
        rls = []
        for rl in Riverline.objects.all().centroid():
            distance = (rl.centroid.x - pt.x)**2 + (rl.centroid.y - pt.y)**2
            distance = distance**0.5
            rl.distance = distance
            rls.append(rl)
        rls.sort(cmp=lambda x, y: cmp(x.distance, y.distance))
        matching_riverlines = rls[:3]

        # matching_riverlines = Riverline.objects.filter(
        #     the_geom__distance_lte=(pt, D(m=radius))).distance(pt).order_by(
        #     'distance')
        logger.debug("Found %s matching riverlines.", len(matching_riverlines))
        for rl in matching_riverlines:
            logger.debug("%s", rl.verbose_code)
        logger.debug("Searching for result data for riverline result %s",
                     self.riverline_result_id)
        riverline_result_datas = RiverlineResultData.objects.filter(
            riverline_result=int(self.riverline_result_id)).filter(
                riverline__in=matching_riverlines)
        logger.debug("%s matching riverlinedata results",
                     riverline_result_datas.count())
        result = []
        for matching_riverline in matching_riverlines:
            for riverline_result_data in riverline_result_datas:
                if not riverline_result_data.riverline == matching_riverline:
                    continue
                result.append({
                    'distance': matching_riverline.distance,
                    'name': 'not used',
                    'workspace_item': self.workspace_item,
                    'identifier': {
                        'riverline_result_data_id': riverline_result_data.id
                    },
                    'google_coords': (google_x, google_y),
                    'object': riverline_result_data
                })
        return result
Esempio n. 5
0
    def search(self, google_x, google_y, radius=None):
        """Return closest cell.

        What we return is in lizard-map's quite elaborate dict format,
        but the main goal is that we return the identifier: a dict
        with the cell id and the hydro model layer id.  The
        ``.graph()`` and ``.html()`` methods use that identifier data.

        """
        # x, y = coordinates.google_to_rd(google_x, google_y)
        radius = radius * 15
        logger.debug("Searching for cell near %s, %s with radius %s",
                     google_x, google_y, radius)
        # pt = Point(coordinates.rd_to_wgs84(x, y), 4326)
        # pt = Point((google_x, google_y), coordinates.GOOGLE)
        #pt = Point(coordinates.google_to_wgs84(google_x, google_y), 4326)
        pt = Point(coordinates.google_to_rd(google_x, google_y), coordinates.RD)
        logger.debug(pt)
        rls = []
        for rl in Riverline.objects.all().centroid():
            distance = (rl.centroid.x - pt.x) ** 2 + (rl.centroid.y - pt.y) ** 2
            distance = distance ** 0.5
            rl.distance = distance
            rls.append(rl)
        rls.sort(cmp=lambda x, y: cmp(x.distance, y.distance))
        matching_riverlines = rls[:3]

        # matching_riverlines = Riverline.objects.filter(
        #     the_geom__distance_lte=(pt, D(m=radius))).distance(pt).order_by(
        #     'distance')
        logger.debug("Found %s matching riverlines.",
                     len(matching_riverlines))
        for rl in matching_riverlines:
            logger.debug("%s", rl.verbose_code)
        logger.debug("Searching for result data for riverline result %s",
                     self.riverline_result_id)
        riverline_result_datas = RiverlineResultData.objects.filter(
            riverline_result=int(self.riverline_result_id)).filter(
            riverline__in=matching_riverlines)
        logger.debug("%s matching riverlinedata results",
                     riverline_result_datas.count())
        result = []
        for matching_riverline in matching_riverlines:
            for riverline_result_data in riverline_result_datas:
                if not riverline_result_data.riverline == matching_riverline:
                    continue
                result.append({'distance': matching_riverline.distance,
                               'name': 'not used',
                               'workspace_item': self.workspace_item,
                               'identifier': {'riverline_result_data_id':
                                                  riverline_result_data.id},
                               'google_coords': (google_x, google_y),
                               'object': riverline_result_data})
        return result
    def search(self, google_x, google_y, radius=None):
        """Return list of dict {'distance': <float>, 'timeserie':
        <timeserie>} of closest fews point that matches x, y, radius.

        """
        x, y = coordinates.google_to_rd(google_x, google_y)
        timeseries_info = self._timeseries()
        for info in timeseries_info:
            info['distance'] = sqrt((info['rd_x'] - x) ** 2 +
                                    (info['rd_y'] - y) ** 2)
        # Filter out correct distances.
        result = []
        for found_result in timeseries_info:
            if found_result['distance'] <= radius * 0.3:
                result.append(found_result)

        result.sort(key=lambda item: item['distance'])
        return result
Esempio n. 7
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)
Esempio n. 8
0
    def search(self, google_x, google_y, radius=None):
        "Search by coordinates, return matching items as list of dicts"

        logger.debug("google_x " + str(google_x))
        logger.debug("google_y " + str(google_y))

        rd_point_clicked = Point(*google_to_rd(google_x, google_y))
        if not self.rainapp_config:
            return None

        geo_objects = GeoObject.objects.filter(
            geometry__contains=rd_point_clicked,
            config=self.rainapp_config)

        result = []
        for g in geo_objects:
            maxdate = CompleteRainValue.objects.filter(
                parameterkey=self.parameterkey,
                config=self.rainapp_config).aggregate(
                md=Max('datetime'))['md']

            logger.debug('SEARCH maxdate = ' + str(maxdate))

            identifier = {
                'location': g.municipality_id,
            }
            result.append({
                'identifier': identifier,
                'distance': 0,
                'workspace_item': self.workspace_item,
                'name': '{}, {}'.format(g.name, self.parameter_name),
                'shortname': g.name,
                'google_coords': (google_x, google_y),
            })

        return result
Esempio n. 9
0
    def search(self, x, y, radius=None):
        """
        """

        pt = Point(coordinates.google_to_rd(x, y), 4326)

        # Looking at how radius is derived in lizard_map.js, it's best applied
        # to the y-coordinate to get a reasonable search distance in meters.

        lon1, lat1 = coordinates.google_to_wgs84(x, y - radius)
        lon2, lat2 = coordinates.google_to_wgs84(x, y + radius)

        # On my computer, a call to Proj() is needed

        pyproj.Proj(init='epsg:4326')

        # before Geod

        geod = pyproj.Geod(ellps='WGS84')

        # Django chrashes with:

        # Rel. 4.7.1, 23 September 2009
        # <(null)>:
        # ellipse setup failure
        # program abnormally terminated

        _forward, _backward, distance = geod.inv(lon1, lat1, lon2, lat2)
        distance /= 2.0

        # Find all profiles within the search distance. Order them by distance.

        results = []

        for location in (Location.objects.
                         filter(project=self.project,
                                the_geom__distance_lte=(pt, D(m=distance))).
                         distance(pt).order_by('distance')):
            if self.measurement_type:
                scheduleds = (ScheduledMeasurement.objects.
                              filter(location=location,
                                     contractor=self.contractor,
                                     measurement_type=self.measurement_type))
            else:
                scheduleds = (ScheduledMeasurement.objects.
                              filter(location=location,
                                     contractor=self.contractor,
                               measurement_type__mtype__can_be_displayed=True).
                              order_by('measurement_type__mtype__name'))

            for scheduled in scheduleds:
                result = {
                    'name': '%s %s %s' % (location.location_code,
                                          scheduled.measurement_type.name,
                                          self.contractor.name),
                    'distance': location.distance.m,
                    'workspace_item': self.workspace_item,
                    'identifier': {
                        'scheduled_measurement_id': scheduled.id,
                        },
                    'grouping_hint': 'lizard_progress %s %s %s %s' % (
                        self.workspace_item.id,
                        self.contractor.slug,
                        self.project.slug,
                        scheduled.measurement_type.slug),
                    }
                results.append(result)
            if results:
                # For now, only show info from one location because
                # our templates don't really work with more yet
                break

        logger.debug("Results=" + str(results))
        return results