% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/export.R
\name{export_topojson}
\alias{export_topojson}
\title{Export an exploded map as TopoJSON}
\usage{
export_topojson(x, file, simplify = NULL, overwrite = FALSE)
}
\arguments{
\item{x}{An \code{sf}, \code{exploded_map}, or \code{grouped_exploded_map} object.
For \code{exploded_map} objects, the WGS84 exploded geometry (\code{sf_exp_wgs})
is exported. For \code{grouped_exploded_map} objects, the WGS84 grouped
geometry (\code{sf_grouped_wgs}) is exported.}

\item{file}{Output file path. Should end in \code{.topojson} or \code{.json}.}

\item{simplify}{Optional simplification proportion passed to
\code{mapshaper -simplify}. Must be a single number between 0 and 1
(exclusive). For example, \code{simplify = 0.5} retains 50\% of vertices.
Default is \code{NULL} (no simplification). Note that simplification
modifies polygon geometry and therefore breaks the exact geometry
preservation guarantee of Proposition 1.}

\item{overwrite}{Logical; if \code{TRUE}, overwrite \code{file} if it already
exists. Default is \code{FALSE}.}
}
\value{
Invisibly returns the output file path.
}
\description{
Converts an \code{sf}, \code{exploded_map}, or \code{grouped_exploded_map} object to
TopoJSON using the external \code{mapshaper} command-line tool. The input is
first written as a temporary GeoJSON file, then converted by mapshaper.
}
\details{
This is intended as a convenience helper for downstream tools such as
Power BI, D3.js, and Observable that prefer or require TopoJSON input.

This function requires the external \code{mapshaper} command-line tool to be
installed and available on the system path. It can be installed with:

\preformatted{npm install -g mapshaper}

The \code{mapshaper} tool is not an R package dependency; it is invoked via
\code{system2()}. If mapshaper is not found, the function errors with an
informative message.
}
\examples{
\dontrun{
# Two-level export
result <- explode_sf(my_sf, region_col = "region", plot = FALSE)
export_topojson(result, "exploded.topojson")

# Three-level grouped export
grp <- explode_grouped(my_sf, region_col = "region", plot = FALSE)
export_topojson(grp, "grouped.topojson")

# With simplification (breaks Proposition 1 guarantee)
export_topojson(result, "simplified.topojson", simplify = 0.5)

# Raw sf object
export_topojson(my_sf, "raw.topojson", overwrite = TRUE)
}

}
