Пример #1
0
void lat_sistema_fecha(lat_mv * mv) {
	lat_objeto *tiempo = lat_desapilar(mv);
	char *num = __cadena(tiempo);
	time_t raw;
	struct tm *tipo;
	time(&raw);
	tipo = localtime(&raw);
	lat_objeto *tmp = mv->objeto_nulo;
	if (!strcmp(num, "seg")) {
		tmp = lat_numerico_nuevo(mv, tipo->tm_sec);	//segundos
	} else if (!strcmp(num, "min")) {
		tmp = lat_numerico_nuevo(mv, tipo->tm_min);
	} else if (!strcmp(num, "hora")) {
		tmp = lat_numerico_nuevo(mv, tipo->tm_hour);
	} else if (!strcmp(num, "d_mes")) {
		tmp = lat_numerico_nuevo(mv, tipo->tm_mday);	// dia del mes
	} else if (!strcmp(num, "mes")) {
		tmp = lat_numerico_nuevo(mv, tipo->tm_mon);
	} else if (!strcmp(num, "año")) {
		tmp = lat_numerico_nuevo(mv, tipo->tm_year + 1900);
	} else if (!strcmp(num, "d_sem")) {
		tmp = lat_numerico_nuevo(mv, tipo->tm_wday);	// día de la sem.
	} else if (!strcmp(num, "d_año")) {
		tmp = lat_numerico_nuevo(mv, tipo->tm_yday);	// día del año
	} else if (!strcmp(num, "estacion")) {
		tmp = lat_numerico_nuevo(mv, tipo->tm_isdst);	// verano/inv
	} else {
		filename = tiempo->nombre_archivo;
		lat_error("Linea %d, %d: %s", tiempo->num_linea, tiempo->num_columna,
				  "el formato de tiempo indicado no existe.");
	}
	lat_apilar(mv, tmp);
	lat_gc_agregar(mv, tmp);
}
Пример #2
0
//'@title Decode Geohashes
//'@description \code{gh_decode} takes geohashes and turns them back into
//'latitude/longitude pairs, with an associated margin of error for each value.
//'
//'@param hashes a character vector of geohashes.
//'
//'@return a data.frame of four columns; "lat", "lng", "lat_error" and "lng_error"
//'
//'@seealso \code{\link{gh_encode}} for generating geohashes, and
//'\code{\link{gh_neighbours}} for identifying the neighbouring hash boxes
//'to a geohash.
//'
//'@examples
//'# A simple example:
//'gh_encode(lat = 42.60498046875, lng = -5.60302734375, precision = 5)
//'#[1] "ezs42"
//'
//'gh_decode("ezs42")
//'# lat      lng      lat_error  lng_error
//'# 42.60498 -5.603027 0.02197266 0.02197266
//'@export
//[[Rcpp::export]]
DataFrame gh_decode(CharacterVector hashes){

  unsigned int input_size = hashes.size();
  NumericVector lats(input_size);
  NumericVector lngs(input_size);
  NumericVector lat_error(input_size);
  NumericVector lng_error(input_size);
  for(unsigned int i = 0; i < input_size; i++){

    if((i % 10000) == 0){
      Rcpp::checkUserInterrupt();
    }

    if(CharacterVector::is_na(hashes[i])){
      lats[i] = NA_REAL;
      lngs[i] = NA_REAL;
      lat_error[i] = NA_REAL;
      lng_error[i] = NA_REAL;
    } else {
      cgeohash::DecodedHash holding = cgeohash::decode(Rcpp::as<std::string>(hashes[i]));

      lats[i] = holding.latitude;
      lngs[i] = holding.longitude;
      lat_error[i] = holding.latitude_err;
      lng_error[i] = holding.longitude_err;
    }

  }

  return DataFrame::create(_["gh"] = hashes,
                           _["lat"] = lats,
                           _["lng"] = lngs,
                           _["lat_error"] = lat_error,
                           _["lng_error"] = lng_error,
                           _["stringsAsFactors"] = false);
}