コード例 #1
0
/**
 * For each track - mark whether the start is in within the viewport
 */
static void set_in_current_view_property ( VikTrwLayer *vtl, datasource_osm_my_traces_t *data, GList *gl )
{
    gdouble min_lat, max_lat, min_lon, max_lon;
    /* get Viewport bounding box */
    vik_viewport_get_min_max_lat_lon ( data->vvp, &min_lat, &max_lat, &min_lon, &max_lon );

    LatLonBBox bbox;
    bbox.north = max_lat;
    bbox.east = max_lon;
    bbox.south = min_lat;
    bbox.west = min_lon;

    GList *iterator = gl;
    while ( iterator ) {
        gpx_meta_data_t* gmd = (gpx_meta_data_t*)iterator->data;
        // Convert point position into a 'fake' bounding box
        // TODO - probably should have function to see if point is within bounding box
        //   rather than constructing this fake bounding box for the test
        LatLonBBox gmd_bbox;
        gmd_bbox.north = gmd->ll.lat;
        gmd_bbox.east = gmd->ll.lon;
        gmd_bbox.south = gmd->ll.lat;
        gmd_bbox.west = gmd->ll.lon;

        if ( BBOX_INTERSECT ( bbox, gmd_bbox ) )
            gmd->in_current_view = TRUE;

        iterator = g_list_next ( iterator );
    }
}
コード例 #2
0
ファイル: datasource_osm.c プロジェクト: gdt/viking
static void datasource_osm_get_cmd_string ( datasource_osm_widgets_t *widgets, gchar **cmd, gchar **input_file_type, DownloadMapOptions *options )
{
  int page = 0;
  gdouble min_lat, max_lat, min_lon, max_lon;
  gchar sminlon[G_ASCII_DTOSTR_BUF_SIZE];
  gchar smaxlon[G_ASCII_DTOSTR_BUF_SIZE];
  gchar sminlat[G_ASCII_DTOSTR_BUF_SIZE];
  gchar smaxlat[G_ASCII_DTOSTR_BUF_SIZE];

  /* get Viewport bounding box */
  vik_viewport_get_min_max_lat_lon ( widgets->vvp, &min_lat, &max_lat, &min_lon, &max_lon );

  /* Convert as LANG=C double representation */
  g_ascii_dtostr (sminlon, G_ASCII_DTOSTR_BUF_SIZE, min_lon);
  g_ascii_dtostr (smaxlon, G_ASCII_DTOSTR_BUF_SIZE, max_lon);
  g_ascii_dtostr (sminlat, G_ASCII_DTOSTR_BUF_SIZE, min_lat);
  g_ascii_dtostr (smaxlat, G_ASCII_DTOSTR_BUF_SIZE, max_lat);

  /* Retrieve the specified page number */
  last_page_number = gtk_spin_button_get_value(GTK_SPIN_BUTTON(widgets->page_number));
  page = last_page_number;

  *cmd = g_strdup_printf( DOWNLOAD_URL_FMT, sminlon, sminlat, smaxlon, smaxlat, page );
  *input_file_type = NULL;
  options = NULL;
}
コード例 #3
0
ファイル: datasource_osm.c プロジェクト: viking-gps/viking
static void datasource_osm_get_process_options ( datasource_osm_widgets_t *widgets, ProcessOptions *po, DownloadFileOptions *options, const gchar *notused1, const gchar *notused2)
{
  int page = 0;
  gdouble min_lat, max_lat, min_lon, max_lon;
  gchar sminlon[G_ASCII_DTOSTR_BUF_SIZE];
  gchar smaxlon[G_ASCII_DTOSTR_BUF_SIZE];
  gchar sminlat[G_ASCII_DTOSTR_BUF_SIZE];
  gchar smaxlat[G_ASCII_DTOSTR_BUF_SIZE];

  /* get Viewport bounding box */
  vik_viewport_get_min_max_lat_lon ( widgets->vvp, &min_lat, &max_lat, &min_lon, &max_lon );

  /* Convert as LANG=C double representation */
  g_ascii_dtostr (sminlon, G_ASCII_DTOSTR_BUF_SIZE, min_lon);
  g_ascii_dtostr (smaxlon, G_ASCII_DTOSTR_BUF_SIZE, max_lon);
  g_ascii_dtostr (sminlat, G_ASCII_DTOSTR_BUF_SIZE, min_lat);
  g_ascii_dtostr (smaxlat, G_ASCII_DTOSTR_BUF_SIZE, max_lat);

  /* Retrieve the specified page number */
  last_page_number = gtk_spin_button_get_value(GTK_SPIN_BUTTON(widgets->page_number));
  page = last_page_number;

  // NB Download is of GPX type
  po->url = g_strdup_printf( DOWNLOAD_URL_FMT, sminlon, sminlat, smaxlon, smaxlat, page );
  options = NULL; // i.e. use the default download settings
}
コード例 #4
0
/* TODO: generalize */
static void dem24k_draw_existence ( VikViewport *vp )
{
  gdouble max_lat, max_lon, min_lat, min_lon;  
  gchar buf[strlen(MAPS_CACHE_DIR)+40];
  gdouble i, j;

  vik_viewport_get_min_max_lat_lon ( vp, &min_lat, &max_lat, &min_lon, &max_lon );

  for (i = floor(min_lat*8)/8; i <= floor(max_lat*8)/8; i+=0.125) {
    /* check lat dir first -- faster */
    g_snprintf(buf, sizeof(buf), "%sdem24k/%d/",
        MAPS_CACHE_DIR,
	(gint) i );
    if ( g_file_test(buf, G_FILE_TEST_EXISTS) == FALSE )
      continue;
    for (j = floor(min_lon*8)/8; j <= floor(max_lon*8)/8; j+=0.125) {
      /* check lon dir first -- faster */
      g_snprintf(buf, sizeof(buf), "%sdem24k/%d/%d/",
        MAPS_CACHE_DIR,
	(gint) i,
        (gint) j );
      if ( g_file_test(buf, G_FILE_TEST_EXISTS) == FALSE )
        continue;
      g_snprintf(buf, sizeof(buf), "%sdem24k/%d/%d/%.03f,%.03f.dem",
	        MAPS_CACHE_DIR,
		(gint) i,
		(gint) j,
		floor(i*8)/8,
		floor(j*8)/8 );
      if ( g_file_test(buf, G_FILE_TEST_EXISTS ) == TRUE ) {
        VikCoord ne, sw;
        gint x1, y1, x2, y2;
        sw.north_south = i;
        sw.east_west = j-0.125;
        sw.mode = VIK_COORD_LATLON;
        ne.north_south = i+0.125;
        ne.east_west = j;
        ne.mode = VIK_COORD_LATLON;
        vik_viewport_coord_to_screen ( vp, &sw, &x1, &y1 );
        vik_viewport_coord_to_screen ( vp, &ne, &x2, &y2 );
        if ( x1 < 0 ) x1 = 0;
        if ( y2 < 0 ) y2 = 0;
        vik_viewport_draw_rectangle ( vp, gtk_widget_get_style(GTK_WIDGET(vp))->black_gc,
		FALSE, x1, y2, x2-x1, y1-y2 );
      }
    }
  }
}
コード例 #5
0
/* TODO: generalize */
static void srtm_draw_existence ( VikViewport *vp )
{
  gdouble max_lat, max_lon, min_lat, min_lon;  
  gchar buf[strlen(MAPS_CACHE_DIR)+strlen(SRTM_CACHE_TEMPLATE)+30];
  gint i, j;

  vik_viewport_get_min_max_lat_lon ( vp, &min_lat, &max_lat, &min_lon, &max_lon );

  for (i = floor(min_lat); i <= floor(max_lat); i++) {
    for (j = floor(min_lon); j <= floor(max_lon); j++) {
      const gchar *continent_dir;
      if ((continent_dir = srtm_continent_dir(i, j)) == NULL)
        continue;
      g_snprintf(buf, sizeof(buf), SRTM_CACHE_TEMPLATE,
                MAPS_CACHE_DIR,
                continent_dir,
                G_DIR_SEPARATOR_S,
		(i >= 0) ? 'N' : 'S',
		ABS(i),
		(j >= 0) ? 'E' : 'W',
		ABS(j) );
      if ( g_file_test(buf, G_FILE_TEST_EXISTS ) == TRUE ) {
        VikCoord ne, sw;
        gint x1, y1, x2, y2;
        sw.north_south = i;
        sw.east_west = j;
        sw.mode = VIK_COORD_LATLON;
        ne.north_south = i+1;
        ne.east_west = j+1;
        ne.mode = VIK_COORD_LATLON;
        vik_viewport_coord_to_screen ( vp, &sw, &x1, &y1 );
        vik_viewport_coord_to_screen ( vp, &ne, &x2, &y2 );
        if ( x1 < 0 ) x1 = 0;
        if ( y2 < 0 ) y2 = 0;
        vik_viewport_draw_rectangle ( vp, gtk_widget_get_style(GTK_WIDGET(vp))->black_gc,
		FALSE, x1, y2, x2-x1, y1-y2 );
      }
    }
  }
}
コード例 #6
0
static void vik_dem_layer_draw_dem ( VikDEMLayer *vdl, VikViewport *vp, VikDEM *dem )
{
  VikDEMColumn *column, *prevcolumn, *nextcolumn;

  struct LatLon dem_northeast, dem_southwest;
  gdouble max_lat, max_lon, min_lat, min_lon;

  /**** Check if viewport and DEM data overlap ****/

  /* get min, max lat/lon of viewport */
  vik_viewport_get_min_max_lat_lon ( vp, &min_lat, &max_lat, &min_lon, &max_lon );

  /* get min, max lat/lon of DEM data */
  if ( dem->horiz_units == VIK_DEM_HORIZ_LL_ARCSECONDS ) {
    dem_northeast.lat = dem->max_north / 3600.0;
    dem_northeast.lon = dem->max_east / 3600.0;
    dem_southwest.lat = dem->min_north / 3600.0;
    dem_southwest.lon = dem->min_east / 3600.0;
  } else if ( dem->horiz_units == VIK_DEM_HORIZ_UTM_METERS ) {
    struct UTM dem_northeast_utm, dem_southwest_utm;
    dem_northeast_utm.northing = dem->max_north;
    dem_northeast_utm.easting = dem->max_east;
    dem_southwest_utm.northing = dem->min_north;
    dem_southwest_utm.easting = dem->min_east;
    dem_northeast_utm.zone = dem_southwest_utm.zone = dem->utm_zone;
    dem_northeast_utm.letter = dem_southwest_utm.letter = dem->utm_letter;

    a_coords_utm_to_latlon(&dem_northeast_utm, &dem_northeast);
    a_coords_utm_to_latlon(&dem_southwest_utm, &dem_southwest);
  }

  if ( (max_lat > dem_northeast.lat && min_lat > dem_northeast.lat) ||
       (max_lat < dem_southwest.lat && min_lat < dem_southwest.lat) )
    return;
  else if ( (max_lon > dem_northeast.lon && min_lon > dem_northeast.lon) ||
            (max_lon < dem_southwest.lon && min_lon < dem_southwest.lon) )
    return;
  /* else they overlap */

  /**** End Overlap Check ****/
  /* boxes to show where we have DEM instead of actually drawing the DEM.
   * useful if we want to see what areas we have coverage for (if we want
   * to get elevation data for a track) but don't want to cover the map.
   */

  #if 0
  /* draw a box if a DEM is loaded. in future I'd like to add an option for this
   * this is useful if we want to see what areas we have dem for but don't want to
   * cover the map (or maybe we just need translucent DEM?) */
  {
    VikCoord demne, demsw;
    gint x1, y1, x2, y2;
    vik_coord_load_from_latlon(&demne, vik_viewport_get_coord_mode(vp), &dem_northeast);
    vik_coord_load_from_latlon(&demsw, vik_viewport_get_coord_mode(vp), &dem_southwest);

    vik_viewport_coord_to_screen ( vp, &demne, &x1, &y1 );
    vik_viewport_coord_to_screen ( vp, &demsw, &x2, &y2 );

    if ( x1 > vik_viewport_get_width(vp) ) x1=vik_viewport_get_width(vp);
    if ( y2 > vik_viewport_get_height(vp) ) y2=vik_viewport_get_height(vp);
    if ( x2 < 0 ) x2 = 0;
    if ( y1 < 0 ) y1 = 0;
    vik_viewport_draw_rectangle ( vp, gtk_widget_get_style(GTK_WIDGET(vp))->black_gc,
	FALSE, x2, y1, x1-x2, y2-y1 );
    return;
  }
  #endif

  if ( dem->horiz_units == VIK_DEM_HORIZ_LL_ARCSECONDS ) {
    VikCoord tmp; /* TODO: don't use coord_load_from_latlon, especially if in latlon drawing mode */

    gdouble max_lat_as, max_lon_as, min_lat_as, min_lon_as;  
    gdouble start_lat_as, end_lat_as, start_lon_as, end_lon_as;

    gdouble start_lat, end_lat, start_lon, end_lon;

    struct LatLon counter;

    guint x, y, start_x, start_y;

    gint16 elev;

    guint skip_factor = ceil ( vik_viewport_get_xmpp(vp) / 80 ); /* todo: smarter calculation. */

    gdouble nscale_deg = dem->north_scale / ((gdouble) 3600);
    gdouble escale_deg = dem->east_scale / ((gdouble) 3600);

    max_lat_as = max_lat * 3600;
    min_lat_as = min_lat * 3600;
    max_lon_as = max_lon * 3600;
    min_lon_as = min_lon * 3600;

    start_lat_as = MAX(min_lat_as, dem->min_north);
    end_lat_as   = MIN(max_lat_as, dem->max_north);
    start_lon_as = MAX(min_lon_as, dem->min_east);
    end_lon_as   = MIN(max_lon_as, dem->max_east);

    start_lat = floor(start_lat_as / dem->north_scale) * nscale_deg;
    end_lat   = ceil (end_lat_as / dem->north_scale) * nscale_deg;
    start_lon = floor(start_lon_as / dem->east_scale) * escale_deg;
    end_lon   = ceil (end_lon_as / dem->east_scale) * escale_deg;

    vik_dem_east_north_to_xy ( dem, start_lon_as, start_lat_as, &start_x, &start_y );
    guint gradient_skip_factor = 1;
    if(vdl->type == DEM_TYPE_GRADIENT)
	    gradient_skip_factor = skip_factor;

    /* verify sane elev interval */
    if ( vdl->max_elev <= vdl->min_elev )
      vdl->max_elev = vdl->min_elev + 1;

    for ( x=start_x, counter.lon = start_lon; counter.lon <= end_lon+escale_deg*skip_factor; counter.lon += escale_deg * skip_factor, x += skip_factor ) {
      // NOTE: ( counter.lon <= end_lon + ESCALE_DEG*SKIP_FACTOR ) is neccessary so in high zoom modes,
      // the leftmost column does also get drawn, if the center point is out of viewport.
      if ( x < dem->n_columns ) {
        column = g_ptr_array_index ( dem->columns, x );
        // get previous and next column. catch out-of-bound.
	gint32 new_x = x;
	new_x -= gradient_skip_factor;
        if(new_x < 1)
          prevcolumn = g_ptr_array_index ( dem->columns, x+1);
        else
          prevcolumn = g_ptr_array_index ( dem->columns, new_x);
	new_x = x;
	new_x += gradient_skip_factor;
        if(new_x >= dem->n_columns)
          nextcolumn = g_ptr_array_index ( dem->columns, x-1);
        else
          nextcolumn = g_ptr_array_index ( dem->columns, new_x);

        for ( y=start_y, counter.lat = start_lat; counter.lat <= end_lat; counter.lat += nscale_deg * skip_factor, y += skip_factor ) {
          if ( y > column->n_points )
            break;

          elev = column->points[y];

	  // calculate bounding box for drawing
	  gint box_x, box_y, box_width, box_height;
	  struct LatLon box_c;
	  box_c = counter;
	  box_c.lat += (nscale_deg * skip_factor)/2;
          box_c.lon -= (escale_deg * skip_factor)/2;
	  vik_coord_load_from_latlon(&tmp, vik_viewport_get_coord_mode(vp), &box_c);
	  vik_viewport_coord_to_screen(vp, &tmp, &box_x, &box_y);
	  // catch box at borders
	  if(box_x < 0)
	          box_x = 0;
	  if(box_y < 0)
	          box_y = 0;
          box_c.lat -= nscale_deg * skip_factor;
	  box_c.lon += escale_deg * skip_factor;
	  vik_coord_load_from_latlon(&tmp, vik_viewport_get_coord_mode(vp), &box_c);
	  vik_viewport_coord_to_screen(vp, &tmp, &box_width, &box_height);
	  box_width -= box_x;
	  box_height -= box_y;
          // catch box at borders
	  if(box_width < 0 || box_height < 0)
		  continue; // skip this. this is out of our viewport anyway. FIXME: why?

	  gboolean below_minimum = FALSE;
          if(vdl->type == DEM_TYPE_HEIGHT) {
            if ( elev != VIK_DEM_INVALID_ELEVATION && elev < vdl->min_elev ) {
              // Prevent 'elev - vdl->min_elev' from being negative so can safely use as array index
              elev = ceil ( vdl->min_elev );
	      below_minimum = TRUE;
	    }
            if ( elev != VIK_DEM_INVALID_ELEVATION && elev > vdl->max_elev )
              elev = vdl->max_elev;
          }

          {
	    if(box_width < 0 || box_height < 0) // FIXME: why does this happen?
              continue;

            if(vdl->type == DEM_TYPE_GRADIENT) {
              if( elev == VIK_DEM_INVALID_ELEVATION ) {
                /* don't draw it */
              } else {
                // calculate and sum gradient in all directions
                gint16 change = 0;
		gint32 new_y;

		// calculate gradient from height points all around the current one
		new_y = y - gradient_skip_factor;
		if(new_y < 0)
			new_y = y;
		change += get_height_difference(elev, prevcolumn->points[new_y]);
		change += get_height_difference(elev, column->points[new_y]);
		change += get_height_difference(elev, nextcolumn->points[new_y]);

		change += get_height_difference(elev, prevcolumn->points[y]);
		change += get_height_difference(elev, nextcolumn->points[y]);

		new_y = y + gradient_skip_factor;
		if(new_y >= column->n_points)
			new_y = y;
		change += get_height_difference(elev, prevcolumn->points[new_y]);
		change += get_height_difference(elev, column->points[new_y]);
		change += get_height_difference(elev, nextcolumn->points[new_y]);

		change = change / ((skip_factor > 1) ? log(skip_factor) : 0.55); // FIXME: better calc.

                if(change < vdl->min_elev)
                  // Prevent 'change - vdl->min_elev' from being negative so can safely use as array index
                  change = ceil ( vdl->min_elev );

                if(change > vdl->max_elev)
                  change = vdl->max_elev;

                // void vik_viewport_draw_rectangle ( VikViewport *vvp, GdkGC *gc, gboolean filled, gint x1, gint y1, gint x2, gint y2 );
                vik_viewport_draw_rectangle(vp, vdl->gcsgradient[(gint)floor(((change - vdl->min_elev)/(vdl->max_elev - vdl->min_elev))*(DEM_N_GRADIENT_COLORS-2))+1], TRUE, box_x, box_y, box_width, box_height);
              }
            } else {
              if(vdl->type == DEM_TYPE_HEIGHT) {
                if ( elev == VIK_DEM_INVALID_ELEVATION )
                  ; /* don't draw it */
                else if ( elev <= 0 || below_minimum )
		  /* If 'sea' colour or below the defined mininum draw in the configurable colour */
                  vik_viewport_draw_rectangle(vp, vdl->gcs[0], TRUE, box_x, box_y, box_width, box_height);
                else
                  vik_viewport_draw_rectangle(vp, vdl->gcs[(gint)floor(((elev - vdl->min_elev)/(vdl->max_elev - vdl->min_elev))*(DEM_N_HEIGHT_COLORS-2))+1], TRUE, box_x, box_y, box_width, box_height);
              }
            }
          }
        } /* for y= */
      }
    } /* for x= */
  } else if ( dem->horiz_units == VIK_DEM_HORIZ_UTM_METERS ) {
    gdouble max_nor, max_eas, min_nor, min_eas;
    gdouble start_nor, start_eas, end_nor, end_eas;

    gint16 elev;

    guint x, y, start_x, start_y;

    VikCoord tmp; /* TODO: don't use coord_load_from_latlon, especially if in latlon drawing mode */
    struct UTM counter;

    guint skip_factor = ceil ( vik_viewport_get_xmpp(vp) / 10 ); /* todo: smarter calculation. */

    VikCoord tleft, tright, bleft, bright;

    vik_viewport_screen_to_coord ( vp, 0, 0, &tleft );
    vik_viewport_screen_to_coord ( vp, vik_viewport_get_width(vp), 0, &tright );
    vik_viewport_screen_to_coord ( vp, 0, vik_viewport_get_height(vp), &bleft );
    vik_viewport_screen_to_coord ( vp, vik_viewport_get_width(vp), vik_viewport_get_height(vp), &bright );


    vik_coord_convert(&tleft, VIK_COORD_UTM);
    vik_coord_convert(&tright, VIK_COORD_UTM);
    vik_coord_convert(&bleft, VIK_COORD_UTM);
    vik_coord_convert(&bright, VIK_COORD_UTM);

    max_nor = MAX(tleft.north_south, tright.north_south);
    min_nor = MIN(bleft.north_south, bright.north_south);
    max_eas = MAX(bright.east_west, tright.east_west);
    min_eas = MIN(bleft.east_west, tleft.east_west);

    start_nor = MAX(min_nor, dem->min_north);
    end_nor   = MIN(max_nor, dem->max_north);
    if ( tleft.utm_zone == dem->utm_zone && bleft.utm_zone == dem->utm_zone
         && (tleft.utm_letter >= 'N') == (dem->utm_letter >= 'N')
         && (bleft.utm_letter >= 'N') == (dem->utm_letter >= 'N') ) /* if the utm zones/hemispheres are different, min_eas will be bogus */
      start_eas = MAX(min_eas, dem->min_east);
    else
      start_eas = dem->min_east;
    if ( tright.utm_zone == dem->utm_zone && bright.utm_zone == dem->utm_zone
         && (tright.utm_letter >= 'N') == (dem->utm_letter >= 'N')
         && (bright.utm_letter >= 'N') == (dem->utm_letter >= 'N') ) /* if the utm zones/hemispheres are different, min_eas will be bogus */
      end_eas = MIN(max_eas, dem->max_east);
    else
      end_eas = dem->max_east;

    start_nor = floor(start_nor / dem->north_scale) * dem->north_scale;
    end_nor   = ceil (end_nor / dem->north_scale) * dem->north_scale;
    start_eas = floor(start_eas / dem->east_scale) * dem->east_scale;
    end_eas   = ceil (end_eas / dem->east_scale) * dem->east_scale;

    vik_dem_east_north_to_xy ( dem, start_eas, start_nor, &start_x, &start_y );

    /* TODO: why start_x and start_y are -1 -- rounding error from above? */

    counter.zone = dem->utm_zone;
    counter.letter = dem->utm_letter;

    for ( x=start_x, counter.easting = start_eas; counter.easting <= end_eas; counter.easting += dem->east_scale * skip_factor, x += skip_factor ) {
      if ( x > 0 && x < dem->n_columns ) {
        column = g_ptr_array_index ( dem->columns, x );
        for ( y=start_y, counter.northing = start_nor; counter.northing <= end_nor; counter.northing += dem->north_scale * skip_factor, y += skip_factor ) {
          if ( y > column->n_points )
            continue;
          elev = column->points[y];
          if ( elev != VIK_DEM_INVALID_ELEVATION && elev < vdl->min_elev )
            elev=vdl->min_elev;
          if ( elev != VIK_DEM_INVALID_ELEVATION && elev > vdl->max_elev )
            elev=vdl->max_elev;

          {
            gint a, b;
            vik_coord_load_from_utm(&tmp, vik_viewport_get_coord_mode(vp), &counter);
	            vik_viewport_coord_to_screen(vp, &tmp, &a, &b);
            if ( elev == VIK_DEM_INVALID_ELEVATION )
              ; /* don't draw it */
            else if ( elev <= 0 )
              vik_viewport_draw_rectangle(vp, vdl->gcs[0], TRUE, a-1, b-1, 2, 2 );
            else
              vik_viewport_draw_rectangle(vp, vdl->gcs[(gint)floor((elev - vdl->min_elev)/(vdl->max_elev - vdl->min_elev)*(DEM_N_HEIGHT_COLORS-2))+1], TRUE, a-1, b-1, 2, 2 );
          }
        } /* for y= */
      }
    } /* for x= */
  }
}