Exemple #1
0
        def render(self, name, value, attrs):
            html = super(OpenLayersWidgetLatitudeLongitude,
                         self).render(name, value, attrs)
            # If a string reaches here (via a validation error on another
            # field) then just reconstruct the Geometry.
            if isinstance(value, basestring):
                try:
                    value = GEOSGeometry(value)
                except (GEOSException, ValueError):
                    value = None

            if value and value.geom_type.upper() != self.geom_type:
                value = None

            geom_type = self.params['geom_type']
            if geom_type.name == 'Point':
                value_latitude = (value and value.get_y()) or ''
                value_longitude = (value and value.get_x()) or ''
                latitude = self._emule_widget_django('latitude', _('latitude'),
                                                     name, value_latitude)
                longitude = self._emule_widget_django('longitude',
                                                      _('longitude'), name,
                                                      value_longitude)
                view_on_map = "<input id='view_on_map_%s' class='view_on_map' type='button' value='%s'/>" % (
                    name, _('View on map'))
                return mark_safe("%s %s %s %s" %
                                 (html, latitude, longitude, view_on_map))
            return html
Exemple #2
0
def deg_min_sec(value):
    """
    Usage::

        {{ form.origin_point.value|deg_min_sec }}
    """
    #GEOSGeometry('POINT(-95.3385 29.7245)')

    try:
        point = GEOSGeometry(value)
        x = point.get_x()
        y = point.get_y()
        c=LatLon.LatLon(LatLon.Longitude(x), LatLon.Latitude(y))
        latlon = c.to_string('d% %m% %S% %H')
        lon = latlon[0].split(' ')
        lat = latlon[1].split(' ')

        # need to format float number (seconds) to 1 dp
        lon[2] = str(round(eval(lon[2]), 1))
        lat[2] = str(round(eval(lat[2]), 1))

        # Degrees Minutes Seconds Hemisphere
        lat_str = lat[0] + u'\N{DEGREE SIGN} ' + lat[1].zfill(2) + '\' ' + lat[2].zfill(4) + '\" ' + lat[3]
        lon_str = lon[0] + u'\N{DEGREE SIGN} ' + lon[1].zfill(2) + '\' ' + lon[2].zfill(4) + '\" ' + lon[3]

        return 'Lat/Lon ' + lat_str + ', ' + lon_str
    except:
        return None
Exemple #3
0
def latlon(value):
    """
    Usage::

        {{ form.origin_point.value|latlon }}
    """
    #GEOSGeometry('POINT(-95.3385 29.7245)')

    try:
        point = GEOSGeometry(value)
        x = round(point.get_x(), 2)
        y = round(point.get_y(), 2)
        return '(Lon/Lat) {}/{}'.format(x, y)
    except:
        return None
Exemple #4
0
        def render(self, name, value, attrs):
            html = super(OpenLayersWidgetLatitudeLongitude, self).render(name, value, attrs)
            # If a string reaches here (via a validation error on another
            # field) then just reconstruct the Geometry.
            if isinstance(value, basestring):
                try:
                    value = GEOSGeometry(value)
                except (GEOSException, ValueError):
                    value = None

            if value and value.geom_type.upper() != self.geom_type:
                value = None

            geom_type = self.params['geom_type']
            if geom_type.name == 'Point':
                value_latitude = (value and value.get_y()) or ''
                value_longitude = (value and value.get_x()) or ''
                latitude = self._emule_widget_django('latitude', _('latitude'), name, value_latitude)
                longitude = self._emule_widget_django('longitude', _('longitude'), name, value_longitude)
                view_on_map = "<input id='view_on_map_%s' class='view_on_map' type='button' value='%s'/>" % (name, _('View on map'))
                return mark_safe("%s %s %s %s" % (html, latitude, longitude, view_on_map))
            return html