Module vector_tile

Source
Expand description

Vector tile coordinate handling and conversions

This module provides functionality for converting between different coordinate systems used in vector tile mapping:

  • WGS84 coordinates (latitude/longitude)
  • Pixel coordinates within tiles
  • Tile coordinates (x, y, zoom)

§Vector Tiles

Vector tiles are square vector images, typically 256×256 pixels, that together create a slippy map. The tile coordinate system:

  • Origin (0,0) is at the top-left corner
  • Tiles are addressed by x, y coordinates and zoom level
  • At zoom level z, the map consists of 2^z × 2^z tiles

§Coordinate Systems

§Tile Coordinates

  • x: Column number from left (0 to 2^zoom - 1)
  • y: Row number from top (0 to 2^zoom - 1)
  • zoom: Detail level (typically 0-20)

§Pixel Coordinates

  • Within each tile: 0 to TILE_SIZE-1 (typically 256)
  • Global: 0 to 2^zoom * TILE_SIZE

§Examples

use toolbox_rs::vector_tile::{degree_to_pixel_lon, degree_to_pixel_lat};
use toolbox_rs::wgs84::{FloatLatitude, FloatLongitude};

// Convert Dresden coordinates to pixels at zoom level 12
let lat = FloatLatitude(51.0504);
let lon = FloatLongitude(13.7373);
let zoom = 12;

let px_x = degree_to_pixel_lon(lon, zoom);
let px_y = degree_to_pixel_lat(lat, zoom);

§Implementation Notes

  • Pixel coordinates increase from west to east (x) and north to south (y)
  • The equator is centered at y = 2^(zoom-1) * TILE_SIZE
  • Greenwich meridian is centered at x = 2^(zoom-1) * TILE_SIZE

Structs§

TileBounds

Functions§

coordinate_to_tile_number
Converts WGS84 coordinates to tile coordinates at a given zoom level
degree_to_pixel_lat
Converts latitude in degrees to pixel y-coordinate
degree_to_pixel_lon
Converts longitude in degrees to pixel x-coordinate
get_tile_bounds
Calculates the WGS84 coordinate bounds of a map tile
linestring_to_tile_coords
Converts WGS84 coordinates to tile-local pixel coordinates
pixel_to_degree
Converts pixel coordinates to degrees