Convert to Google's bounds format: 'latMin,lonMin|latMax,lonMax'
977009
def to_google_str(self):
        
        vb = self.convert_srs(4326)
        return '%s,%s|%s,%s' % (vb.bottom, vb.left, vb.top, vb.right)
63392
function(a) {
            this.get('bounds', new google.maps.LatLngBounds()).extend(this._latLng(a));
            this.get('map').fitBounds(this.get('bounds'));
        }
966569
def get_bounding_box(self):
        """"""
        from pyproj import Geod
        geod = Geod(ellps='WGS84')
        dataset_group = DATASET_KEYS[self.datasets[0]]
        idx = 0
        lons_ring = None
        lats_ring = None
        while True:
            path = 'Data_Products/{dataset_group}/{dataset_group}_Gran_{idx}/attr/'
            prefix = path.format(dataset_group=dataset_group, idx=idx)
            try:
                lats = self.file_content[prefix + 'G-Ring_Latitude']
                lons = self.file_content[prefix + 'G-Ring_Longitude']
                if lons_ring is None:
                    lons_ring = lons
                    lats_ring = lats
                else:
                    prev_lon = lons_ring[0]
                    prev_lat = lats_ring[0]
                    dists = list(geod.inv(lon, lat, prev_lon, prev_lat)[2] for lon, lat in zip(lons, lats))
                    first_idx = np.argmin(dists)
                    if first_idx == 2 and len(lons) == 8:
                        lons_ring = np.hstack((lons[:3], lons_ring[:-2], lons[4:]))
                        lats_ring = np.hstack((lats[:3], lats_ring[:-2], lats[4:]))
                    else:
                        raise NotImplementedError("Don't know how to handle G-Rings of length %d" % len(lons))

            except KeyError:
                break
            idx += 1

        return lons_ring, lats_ring
546623
def _format_lat(self, lat):
        '''  '''

        if self.ppd in [4, 8, 16, 32, 64]:
            latcenter = '000N'
        elif self.ppd in [128]:
            if lat < 0:
                latcenter = '450S'
            else:
                latcenter = '450N'

        return latcenter
245225
def area2lonlat(dataarray):
    """"""
    area = dataarray.attrs['area']
    lons, lats = area.get_lonlats_dask()
    lons = xr.DataArray(lons, dims=['y', 'x'],
                        attrs={'name': "longitude",
                               'standard_name': "longitude",
                               'units': 'degrees_east'},
                        name='longitude')
    lats = xr.DataArray(lats, dims=['y', 'x'],
                        attrs={'name': "latitude",
                               'standard_name': "latitude",
                               'units': 'degrees_north'},
                        name='latitude')
    dataarray.attrs['coordinates'] = 'longitude latitude'

    return [dataarray, lons, lats]
1083191
def _format_lat(self, lat):
        '''  '''
        if self.ppd in [4, 16, 64, 128]:
            return None
        else:
            if lat < 0:
                return map(lambda x: "{0:0>2}"
                           .format(int(np.abs(x))) + 'S', self._map_center('lat', lat))
            else:
                return map(lambda x: "{0:0>2}"
                           .format(int(x)) + 'N', self._map_center('lat', lat))
67602
def _expand_coord(self, lat, lon, lmax_calc, degrees):
        """"""
        if self.normalization == '4pi':
            norm = 1
        elif self.normalization == 'schmidt':
            norm = 2
        elif self.normalization == 'unnorm':
            norm = 3
        elif self.normalization == 'ortho':
            norm = 4
        else:
            raise ValueError(
                "Normalization must be '4pi', 'ortho', 'schmidt', or " +
                "'unnorm'. Input value was {:s}"
                .format(repr(self.normalization)))

        if degrees is True:
            latin = lat
            lonin = lon
        else:
            latin = _np.rad2deg(lat)
            lonin = _np.rad2deg(lon)

        if type(lat) is not type(lon):
            raise ValueError('lat and lon must be of the same type. ' +
                             'Input types are {:s} and {:s}'
                             .format(repr(type(lat)), repr(type(lon))))

        if type(lat) is int or type(lat) is float or type(lat) is _np.float_:
            return _shtools.MakeGridPoint(self.coeffs, lat=latin, lon=lonin,
                                          lmax=lmax_calc, norm=norm,
                                          csphase=self.csphase)
        elif type(lat) is _np.ndarray:
            values = _np.empty_like(lat, dtype=float)
            for v, latitude, longitude in _np.nditer([values, latin, lonin],
                                                     op_flags=['readwrite']):
                v[...] = _shtools.MakeGridPoint(self.coeffs, lat=latitude,
                                                lon=longitude,
                                                lmax=lmax_calc, norm=norm,
                                                csphase=self.csphase)
            return values
        elif type(lat) is list:
            values = []
            for latitude, longitude in zip(latin, lonin):
                values.append(
                    _shtools.MakeGridPoint(self.coeffs, lat=latitude,
                                           lon=longitude,
                                           lmax=lmax_calc, norm=norm,
                                           csphase=self.csphase))
            return values
        else:
            raise ValueError('lat and lon must be either an int, float, ' +
                             'ndarray, or list. ' +
                             'Input types are {:s} and {:s}'
                             .format(repr(type(lat)), repr(type(lon))))
155523
function getLetterDesignator(lat) {
        //This is here as an error flag to show that the Latitude is
        //outside MGRS limits
        var LetterDesignator = 'Z';

        if ((84 >= lat) && (lat >= 72)) {
            LetterDesignator = 'X';
        }
        else if ((72 > lat) && (lat >= 64)) {
            LetterDesignator = 'W';
        }
        else if ((64 > lat) && (lat >= 56)) {
            LetterDesignator = 'V';
        }
        else if ((56 > lat) && (lat >= 48)) {
            LetterDesignator = 'U';
        }
        else if ((48 > lat) && (lat >= 40)) {
            LetterDesignator = 'T';
        }
        else if ((40 > lat) && (lat >= 32)) {
            LetterDesignator = 'S';
        }
        else if ((32 > lat) && (lat >= 24)) {
            LetterDesignator = 'R';
        }
        else if ((24 > lat) && (lat >= 16)) {
            LetterDesignator = 'Q';
        }
        else if ((16 > lat) && (lat >= 8)) {
            LetterDesignator = 'P';
        }
        else if ((8 > lat) && (lat >= 0)) {
            LetterDesignator = 'N';
        }
        else if ((0 > lat) && (lat >= -8)) {
            LetterDesignator = 'M';
        }
        else if ((-8 > lat) && (lat >= -16)) {
            LetterDesignator = 'L';
        }
        else if ((-16 > lat) && (lat >= -24)) {
            LetterDesignator = 'K';
        }
        else if ((-24 > lat) && (lat >= -32)) {
            LetterDesignator = 'J';
        }
        else if ((-32 > lat) && (lat >= -40)) {
            LetterDesignator = 'H';
        }
        else if ((-40 > lat) && (lat >= -48)) {
            LetterDesignator = 'G';
        }
        else if ((-48 > lat) && (lat >= -56)) {
            LetterDesignator = 'F';
        }
        else if ((-56 > lat) && (lat >= -64)) {
            LetterDesignator = 'E';
        }
        else if ((-64 > lat) && (lat >= -72)) {
            LetterDesignator = 'D';
        }
        else if ((-72 > lat) && (lat >= -80)) {
            LetterDesignator = 'C';
        }
        return LetterDesignator;
    }
626487
def _UTMLetterDesignator(Lat):
        

        if   84 >= Lat >= 72: return 'X'
        elif 72 >  Lat >= 64: return 'W'
        elif 64 >  Lat >= 56: return 'V'
        elif 56 >  Lat >= 48: return 'U'
        elif 48 >  Lat >= 40: return 'T'
        elif 40 >  Lat >= 32: return 'S'
        elif 32 >  Lat >= 24: return 'R'
        elif 24 >  Lat >= 16: return 'Q'
        elif 16 >  Lat >= 8:  return 'P'
        elif  8 >  Lat >= 0:  return 'N'
        elif  0 >  Lat >=-8:  return 'M'
        elif -8 >  Lat >=-16: return 'L'
        elif -16 > Lat >=-24: return 'K'
        elif -24 > Lat >=-32: return 'J'
        elif -32 > Lat >=-40: return 'H'
        elif -40 > Lat >=-48: return 'G'
        elif -48 > Lat >=-56: return 'F'
        elif -56 > Lat >=-64: return 'E'
        elif -64 > Lat >=-72: return 'D'
        elif -72 > Lat >=-80: return 'C'
        else:                 return 'Z'
634396
def coords_string_parser(self, coords):
        """"""

        lat, lon = coords.split(',')
        return {"lat": lat.strip(), "lon": lon.strip(), "bounds": {}}
1328101
def set_max_decimal_places(doc, max_decimals):
    
    
    def replace_delimited_string_member(
            delimited_str,
            separator,
            index_no,
            decimal_places):
        "Modify the number of decimal places for a delimited string member"
        values = delimited_str.split(separator)
        values[index_no] = str(round(float(values[index_no]), decimal_places))
        return separator.join(values)
    
    if max_decimals.has_key('longitude'):
        data_type = 'longitude'
        index_no = 0 # longitude is in the first position
        # modify <longitude>
        for el in doc.findall(".//{http://www.opengis.net/kml/2.2}longitude"):
            new_val = round(float(el.text), max_decimals[data_type])
            el.getparent().longitude = K.longitude(new_val)
        # modify <coordinates> elements
        for el in doc.findall(".//{http://www.opengis.net/kml/2.2}coordinates"):
            vertex_str_list = []
            for vertex in el.text.strip().split(' '):
                vertex_str_list.append(
                    replace_delimited_string_member(
                        delimited_str=vertex,
                        separator=',',
                        index_no=index_no,
                        decimal_places=max_decimals[data_type]
                    )
                )
            el_new = K.coordinates(' '.join(vertex_str_list).strip())
            el.getparent().replace(el, el_new)
        # modify <gx:coords> elements
        for el in doc.findall(".//{http://www.google.com/kml/ext/2.2}coord"):
            el._setText(
                replace_delimited_string_member(
                    delimited_str=el.text,
                    separator=' ',
                    index_no=index_no,
                    decimal_places=max_decimals[data_type]
                )
            )
    
    if max_decimals.has_key('latitude'):
        data_type = 'latitude'
        index_no = 1 # latitude is in the second position
        # modify <latitude> elements
        for el in doc.findall(".//{http://www.opengis.net/kml/2.2}latitude"):
            new_val = round(float(el.text), max_decimals[data_type])
            el.getparent().latitude = K.latitude(new_val)
        # modify <coordinates> elements
        for el in doc.findall(".//{http://www.opengis.net/kml/2.2}coordinates"):
            vertex_str_list = []
            for vertex in el.text.strip().split(' '):
                vertex_str_list.append(
                    replace_delimited_string_member(
                        delimited_str=vertex,
                        separator=',',
                        index_no=index_no,
                        decimal_places=max_decimals[data_type]
                    )
                )
            el_new = K.coordinates(' '.join(vertex_str_list).strip())
            el.getparent().replace(el, el_new)
        # modify <gx:coords> elements
        for el in doc.findall(".//{http://www.google.com/kml/ext/2.2}coord"):
            el._setText(
                replace_delimited_string_member(
                    delimited_str=el.text,
                    separator=' ',
                    index_no=index_no,
                    decimal_places=max_decimals[data_type]
                )
            )

    if max_decimals.has_key('altitude'):
        data_type = 'altitude'
        index_no = 2 # altitude is in the third position
        # modify <altitude> elements
        for el in doc.findall(".//{http://www.opengis.net/kml/2.2}altitude"):
            new_val = round(float(el.text), max_decimals[data_type])
            el.getparent().altitude = K.altitude(new_val)
        # modify <coordinates> elements
        for el in doc.findall(".//{http://www.opengis.net/kml/2.2}coordinates"):
            vertex_str_list = []
            for vertex in el.text.strip().split(' '):
                vertex_str_list.append(
                    replace_delimited_string_member(
                        delimited_str=vertex,
                        separator=',',
                        index_no=index_no,
                        decimal_places=max_decimals[data_type]
                    )
                )
            el_new = K.coordinates(' '.join(vertex_str_list).strip())
            el.getparent().replace(el, el_new)
        # modify <gx:coords> elements
        for el in doc.findall(".//{http://www.google.com/kml/ext/2.2}coord"):
            el._setText(
                replace_delimited_string_member(
                    delimited_str=el.text,
                    separator=' ',
                    index_no=index_no,
                    decimal_places=max_decimals[data_type]
                )
            )
    
    if max_decimals.has_key('heading'):
        for el in doc.findall(".//{http://www.opengis.net/kml/2.2}heading"):
            new_val = round(float(el.text), max_decimals['heading'])
            el.getparent().heading = K.heading(new_val)
    if max_decimals.has_key('tilt'):
        for el in doc.findall(".//{http://www.opengis.net/kml/2.2}tilt"):
            new_val = round(float(el.text), max_decimals['tilt'])
            el.getparent().tilt = K.tilt(new_val)
    if max_decimals.has_key('range'):
        for el in doc.findall(".//{http://www.opengis.net/kml/2.2}range"):
            new_val = round(float(el.text), max_decimals['range'])
            el.getparent().range = K.range(new_val)
352516
def _parsed_string_to_bounds(date_type, resolution, parsed):
    
    if resolution == 'year':
        return (date_type(parsed.year, 1, 1),
                date_type(parsed.year + 1, 1, 1) - timedelta(microseconds=1))
    elif resolution == 'month':
        if parsed.month == 12:
            end = date_type(parsed.year + 1, 1, 1) - timedelta(microseconds=1)
        else:
            end = (date_type(parsed.year, parsed.month + 1, 1) -
                   timedelta(microseconds=1))
        return date_type(parsed.year, parsed.month, 1), end
    elif resolution == 'day':
        start = date_type(parsed.year, parsed.month, parsed.day)
        return start, start + timedelta(days=1, microseconds=-1)
    elif resolution == 'hour':
        start = date_type(parsed.year, parsed.month, parsed.day, parsed.hour)
        return start, start + timedelta(hours=1, microseconds=-1)
    elif resolution == 'minute':
        start = date_type(parsed.year, parsed.month, parsed.day, parsed.hour,
                          parsed.minute)
        return start, start + timedelta(minutes=1, microseconds=-1)
    elif resolution == 'second':
        start = date_type(parsed.year, parsed.month, parsed.day, parsed.hour,
                          parsed.minute, parsed.second)
        return start, start + timedelta(seconds=1, microseconds=-1)
    else:
        raise KeyError
886016
def _process_out_of_bounds(self, value, start, end):
        ""
        if isinstance(value, np.datetime64):
            v = dt64_to_dt(value)
            if isinstance(start, (int, float)):
                start = convert_timestamp(start)
            if isinstance(end, (int, float)):
                end = convert_timestamp(end)
            s, e = start, end
            if isinstance(s, np.datetime64):
                s = dt64_to_dt(s)
            if isinstance(e, np.datetime64):
                e = dt64_to_dt(e)
        else:
            v, s, e = value, start, end

        if v < s:
            value = start
        elif v > e:
            value = end

        return value
165507
function(bounds) {
        var res = this.getServerResolution();
        var x = Math.round((bounds.left - this.maxExtent.left) /
            (res * this.tileSize.w));
        var y = Math.round((this.maxExtent.top - bounds.top) /
            (res * this.tileSize.h));
        var z = this.getServerZoom();

        if (this.wrapDateLine) {
            var limit = Math.pow(2, z);
            x = ((x % limit) + limit) % limit;
        }

        return {'x': x, 'y': y, 'z': z};
    }
319298
def get_bounding_box(self):
        
        return (np.min(self.data["longitude"]),
                np.max(self.data["longitude"]),
                np.min(self.data["latitude"]),
                np.max(self.data["latitude"]))
181724
function(data) {
        var toLat = coordinate.format(data.to.lat, 'lat');
        var toLon = coordinate.format(data.to.lon, 'lon');

        var parts = ["IIRMB",
            "A",
            data.xte.toFixed(2),
            data.dts,
            data.to.name,
            data.from.name,
            toLat[0],
            toLat[1],
            toLon[0],
            toLon[1],
            data.dtw.toFixed(1),
            data.btw.toFixed(0),
            data.vmgw.toFixed(2),
            'V'
        ];

        return parts.join(',');
    }
562636
function parse_lat_lon(obj, lat_field, lon_field) {
  if ([lat_field, lon_field].every(_.has.bind(null, obj))) {
    return { latitude: obj[lat_field], longitude: obj[lon_field] };
  }
}