// Overlay test suite
void test_rsat1_overlay(void)
{
  c2v_config *cfg = read_c2v_config("rsat1/overlay/rsat1_overlay.cfg");
  CU_ASSERT_TRUE(convert2vector(cfg));
  FREE(cfg);
  cu_difftext("rsat1/overlay/test_overlay.kml", 
	      "rsat1/overlay/R163749163U1S001.kml",
	      "rsat1/overlay/test_except.lst");
}
Exemple #2
0
int open_google_earth()
{
    char *kml_filename = appendExt(curr->filename, ".kml");

    char *basename = get_basename(curr->filename);
    char *dirname = get_dirname(curr->filename);

    char *arg;
    if (strlen(dirname)==0) {
        char *tmpdir = g_get_current_dir();
        dirname = escapify(tmpdir);
        arg = MALLOC(sizeof(char)*(strlen(dirname)+strlen(kml_filename)+20));
        sprintf(arg, "%s/%s", dirname, kml_filename);
        //free(tmpdir);
    }
    else {
        arg = STRDUP(kml_filename);
    }

    char *png_file = appendExt(arg, ".png");

    printf("png file: %s\n", png_file);
    printf("Temporary kml file: %s\n", arg);

    FILE *kml_file = fopen(arg, "w");
    if (!kml_file)
    {
        asfPrintWarning("Couldn't open kml file!\n");        
        return FALSE;
    }

    dbf_header_t *dbf;
    int nAttr, nCoords;
    double *lat, *lon, center_lat, center_lon;
    char configFile[255], *name;
    meta_parameters *meta;

    sprintf(configFile, "%s/convert2vector.config", get_asf_share_dir());
    c2v_config *cfg = read_c2v_config(configFile);

    kml_header(kml_file);

    meta = meta2vector(curr->filename, &dbf, &nAttr, &lat, &lon, &nCoords);
    //meta_parameters *meta = curr->meta;
    if (meta && meta->general &&
        meta_is_valid_double(meta->general->center_latitude) &&
        meta_is_valid_double(meta->general->center_longitude))
    {
        pixbuf2png(pixbuf_small, png_file);
        //kml_entry_with_overlay(kml_file, meta, basename, png_file, dirname);
        name = get_basename(kml_filename);
        center_lat = meta->general->center_latitude;
        center_lon = meta->general->center_longitude;
        write_kml_placemark(kml_file, name, center_lat, center_lon, png_file, 
          dbf, nAttr, lat, lon, nCoords, cfg);
        FREE(lat);
        FREE(lon);
        FREE(dbf);
    }
    else
    {
        asfPrintWarning(
            "Failed, metadata doesn't contain valid lat/lon info.\n");
        return FALSE;
    }

    kml_footer(kml_file);
    fclose(kml_file);

    gchar *ge;

    printf("kml: %s\n", kml_filename);
    printf("dir: %s\n", dirname);

#ifdef win32
    char path[1024];
    FindExecutable((LPCTSTR)kml_filename, (LPCTSTR)dirname, (LPTSTR)path);
    ge = escapify(path);
    printf("Path to google earth: %s\n", ge);
    
    asfSystem("\"%s\" \"%s\"", ge, arg);
#else
    ge = find_in_path("googleearth");
    if (!ge)
    {
       message_box("Couldn't find googleearth! Is it installed?");
       return FALSE;
    }

    int pid = fork();
    if (pid == 0) {
        asfSystem("\"%s\" \"%s\"", ge, arg);
        //unlink(kml_filename);
        exit(EXIT_SUCCESS);
    }
#endif

    free(kml_filename);
    free(basename);
    free(dirname);
    free(arg);

    return TRUE;
}
int main(int argc, char **argv)
{
  char inFormat[25], outFormat[25], configFile[255];
  int currArg = 1, NUM_ARGS = 1, configFlag = FALSE;
  c2v_config *cfg=NULL;

  if (argc < 3) {
    usage(argv[0]);
    exit(1);
  }
    
  // Check for configuration file option first
  while (currArg < (argc-NUM_ARGS)) {
    char *key = argv[currArg++];
    if (strmatches(key, "-help", "--help", NULL)) {
      usage(argv[0]);
      char format[25], data_dictionary[512];
      CHECK_ARG(1);
      strcpy(format, GET_ARG(1));
      sprintf(data_dictionary, "%s%c%s_data_dictionary.csv", 
        get_asf_share_dir(), DIR_SEPARATOR, format);
      if (fileExists(data_dictionary)) {
        asfPrintStatus("\nFormat defined in %s_data_dictionary.csv\n\n", 
        format);
        catFile(data_dictionary);
        asfPrintStatus("\n\n");
      }
      else
        asfPrintWarning("Could not find a data dictionary for format (%s)!\n\n", 
          format);
      exit(1);
    }
    else if (strmatches(key, "-config", "--config", "-c", NULL)) {
      CHECK_ARG(1);
      strcpy(configFile, GET_ARG(1));
      cfg = read_c2v_config(configFile);
      configFlag = TRUE;
    }
  }
  if (!configFlag) {
    sprintf(configFile, "%s%cconvert2vector.config", 
      get_asf_share_dir(), DIR_SEPARATOR);
    asfPrintStatus("\nReading parameters from default configuration file:\n"
		   "%s\n", configFile);
    cfg = read_c2v_config(configFile);
  }

  // Pick up the rest of the arguments
  currArg = 1;
  NUM_ARGS = 2;
  while (currArg < (argc-NUM_ARGS)) {
    char *key = argv[currArg++];
    if (strmatches(key, "-config", "--config", "-c", NULL)) { ; }
    else if (strmatches(key, "-log", "--log", NULL)) {
      CHECK_ARG(1);
      strcpy(logFile,GET_ARG(1));
      fLog = FOPEN(logFile, "a");
      logflag = TRUE;
    }
    else if (strmatches(key, "-quiet", "--quiet", "-q", NULL))
      quietflag = TRUE;
    else if (strmatches(key, "-list", "--list", NULL))
      cfg->list = TRUE;
    else if (strmatches(key, "-nosplit", "--nosplit", "-ns", NULL))
      cfg->nosplit = TRUE;
    else if (strmatches(key, "-input-format", "--input-format", "-i", NULL)) {
      CHECK_ARG(1);
      strcpy(cfg->input_format, GET_ARG(1));
    }
    else if (strmatches(key, "-output-format", "--output-format", "-o", NULL)) {
      CHECK_ARG(1);
      strcpy(cfg->output_format, GET_ARG(1));
    }
    else {
      --currArg;
      break;
    }
  }
  if ((argc-currArg) < NUM_ARGS) {
    printf("Insufficient arguments.\n");
    usage(argv[0]);
  }

  if (!configFlag) {
    sprintf(cfg->input_file, "%s", argv[currArg++]);
    sprintf(cfg->output_file, "%s", argv[currArg]);
  }

  asfSplashScreen (argc, argv);

  sprintf(inFormat, "%s", uc(cfg->input_format));
  sprintf(outFormat, "%s", uc(cfg->output_format));
  
  // Check whether you can find information about the format in the header
  // list file in the share directory
  dbf_header_t *dbf;
  int nCols;
  char shape_type[25];
  if (strcmp_case(inFormat, "CSV") == 0 ||
    read_header_config(inFormat, &dbf, &nCols, shape_type))
    asfPrintStatus("   Converting a %s format file to %s\n", 
      inFormat, outFormat);
  else
    asfPrintError("   Unsupported input format (%s)\n", inFormat);
  
  // Set output directory as the temporary directory -- where all temp files
  // created during import should be put
  char *tmpdir = get_dirname(cfg->output_file);
  if (tmpdir && strlen(tmpdir) > 0)
    set_asf_tmp_dir(tmpdir);

  convert2vector(cfg);

  asfPrintStatus("Done.\n\n");

  return(0);
}