Nodes/Border Distance Mapper/Border Distance Mapper
ComfyUI Node

Border Distance Mapper

Draw a 'how far from the border' map right inside ComfyUI

By GraftingRayman·Created 10 months ago·Updated 10 months ago· 1
Border Distance Mapper
    • world_map
    • buffer_mask
    • city_map
    • city_buffer_mask
    city_nameLondon
    distance_km20000
    image_width2048
    image_height1024
    outline_colorred
    show_countrytrue
    map_styledetailed
    detail_levelhigh
    force_refreshfalse

    Border Distance Mapper does exactly what the name says, no more. Type a city and a distance in kilometers, and it draws a world map with a buffer zone traced around that country's border - plus a matching circle of the same radius around the city itself. It's a tiny, zero-impression novelty node from GraftingRayman, who's a regular over on r/comfyui shipping small utility tools (prompt selectors, generators, LoRA bake/extract). It doesn't generate anything in the diffusion sense; it renders a map. But if you ever want a geographic visualization without leaving the graph - a map to composite into an image workflow, or just to see how much of Europe sits within 500 km of Poland - this is the fastest way to get one.

    How it works

    Under the hood it's three live web lookups plus a cache:

    • Nominatim (OpenStreetMap's geocoder) turns your city name into coordinates and a country code.
    • Overpass API (overpass-api.de) fetches that country's border polygon.
    • Wikimedia Commons supplies an equirectangular world map image as the base.

    Then shapely buffers the country polygon by distance_km / 111 degrees (roughly 111 km per degree) and Pillow draws the outline onto a Mercator-projected image. Note the author's README says "streetmap" - it's OpenStreetMap, not a separate service, and there's no API key anywhere.

    The README warns the first run takes 2–5 minutes: that's the node pulling the entire world's border geometry from Overpass and a big Wikimedia map, then stashing both in custom_nodes/Border-Distance-Mapper/cache/ (world_countries_cache.json plus rendered world_maps/*.png). Every run after that is fast. City lookups still hit Nominatim each time, so it's not fully offline even after the first run.

    The inputs that matter

    Nine inputs, and you'll touch maybe four of them:

    • city_name (default "London") - plain text, no commas needed.
    • distance_km - 1 to 40,000 in steps of 100. This is the radius around the border and the city circle; they share one value.
    • image_width / image_height - 1024–4096 and 512–4096, stepped to multiples of 64. Bigger means the border geometry renders more legibly.
    • outline_color - red, blue, green, yellow, white, black, or orange.
    • The rest (show_country, map_style, detail_level, force_refresh) are cosmetic or cache controls. detail_level (low→ultra) trades download point density for map crispness; you'll feel it mainly on the first run.

    It outputs four images: world_map, buffer_mask, city_map, and city_buffer_mask - all IMAGE tensors. wire world_map anywhere you'd use an image, or feed the masks into a compositor.

    Where people get burned

    The "masks" aren't masks. buffer_mask and city_buffer_mask are RGBA overlays with a 4-pixel colored outline on a transparent background - not filled alpha regions. If you expected a binary region you could feed into inpainting or a ControlNet preprocessor, you'll be disappointed. They composite as a line drawing, which is what you want for a map and not what you want for a mask.

    The distance math is approximate. The buffer is a flat-plane shapely buffer in degrees, not a true geodesic measurement. Fine for eyeballing and mostly accurate at mid latitudes; it drifts noticeably near the poles. Nobody's doing survey work here.

    Dependencies are unshipped. The pack has no requirements.txt, but the code imports scipy and shapely, which aren't part of base ComfyUI. If the node errors on import, install them into ComfyUI's Python (venv or the portable build's python_embeded):

    cd ComfyUI
    ./venv/bin/pip install scipy shapely
    

    force_refresh is a half-truth. The README implies it clears the cache, but it only regenerates the base map PNG. The country-border JSON is reused if it's still on disk. For a genuinely fresh pull, delete the cache/ folder.

    Installing it

    ComfyUI Manager: search "Border Distance Mapper" and hit install. Or manually:

    cd ComfyUI/custom_nodes
    git clone https://github.com/GraftingRayman/Border-Distance-Mapper
    

    Then restart ComfyUI. No model files to download - the only heavy lifting is the first-run web fetch, and the Overpass API can rate-limit you on that first pull. If the map comes back with "No data: [code]" stamped on it, you're probably hitting that; wait a bit and rerun, or use force_refresh. It's a fun little toy with an honest name, and for a zero-impression node the code is surprisingly complete.

    Categoryimage/mapping

    Inputs (9)

    NameTypeDefaultDescription
    city_nameSTRINGLondon
    distance_kmFLOAT200001–40000
    image_widthINT20481024–4096
    image_heightINT1024512–4096
    outline_colorCOMBOred7 options: red, blue, green, yellow, white, black, +1
    show_countryBOOLEANtrue
    map_styleCOMBOdetailed4 options: detailed, simple, minimal, coastline
    detail_levelCOMBOhigh4 options: low, medium, high, ultra
    force_refreshBOOLEANfalse

    Outputs (4)

    NameTypeDescription
    world_mapIMAGE
    buffer_maskIMAGE
    city_mapIMAGE
    city_buffer_maskIMAGE