예제 #1
0
/**
 * http://en.wikipedia.org/wiki/World_file
 *
 * Note world files do not define the units and nor are the units standardized :(
 * Currently Viking only supports:
 *  x&y scale as meters per pixel
 *  x&y coords as UTM eastings and northings respectively
 */
static gint world_file_read_file ( const gchar* filename, gdouble values[4] )
{
  g_debug ("%s - trying world file %s", __FUNCTION__, filename);

  FILE *f = g_fopen ( filename, "r" );
  if ( !f )
    return 1;
  else {
    gint answer = 2; // Not enough info read yet
    // **We do not handle 'skew' values ATM - normally they are a value of 0 anyway to align with the UTM grid
    if ( world_file_read_line ( f, &values[0], TRUE ) // x scale
      && world_file_read_line ( f, NULL, FALSE ) // Ignore value in y-skew line**
      && world_file_read_line ( f, NULL, FALSE ) // Ignore value in x-skew line**
      && world_file_read_line ( f, &values[1], TRUE ) // y scale
      && world_file_read_line ( f, &values[2], TRUE ) // x-coordinate of the upper left pixel
      && world_file_read_line ( f, &values[3], TRUE ) // y-coordinate of the upper left pixel
       )
    {
       // Success
       g_debug ("%s - %s - world file read success", __FUNCTION__, filename);
       answer = 0;
    }
    fclose ( f );
    return answer;
  }
}
예제 #2
0
static void georef_layer_dialog_load ( GtkWidget *pass_along[4] )
{
  GtkWidget *file_selector = gtk_file_chooser_dialog_new (_("Choose World file"),
				      NULL,
				      GTK_FILE_CHOOSER_ACTION_OPEN,
				      GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
				      GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
				      NULL);

  if ( gtk_dialog_run ( GTK_DIALOG ( file_selector ) ) == GTK_RESPONSE_ACCEPT )
  {
    FILE *f = g_fopen ( gtk_file_chooser_get_filename ( GTK_FILE_CHOOSER(file_selector) ), "r" );
    gtk_widget_destroy ( file_selector ); 
    if ( !f )
    {
      a_dialog_error_msg ( VIK_GTK_WINDOW_FROM_WIDGET(pass_along[0]), _("The World file you requested could not be opened for reading.") );
      return;
    }
    else
    {
      gchar *buffer = g_malloc ( 1024 * sizeof(gchar) );
      if ( world_file_read_line ( buffer, 1024, f, pass_along[0], TRUE ) && world_file_read_line ( buffer, 1024, f, pass_along[0], FALSE)
        && world_file_read_line ( buffer, 1024, f, pass_along[0], FALSE ) && world_file_read_line ( buffer, 1024, f, pass_along[1], TRUE)
        && world_file_read_line ( buffer, 1024, f, pass_along[2], TRUE ) && world_file_read_line ( buffer, 1024, f, pass_along[3], TRUE ) )
      {
        g_free ( buffer );
        fclose ( f );
	f = NULL;
      }
    }
  }
  else
    gtk_widget_destroy ( file_selector ); 
/* do your jazz
We need a
  file selection dialog
  file opener for reading, if NULL, send error_msg ( VIK_GTK_WINDOW_FROM_WIDGET(pass_along[0]) )
  does that catch directories too?
  read lines -- if not enough lines, give error.
  if anything outside, give error. define range with #define CONSTANTS
  put 'em in thar widgets, and that's it.
*/
}