Documentation
¶
Overview ¶
Package gismanager publishes GIS data files (shapefile, GeoJSON, GeoPackage, KML) to PostGIS, then exposes the resulting tables as GeoServer feature types via the geoserver/v2 REST client.
Index ¶
- Variables
- func BuildVRT(ctx context.Context, dst string, srcs []string, opts ...VRTOption) error
- func ConvertRaster(ctx context.Context, src, dst string, opts ...RasterConvertOption) error
- func ConvertVector(ctx context.Context, src, dst string, opts ...VectorConvertOption) error
- func DBIsAlive(dbType string, connectionStr string) errordeprecated
- func DBIsAliveContext(ctx context.Context, dbType string, connectionStr string) (err error)
- func DEMProcessing(ctx context.Context, src, dst, mode string, opts ...DEMOption) error
- func GetGISFiles(root string) ([]string, error)
- func GetLogger() *slog.Logger
- func Rasterize(ctx context.Context, vectorSrc, rasterDst string, opts ...RasterizeOption) error
- func ReprojectRaster(ctx context.Context, src, dst, srcSRS, dstSRS string, ...) error
- func ToCOG(ctx context.Context, src, dst string, opts ...RasterConvertOption) error
- func ToPMTiles(ctx context.Context, src, dst string, opts ...PMTilesOption) error
- type DEMOption
- func WithDEMAlgorithm(alg string) DEMOption
- func WithDEMAltitude(degrees float64) DEMOption
- func WithDEMAzimuth(degrees float64) DEMOption
- func WithDEMColorFile(path string) DEMOption
- func WithDEMCombined() DEMOption
- func WithDEMCreationOption(key, val string) DEMOption
- func WithDEMFormat(driver string) DEMOption
- func WithDEMLogger(l *slog.Logger) DEMOption
- func WithDEMMultidirectional() DEMOption
- func WithDEMOutputType(t string) DEMOption
- func WithDEMRawOptions(args ...string) DEMOption
- func WithDEMScale(s float64) DEMOption
- func WithDEMZFactor(z float64) DEMOption
- type DatastoreConfig
- type GISError
- type GdalLayer
- func (layer *GdalLayer) Features(ctx context.Context) iter.Seq[gdal.Feature]
- func (layer *GdalLayer) GeometryName() string
- func (layer *GdalLayer) GetFeatures() (features []*gdal.Feature)deprecated
- func (layer *GdalLayer) GetGeomtryName() stringdeprecated
- func (layer *GdalLayer) GetLayerSchema() (fields []*LayerField)
- func (layer *GdalLayer) LayerToPostgis(targetSource *gdal.DataSource, manager *ManagerConfig, overwrite bool) (newLayer *GdalLayer, err error)
- type GeoserverConfig
- type LayerField
- type ManagerConfig
- func (manager *ManagerConfig) GetDriver(path string) (driver gdal.OGRDriver, err error)
- func (manager *ManagerConfig) GetGeoserverCatalog() (*geoserver.Client, error)
- func (manager *ManagerConfig) NewLayer(l *gdal.Layer) *GdalLayer
- func (manager *ManagerConfig) OpenSource(_ context.Context, path string, access int) (*gdal.DataSource, error)
- func (manager *ManagerConfig) PublishAll(ctx context.Context) error
- func (manager *ManagerConfig) PublishGeoserverLayer(ctx context.Context, layer *GdalLayer) error
- func (c *ManagerConfig) Validate() error
- func (manager *ManagerConfig) Walk(ctx context.Context) iter.Seq2[WalkItem, error]
- type Option
- type PMTilesOption
- type RasterConvertOption
- func WithRasterBands(bands ...int) RasterConvertOption
- func WithRasterCreationOption(key, val string) RasterConvertOption
- func WithRasterCutline(ds, layer string) RasterConvertOption
- func WithRasterFormat(driver string) RasterConvertOption
- func WithRasterLogger(l *slog.Logger) RasterConvertOption
- func WithRasterOutputBounds(minX, minY, maxX, maxY float64) RasterConvertOption
- func WithRasterRawOptions(args ...string) RasterConvertOption
- func WithRasterResamplingAlg(alg string) RasterConvertOption
- func WithRasterTargetResolution(xRes, yRes float64) RasterConvertOption
- type RasterizeOption
- func WithRasterizeAttribute(name string) RasterizeOption
- func WithRasterizeBurnValues(values ...float64) RasterizeOption
- func WithRasterizeCreationOption(key, val string) RasterizeOption
- func WithRasterizeFormat(driver string) RasterizeOption
- func WithRasterizeLayer(name string) RasterizeOption
- func WithRasterizeLogger(l *slog.Logger) RasterizeOption
- func WithRasterizeOutputBounds(minX, minY, maxX, maxY float64) RasterizeOption
- func WithRasterizeOutputSize(xSize, ySize int) RasterizeOption
- func WithRasterizeOutputType(t string) RasterizeOption
- func WithRasterizeRawOptions(args ...string) RasterizeOption
- func WithRasterizeTargetResolution(xRes, yRes float64) RasterizeOption
- func WithRasterizeWhere(sql string) RasterizeOption
- type SourceConfig
- type VRTOption
- func WithVRTAddAlpha() VRTOption
- func WithVRTAllowProjectionDifference() VRTOption
- func WithVRTBands(bands ...int) VRTOption
- func WithVRTHideNoData() VRTOption
- func WithVRTLogger(l *slog.Logger) VRTOption
- func WithVRTNoData(values string) VRTOption
- func WithVRTRawOptions(args ...string) VRTOption
- func WithVRTResamplingAlg(alg string) VRTOption
- func WithVRTResolution(mode string) VRTOption
- func WithVRTSeparate() VRTOption
- func WithVRTSrcNoData(values string) VRTOption
- func WithVRTUserResolution(xRes, yRes float64) VRTOption
- type VectorConvertOption
- func WithVectorBoundingBox(minX, minY, maxX, maxY float64) VectorConvertOption
- func WithVectorFormat(driverName string) VectorConvertOption
- func WithVectorLayerName(name string) VectorConvertOption
- func WithVectorLogger(l *slog.Logger) VectorConvertOption
- func WithVectorOverwrite() VectorConvertOption
- func WithVectorRawOptions(args ...string) VectorConvertOption
- func WithVectorSelectFields(fields ...string) VectorConvertOption
- func WithVectorSimplify(tolerance float64) VectorConvertOption
- func WithVectorSourceSRS(srs string) VectorConvertOption
- func WithVectorTargetSRS(srs string) VectorConvertOption
- func WithVectorWhere(sql string) VectorConvertOption
- type WalkItem
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrConfigInvalid signals that the YAML config is syntactically valid // but semantically wrong (missing fields, malformed values, etc.). ErrConfigInvalid = errors.New("gismanager: config invalid") // ErrUnsupportedFormat signals that a path's extension does not map to // any GDAL OGR driver gismanager knows about. ErrUnsupportedFormat = errors.New("gismanager: unsupported format") // ErrInvalidLayer signals that a *GdalLayer was nil or had a nil // embedded *gdal.Layer pointer when an operation required a real layer. ErrInvalidLayer = errors.New("gismanager: invalid layer") // ErrInvalidDatasource signals that a *gdal.DataSource passed in was // nil or unusable. ErrInvalidDatasource = errors.New("gismanager: invalid datasource") // ErrPostGISConnect signals that the PostGIS ping/handshake failed. // The underlying *pq.Error (or driver-level error) is recoverable via // [errors.As]. ErrPostGISConnect = errors.New("gismanager: postgis connect") // ErrGeoServerPublish signals that the GeoServer publish flow failed // at workspace, datastore, or feature-type creation. The underlying // *geoserver.APIError is recoverable via [errors.As]. ErrGeoServerPublish = errors.New("gismanager: geoserver publish") // ErrNoSourcesFound signals that the configured source directory // contained no supported GIS files. ErrNoSourcesFound = errors.New("gismanager: no sources found") // ErrConvertFailed signals that a vector or raster conversion // (ConvertVector / ConvertRaster / ToCOG / ReprojectRaster) failed. // The underlying GDAL error is recoverable via [errors.As] into // [*GISError]; the GISError.Op field disambiguates which entry // point produced the error. ErrConvertFailed = errors.New("gismanager: convert failed") )
Sentinel errors. Match via errors.Is — never compare error strings.
These wrap higher-level failure categories. The library wraps them around the underlying cause (GDAL CGo error, *geoserver.APIError, lib/pq error, etc.) so callers can branch on the category while still recovering the original via errors.As.
Functions ¶
func BuildVRT ¶ added in v1.3.0
BuildVRT composes one or more raster inputs into a Virtual Raster (VRT) at dst. Thin wrapper around the GDAL C entry point behind `gdalbuildvrt` (gdal.BuildVRT).
Use cases: assemble a tile pyramid from many individual GeoTIFFs; stack single-band inputs into RGBA via WithVRTSeparate; build a multi-resolution mosaic for downstream `Warp` / `Translate` calls.
At least one source path is required. Each path is opened with `gdal.OpenEx(OFRaster|OFReadOnly)` and closed when BuildVRT returns.
Errors are wrapped with ErrConvertFailed; recover via errors.As into *GISError. The Op field is "BuildVRT".
Example ¶
ExampleBuildVRT demonstrates assembling several rasters into a single Virtual Raster (the gdalbuildvrt equivalent). Useful for presenting tile pyramids or stacking single-band inputs with WithVRTSeparate.
package main
import (
"context"
"fmt"
"github.com/lukeroth/gdal"
"github.com/hishamkaram/gismanager"
)
func main() {
src1 := "/vsimem/example_buildvrt_a.tif"
src2 := "/vsimem/example_buildvrt_b.tif"
dst := "/vsimem/example_buildvrt.vrt"
driver, _ := gdal.GetDriverByName("GTiff")
for _, p := range []string{src1, src2} {
ds := driver.Create(p, 16, 16, 1, gdal.Byte, nil)
ds.SetGeoTransform([6]float64{0, 1, 0, 16, 0, -1})
ds.Close()
}
if err := gismanager.BuildVRT(context.Background(), dst,
[]string{src1, src2},
); err != nil {
fmt.Println("error:", err)
return
}
fmt.Println("ok")
}
Output: ok
func ConvertRaster ¶ added in v1.2.0
func ConvertRaster(ctx context.Context, src, dst string, opts ...RasterConvertOption) error
ConvertRaster converts the raster source at src into dst, applying any of the provided options. It is a thin wrapper around the C entry point behind `gdal_translate` (gdal.Translate) — every option maps 1:1 to a gdal_translate CLI flag.
Use cases:
- GeoTIFF → COG (prefer ToCOG for sane defaults).
- GeoTIFF → PNG / JPEG for web previews.
- Subset bands or extract a window.
For reprojection use ReprojectRaster instead — gdal_translate does NOT reproject.
Errors are wrapped with ErrConvertFailed; recover the underlying GDAL error via errors.As into *GISError.
func ConvertVector ¶ added in v1.2.0
func ConvertVector(ctx context.Context, src, dst string, opts ...VectorConvertOption) error
ConvertVector converts the vector source at src into dst, applying any of the provided options. It is a thin wrapper around the GDAL C entry point behind `ogr2ogr` (gdal.VectorTranslate) — every option maps 1:1 to an ogr2ogr CLI flag.
Behavior:
- The destination driver is chosen by WithVectorFormat when set, else inferred from dst's extension (GDAL behavior).
- Reprojection happens during the copy when WithVectorTargetSRS is set; chain with WithVectorBoundingBox / WithVectorWhere / WithVectorSimplify for the typical "extract a region" pipeline.
- dst and src paths can use any GDAL Virtual File System prefix (`/vsimem/`, `/vsis3/`, `/vsicurl/`, `/vsigs/`, `/vsizip/`); the function passes paths through to GDAL unchanged. Bare `.zip` Shapefile bundles do NOT auto-prefix — pass `/vsizip/<path>` explicitly, or extract first via GetGISFiles.
- ctx is honored at the function boundary (checked before opening the source); the underlying CGo call is synchronous and uninterruptible — long conversions cannot be cancelled mid-way.
Errors are wrapped with ErrConvertFailed; recover the underlying GDAL error via errors.As into *GISError.
Driver names supplied via WithVectorFormat are validated against the running GDAL build before the C call, so an unknown driver surfaces as a clean ErrConvertFailed rather than the upstream silent-fail-with-stderr-warning behavior.
Example ¶
ExampleConvertVector demonstrates a vector format conversion from GeoJSON to GeoPackage in the in-process /vsimem/ VFS — no filesystem write, no network. Same shape works for /vsis3/, /vsigs/, /vsicurl/ destinations.
package main
import (
"context"
"fmt"
"github.com/hishamkaram/gismanager"
)
func main() {
src := "./testdata/neighborhood_names_gis.geojson"
dst := "/vsimem/example_convert_vector.gpkg"
if err := gismanager.ConvertVector(context.Background(), src, dst,
gismanager.WithVectorFormat("GPKG"),
gismanager.WithVectorOverwrite(),
); err != nil {
fmt.Println("error:", err)
return
}
fmt.Println("ok")
}
Output: ok
func DBIsAlive
deprecated
DBIsAlive opens a database/sql connection and pings it. Returns a non-nil error if either step fails.
Deprecated: hard-codes context.Background() for the ping; callers can't apply deadlines or cancellation. Use DBIsAliveContext.
func DBIsAliveContext ¶ added in v1.1.0
DBIsAliveContext opens a database/sql connection and pings it, honoring ctx for cancellation and deadlines on the ping. The connection is always closed before the function returns. Use this in code that already has a context in scope (HTTP handlers, library calls that thread a ctx, etc.).
func DEMProcessing ¶ added in v1.3.0
DEMProcessing runs a `gdaldem`-style raster analysis on a DEM input. Thin wrapper around the C entry point behind `gdaldem` (gdal.DEMProcessing).
mode is one of:
- "hillshade" — shaded relief from sun position
- "slope" — gradient magnitude in degrees or percent
- "aspect" — gradient direction (0-360°)
- "color-relief" — elevation-tinted RGB; REQUIRES WithDEMColorFile
- "TRI" — Terrain Ruggedness Index
- "TPI" — Topographic Position Index
- "roughness" — local elevation variability
Errors are wrapped with ErrConvertFailed; recover via errors.As into *GISError. The Op field is "DEMProcessing".
Example ¶
ExampleDEMProcessing demonstrates DEM analysis (the gdaldem equivalent). Supported modes: hillshade, slope, aspect, color-relief, TRI, TPI, roughness. Color-relief requires WithDEMColorFile; the others need only the input DEM.
package main
import (
"context"
"fmt"
"github.com/lukeroth/gdal"
"github.com/hishamkaram/gismanager"
)
func main() {
src := "/vsimem/example_dem_src.tif"
dst := "/vsimem/example_dem_hillshade.tif"
// Synthesize a 32x32 elevation raster (constant value is fine —
// hillshade just needs a defined geotransform).
driver, _ := gdal.GetDriverByName("GTiff")
srcDS := driver.Create(src, 32, 32, 1, gdal.Float32, nil)
srcDS.SetGeoTransform([6]float64{0, 1, 0, 32, 0, -1})
srcDS.Close()
if err := gismanager.DEMProcessing(context.Background(), src, dst,
"hillshade",
); err != nil {
fmt.Println("error:", err)
return
}
fmt.Println("ok")
}
Output: ok
func GetGISFiles ¶
GetGISFiles walks root recursively and returns every supported GIS file path it finds (shapefile, GeoJSON, GeoPackage, KML, plus zipped shapefile bundles which are auto-extracted to a temp directory).
Diagnostic logs use the project default logger from GetLogger. Callers that want to thread a custom logger should construct a manager via New + WithLogger and use the manager-driven walk path (added by a follow-up PR); the default logger here is preserved for back-compat.
func GetLogger ¶
GetLogger returns the project's default structured logger: a stdlib *slog.Logger writing text-formatted records to stderr.
Callers building their own pipeline should construct an *slog.Logger directly (any handler — JSON, lumberjack-rotated, otel, etc.) and pass it on the ManagerConfig.logger field via the constructor (PR 4 still loads it from FromConfig + GetLogger; functional-options constructor lands in a follow-up).
func Rasterize ¶ added in v1.3.0
func Rasterize(ctx context.Context, vectorSrc, rasterDst string, opts ...RasterizeOption) error
Rasterize burns the vector geometries from vectorSrc into the raster destination at rasterDst. Thin wrapper around the GDAL C entry point behind `gdal_rasterize` (gdal.Rasterize).
Pick one of WithRasterizeBurnValues (constant value per band) or WithRasterizeAttribute (per-feature value from an attribute field). Without either, GDAL defaults to burning value 255 into a single band — almost certainly not what callers want; the binding does not error in that case.
Pick one of WithRasterizeTargetResolution (pixel size in CRS units) or WithRasterizeOutputSize (pixel dimensions). Without either, GDAL chooses an arbitrary 256x256 default.
Errors are wrapped with ErrConvertFailed; recover via errors.As into *GISError. The Op field is "Rasterize".
Same binding gaps documented on ConvertVector apply: ctx is honored only at the function boundary, and the underlying CGo call is synchronous.
Example ¶
ExampleRasterize demonstrates burning vector features into a raster grid (the gdal_rasterize equivalent).
package main
import (
"context"
"fmt"
"github.com/hishamkaram/gismanager"
)
func main() {
src := "./testdata/neighborhood_names_gis.geojson"
dst := "/vsimem/example_rasterize.tif"
if err := gismanager.Rasterize(context.Background(), src, dst,
gismanager.WithRasterizeFormat("GTiff"),
gismanager.WithRasterizeOutputSize(64, 64),
gismanager.WithRasterizeBurnValues(1),
); err != nil {
fmt.Println("error:", err)
return
}
fmt.Println("ok")
}
Output: ok
func ReprojectRaster ¶ added in v1.2.0
func ReprojectRaster(ctx context.Context, src, dst, srcSRS, dstSRS string, opts ...RasterConvertOption) error
ReprojectRaster reprojects the raster source at src into dst, going from srcSRS to dstSRS. It is a thin wrapper around the C entry point behind `gdalwarp` (gdal.Warp).
srcSRS and dstSRS accept any GDAL SetFromUserInput-friendly form ("EPSG:4326", "EPSG:3857", "+proj=longlat +datum=WGS84 +no_defs", well-known WKT). The most common pair in 2025–26 web pipelines is EPSG:32618 / EPSG:4326 → EPSG:3857.
Supports the same [WithRaster*] options as ConvertRaster / ToCOG — chain with WithRasterResamplingAlg, WithRasterTargetResolution, WithRasterCutline for the typical "warp + clip" pipeline.
Output bounds, when supplied via WithRasterOutputBounds, are interpreted in the *target* CRS (gdalwarp's `-te` semantics), not the source CRS (gdal_translate's `-projwin`).
Errors are wrapped with ErrConvertFailed; recover via errors.As into *GISError. The Op field is "ReprojectRaster".
Driver names supplied via WithRasterFormat are pre-validated; an unknown driver surfaces as a clean ErrConvertFailed before the C call. Other silent-failure modes (invalid CRS strings, malformed option values) still rely on GDAL surfacing a non-zero cerr.
Example ¶
ExampleReprojectRaster demonstrates raster reprojection (the gdalwarp equivalent). Requires both source and target SRS; if a cookie-cutter clip is needed pass WithRasterCutline.
package main
import (
"context"
"fmt"
"github.com/lukeroth/gdal"
"github.com/hishamkaram/gismanager"
)
func main() {
src := "/vsimem/example_reproject_src.tif"
dst := "/vsimem/example_reproject_dst.tif"
// Synthesize a 16x16 raster with a defined geotransform and SRS so
// the reprojection has something real to act on.
driver, _ := gdal.GetDriverByName("GTiff")
srcDS := driver.Create(src, 16, 16, 1, gdal.Byte, nil)
srcDS.SetGeoTransform([6]float64{0, 1, 0, 16, 0, -1})
wgs84 := gdal.CreateSpatialReference("")
_ = wgs84.FromEPSG(4326)
wkt, _ := wgs84.ToWKT()
srcDS.SetProjection(wkt)
srcDS.Close()
if err := gismanager.ReprojectRaster(context.Background(), src, dst,
"EPSG:4326", "EPSG:3857",
); err != nil {
fmt.Println("error:", err)
return
}
fmt.Println("ok")
}
Output: ok
func ToCOG ¶ added in v1.2.0
func ToCOG(ctx context.Context, src, dst string, opts ...RasterConvertOption) error
ToCOG converts the raster source at src into a Cloud-Optimized GeoTIFF at dst. Equivalent to:
ConvertRaster(ctx, src, dst,
WithRasterFormat("COG"),
WithRasterCreationOption("COMPRESS", "DEFLATE"),
WithRasterCreationOption("BLOCKSIZE", "512"),
WithRasterCreationOption("OVERVIEW_RESAMPLING", "NEAREST"),
opts...)
Caller-supplied opts override any of the defaults — pass `WithRasterCreationOption("COMPRESS", "ZSTD")` to swap codecs, etc.
Example ¶
ExampleToCOG demonstrates Cloud-Optimized GeoTIFF generation. The helper pre-fills sane defaults (DEFLATE compression, 512 blocks, NEAREST overview resampling); caller-supplied options override.
The example synthesizes a tiny 16x16 input raster in /vsimem/ so it runs hermetically without any pre-fetched fixture.
package main
import (
"context"
"fmt"
"github.com/lukeroth/gdal"
"github.com/hishamkaram/gismanager"
)
func main() {
src := "/vsimem/example_to_cog_src.tif"
dst := "/vsimem/example_to_cog_dst.tif"
// Synthesize a minimal source raster.
driver, _ := gdal.GetDriverByName("GTiff")
srcDS := driver.Create(src, 16, 16, 1, gdal.Byte, nil)
srcDS.Close()
if err := gismanager.ToCOG(context.Background(), src, dst); err != nil {
fmt.Println("error:", err)
return
}
fmt.Println("ok")
}
Output: ok
func ToPMTiles ¶ added in v1.4.0
func ToPMTiles(ctx context.Context, src, dst string, opts ...PMTilesOption) error
ToPMTiles converts the MBTiles archive at src into a PMTiles v3 archive at dst. The source must be a valid MBTiles file — typically produced by ConvertRaster with `WithRasterFormat("MBTILES")` for raster inputs, or by an upstream tippecanoe / QGIS / GDAL pipeline for vector inputs.
Two-stage pipeline for callers who start from a raster:
if err := gismanager.ConvertRaster(ctx, "scene.tif", "scene.mbtiles",
gismanager.WithRasterFormat("MBTILES")); err != nil { ... }
if err := gismanager.ToPMTiles(ctx, "scene.mbtiles", "scene.pmtiles"); err != nil { ... }
PMTiles is the dominant 2026 single-file tile archive format, suitable for serverless distribution from S3, HTTP, or any range-request-capable storage. See https://docs.protomaps.com/pmtiles/.
Direct raster -> PMTiles (skipping the intermediate MBTiles) is tracked as a v1.5 follow-up; for v1.4 the two-step path is the supported route.
Errors are wrapped with ErrConvertFailed; recover the underlying go-pmtiles or filesystem error via errors.As into *GISError. The Op field is "ToPMTiles".
Types ¶
type DEMOption ¶ added in v1.3.0
type DEMOption func(*demConfig)
DEMOption configures a DEMProcessing call.
func WithDEMAlgorithm ¶ added in v1.3.0
WithDEMAlgorithm picks the slope/aspect algorithm. Valid: "Horn" (default, GDAL's traditional formula) or "ZevenbergenThorne" (smoother on rugged terrain). Maps to `-alg`.
func WithDEMAltitude ¶ added in v1.3.0
WithDEMAltitude sets the sun altitude (degrees above horizon) for hillshade. Default 45. Maps to `-alt`.
func WithDEMAzimuth ¶ added in v1.3.0
WithDEMAzimuth sets the sun azimuth (degrees clockwise from north) for hillshade. Default 315 (NW). Maps to `-az`.
func WithDEMColorFile ¶ added in v1.3.0
WithDEMColorFile points at a text file mapping elevation values to RGBA colors. REQUIRED when the processing mode is "color-relief"; ignored for other modes. Format documented at: https://gdal.org/programs/gdaldem.html#color-relief
func WithDEMCombined ¶ added in v1.3.0
func WithDEMCombined() DEMOption
WithDEMCombined enables combined shading (mixes shaded relief with elevation-tinted output) for hillshade mode. Maps to `-combined`.
func WithDEMCreationOption ¶ added in v1.3.0
WithDEMCreationOption appends a single driver-specific creation option (e.g. "COMPRESS=DEFLATE"). May be called multiple times. Maps to repeated `-co KEY=VAL`.
func WithDEMFormat ¶ added in v1.3.0
WithDEMFormat selects the output GDAL driver by name. Maps to `-of`. When empty, GDAL infers from the destination path.
func WithDEMLogger ¶ added in v1.3.0
WithDEMLogger sets the structured logger used during DEM processing. nil falls back to GetLogger.
func WithDEMMultidirectional ¶ added in v1.3.0
func WithDEMMultidirectional() DEMOption
WithDEMMultidirectional enables multidirectional hillshade — averages hillshades from four azimuths for fewer "dark face" artifacts in rugged terrain. Maps to `-multidirectional`.
func WithDEMOutputType ¶ added in v1.3.0
WithDEMOutputType sets the output pixel data type. Maps to `-ot`.
func WithDEMRawOptions ¶ added in v1.3.0
WithDEMRawOptions appends raw `gdaldem`-style flag tokens.
func WithDEMScale ¶ added in v1.3.0
WithDEMScale sets the ratio of vertical units to horizontal units (e.g. 111120 for a lat-lon DEM with meter elevations). Maps to `-s`.
func WithDEMZFactor ¶ added in v1.3.0
WithDEMZFactor sets the vertical exaggeration applied before computing the slope/hillshade/etc. Useful when elevation units differ from horizontal units (e.g. lat-lon DEM with meters elevation — pass an `-s` arg via raw options or use WithDEMZFactor with a large number to compensate). Maps to `-z`.
type DatastoreConfig ¶
type DatastoreConfig struct {
Host string `yaml:"host"`
Port uint `yaml:"port"`
DBName string `yaml:"database"`
DBUser string `yaml:"username"`
DBPass string `yaml:"password"`
Name string `yaml:"name"`
}
DatastoreConfig holds the PostGIS connection parameters that GIS Manager uses both as the GDAL OGR target (for loading) and as the GeoServer datastore to publish.
func (*DatastoreConfig) BuildConnectionString ¶
func (ds *DatastoreConfig) BuildConnectionString() string
BuildConnectionString returns the GDAL-style OGR connection string for PostgreSQL/PostGIS (the leading "PG:" prefix tells OGR which driver to use).
func (*DatastoreConfig) PostgresConnectionString ¶
func (ds *DatastoreConfig) PostgresConnectionString() string
PostgresConnectionString returns a database/sql-compatible PostgreSQL connection URL (driver "postgres" via lib/pq).
type GISError ¶
type GISError struct {
// Op is the operation name (e.g. "OpenSource", "PublishGeoserverLayer",
// "LoadToPostGIS"). Useful for logging and triage.
Op string
// Source identifies what the operation acted on — typically a file
// path, a layer name, or a workspace name. Empty if not applicable.
Source string
// Sentinel is one of the package-level Err* values. errors.Is(e,
// Sentinel) returns true.
Sentinel error
// Cause is the underlying error. May be nil if the failure is
// purely a sentinel (e.g. ErrInvalidLayer with no nested cause).
Cause error
}
GISError is the typed error gismanager returns for higher-level operations. It carries the operation name, the source path (file, layer name, or workspace as appropriate), the sentinel category, and the underlying cause.
Match by sentinel:
if errors.Is(err, gismanager.ErrUnsupportedFormat) { ... }
Inspect for fields:
var gerr *gismanager.GISError
if errors.As(err, &gerr) {
log.Println(gerr.Op, gerr.Source)
}
func (*GISError) Error ¶
Error returns a stable, parseable message of the form
gismanager: <Op> <Source>: <sentinel>: <cause>
Source is omitted if empty; Cause is omitted if nil.
type GdalLayer ¶
GdalLayer wraps a *gdal.Layer with the helper methods gismanager uses (publish, copy-to-PostGIS, schema introspection).
The logger field is intentionally lowercase: callers should construct GdalLayers via [(*ManagerConfig).NewLayer] so the manager's configured logger is stamped on automatically. The zero-value form (`GdalLayer{Layer: l}`) is still supported for back-compat — methods that need a logger fall back to GetLogger when the field is nil.
func (*GdalLayer) Features ¶ added in v1.1.0
Features returns an iterator over every feature in the layer. Features are emitted in OGR-FID order, and each feature is destroyed via gdal.Feature.Destroy as the iteration advances — so the caller never has to remember to free a handle. The cleanup also runs on early break: the still-yielded feature is destroyed when the for-range loop exits, regardless of why.
ctx is honored between feature reads — if it is canceled mid-iteration, the iterator stops cleanly (and the deferred destroy still runs).
Returns an empty iteration if the embedded *gdal.Layer is nil or FeatureCount fails (the manager's logger gets an Error record in the FeatureCount-failure case).
func (*GdalLayer) GeometryName ¶ added in v1.1.0
GeometryName returns the OGR geometry-type name for this layer ("POINT", "LINESTRING", etc.), defaulting to "geom" if the layer has no geometry column.
func (*GdalLayer) GetFeatures
deprecated
GetFeatures returns every feature in the layer, materialized into a slice. Features are read in OGR-FID order. Returns nil if FeatureCount fails.
Deprecated: leaks gdal.Feature handles — each feature in the returned slice owns a C-level handle that must be released via gdal.Feature.Destroy, which the slice form makes easy to forget. Use [(*GdalLayer).Features] which destroys each feature as iteration advances and on early break.
func (*GdalLayer) GetGeomtryName
deprecated
func (*GdalLayer) GetLayerSchema ¶
func (layer *GdalLayer) GetLayerSchema() (fields []*LayerField)
GetLayerSchema returns the layer's geometry column followed by every attribute field, each as a LayerField with name + OGR type.
func (*GdalLayer) LayerToPostgis ¶
func (layer *GdalLayer) LayerToPostgis(targetSource *gdal.DataSource, manager *ManagerConfig, overwrite bool) (newLayer *GdalLayer, err error)
LayerToPostgis copies this layer into the given GDAL PostgreSQL data source (typically a PostGIS-enabled database opened via the OGR PG: driver), preserving the geometry column name and optionally overwriting an existing table of the same name.
Returns errors wrapping ErrPostGISConnect (PostGIS unreachable), ErrInvalidDatasource (nil targetSource), or ErrInvalidLayer (nil embedded *gdal.Layer). Match via errors.Is.
type GeoserverConfig ¶
type GeoserverConfig struct {
WorkspaceName string `yaml:"workspace"`
ServerURL string `yaml:"url"`
Username string `yaml:"username"`
Password string `yaml:"password"`
}
GeoserverConfig holds the GeoServer endpoint and credentials. WorkspaceName is the workspace gismanager publishes layers into; it is created on first use if missing.
type LayerField ¶
LayerField is one column in a layer's schema (geometry or attribute).
type ManagerConfig ¶
type ManagerConfig struct {
Geoserver GeoserverConfig `yaml:"geoserver"`
Datastore DatastoreConfig `yaml:"datastore"`
Source SourceConfig `yaml:"source"`
// contains filtered or unexported fields
}
ManagerConfig is the top-level configuration loaded from YAML.
func FromConfig ¶
func FromConfig(configFile string) (*ManagerConfig, error)
FromConfig loads a ManagerConfig from a YAML file at the given path.
Returns errors wrapping ErrConfigInvalid; recover the underlying os/yaml error via errors.As.
Programmatic callers (no YAML file) should prefer New with Option helpers like WithGeoserver / WithDatastore / WithSource / WithLogger. FromConfig now delegates to New after the YAML decode.
func New ¶ added in v1.1.0
func New(opts ...Option) (*ManagerConfig, error)
New constructs a ManagerConfig from the given options. With no options, the returned manager has zero-value GeoServer / Datastore / Source configs and the default logger from GetLogger. The error return is reserved — today New always returns nil — so future validation (e.g. checking required fields) is a non-breaking addition.
Programmatic callers should prefer New over FromConfig; YAML-driven callers can still use FromConfig, which now delegates here.
func (*ManagerConfig) GetDriver ¶
func (manager *ManagerConfig) GetDriver(path string) (driver gdal.OGRDriver, err error)
GetDriver returns the OGR driver appropriate for the given path or connection string. PostgreSQL connection strings (matching pgRegex) get the PostgreSQL driver; everything else dispatches on file extension.
On unsupported extensions, returns an error wrapping ErrUnsupportedFormat (match via errors.Is).
func (*ManagerConfig) GetGeoserverCatalog ¶
func (manager *ManagerConfig) GetGeoserverCatalog() (*geoserver.Client, error)
GetGeoserverCatalog returns a GeoServer v2 client configured against the manager's GeoServer endpoint. Each call constructs a fresh client; the underlying HTTP transport is the stdlib default. Returns an error if the server URL is malformed.
func (*ManagerConfig) NewLayer ¶ added in v1.1.0
func (manager *ManagerConfig) NewLayer(l *gdal.Layer) *GdalLayer
NewLayer wraps a *gdal.Layer for use with gismanager's helpers, stamping the manager's configured logger on the result. Prefer this over the zero-value form so per-manager logger configuration (custom handler, attached attrs, etc.) reaches the layer's helper methods.
func (*ManagerConfig) OpenSource ¶
func (manager *ManagerConfig) OpenSource(_ context.Context, path string, access int) (*gdal.DataSource, error)
OpenSource opens a GDAL data source at the given path. access is the GDAL permission flag (0 read-only, 1 read-write). ctx is reserved for future cancellation support — GDAL bindings don't propagate it today, but callers should still pass a real context so a downstream-aware version is a non-breaking swap.
Errors wrap ErrUnsupportedFormat (driver lookup failed) or ErrInvalidDatasource (driver matched but Open returned !ok). Match via errors.Is; recover details via errors.As into *GISError.
Example ¶
ExampleManagerConfig_OpenSource shows the read-only inspection surface: open a GIS file via the configured GDAL OGR driver and list layer count. No PostGIS or GeoServer is touched.
package main
import (
"context"
"fmt"
"github.com/hishamkaram/gismanager"
)
func main() {
mgr, err := gismanager.New(
gismanager.WithSource(gismanager.SourceConfig{Path: "./testdata"}),
)
if err != nil {
fmt.Println("construct manager:", err)
return
}
ds, err := mgr.OpenSource(context.Background(),
"./testdata/sample.gpkg", 0)
if err != nil {
fmt.Println("open:", err)
return
}
defer ds.Destroy()
fmt.Println("layers:", ds.LayerCount())
}
Output: layers: 1
func (*ManagerConfig) PublishAll ¶ added in v1.1.0
func (manager *ManagerConfig) PublishAll(ctx context.Context) error
PublishAll runs the full pipeline: walk → load each layer into PostGIS → publish each PostGIS table as a GeoServer feature type. It is the library equivalent of `cmd/gismanager`'s main loop.
PublishAll opens the configured PostGIS datastore once at the top (re-using it across every file's layers), so the caller doesn't pay the per-file PostGIS-open cost.
Concurrency model (since v1.4):
- Walk and LayerToPostgis are SERIAL across the whole call. Both touch the shared *gdal.DataSource (the PostGIS target) and the underlying CGo handle is not reentrancy-safe across goroutines.
- PublishGeoserverLayer (HTTP-only — GeoServer queries PostGIS itself; gismanager just registers the feature type) runs in a bounded worker pool of [defaultPublishConcurrency] goroutines. Layers with publish-side latency (typical GeoServer FeatureType.Create is 100-500ms) overlap, so a 50-layer publish takes O(N/8 * latency) instead of O(N * latency).
- The publish-side ordering is therefore non-deterministic, but that has never been part of PublishAll's contract.
Error semantics (since v1.4):
- Setup failures abort the operation. If [(*ManagerConfig).OpenSource] can't open the PostGIS datastore, PublishAll returns the wrapped error directly without attempting any layer.
- Per-layer failures (walk errors, PostGIS load errors, GeoServer publish errors) do NOT abort the loop. Each is logged via the manager's logger AND collected for aggregation. Aggregation is mutex-protected since publish goroutines run concurrently.
- The final return value is errors.Join of every collected per-layer error, or nil if every layer succeeded.
Callers can branch on the aggregated result with `errors.Is(err, ErrGeoServerPublish)` / `errors.Is(err, ErrPostGISConnect)` — the joined error walks through every collected failure, so any match in the chain returns true. To enumerate per-layer failures individually, type-assert via `errors.As(err, &gerr)` repeatedly or use a small unwrap walker:
if err := mgr.PublishAll(ctx); err != nil {
var u interface{ Unwrap() []error }
if errors.As(err, &u) {
for _, e := range u.Unwrap() {
// inspect each per-layer failure
}
}
}
Pre-v1.4 callers that did `if err := mgr.PublishAll(ctx); err != nil` continue to work — the change strictly adds information. Callers that relied on PublishAll returning nil even when individual layers failed will now see those failures surface; that previous behavior was an acknowledged silent-failure mode (see the v1.3 doc comment) and the aggregated form is the documented path forward.
Example ¶
ExampleManagerConfig_PublishAll demonstrates the high-level publish flow: walk a source directory, load every supported GIS file into the configured PostGIS datastore, then publish each as a GeoServer feature type.
Programmatic construction via New + functional options is preferred over FromConfig when no YAML file is involved, since each option gets compile-time-checked and the manager's logger can be threaded in via WithLogger. FromConfig + ${VAR} env-var interpolation is the right path for ops contexts that store config in YAML and secrets in the environment.
The example deliberately does NOT include an `// Output:` comment — godoc tests would otherwise try to make a real GeoServer / PostGIS connection. The integration suite (//go:build integration) covers the runtime contract end-to-end.
package main
import (
"context"
"fmt"
"github.com/hishamkaram/gismanager"
)
func main() {
mgr, err := gismanager.New(
gismanager.WithGeoserver(gismanager.GeoserverConfig{
ServerURL: "http://localhost:8080/geoserver",
Username: "admin",
Password: "geoserver",
WorkspaceName: "demo",
}),
gismanager.WithDatastore(gismanager.DatastoreConfig{
Host: "localhost",
Port: 5432,
DBName: "gis",
DBUser: "postgres",
DBPass: "postgres",
Name: "gismanager_demo",
}),
gismanager.WithSource(gismanager.SourceConfig{Path: "./gis-data"}),
)
if err != nil {
fmt.Println("construct manager:", err)
return
}
if err := mgr.PublishAll(context.Background()); err != nil {
fmt.Println("publish:", err)
return
}
fmt.Println("published")
}
Output:
func (*ManagerConfig) PublishGeoserverLayer ¶
func (manager *ManagerConfig) PublishGeoserverLayer(ctx context.Context, layer *GdalLayer) error
PublishGeoserverLayer publishes the given GDAL layer as a GeoServer feature type, ensuring the configured workspace and PostGIS datastore exist first.
The flow uses the v2 client's "Get + ErrNotFound" idiom (v2 has no Exists methods): for each resource we try to Get it; only if Get returns geoserver.ErrNotFound do we Create it. Any other error short-circuits. PublishGeoserverLayer publishes the given GDAL layer as a GeoServer feature type, ensuring the configured workspace and PostGIS datastore exist first.
Errors are wrapped with ErrGeoServerPublish; the underlying *geoserver.APIError is recoverable via errors.As for fields and errors.Is against the v2 sentinels (e.g. ErrConflict, ErrServerError).
func (*ManagerConfig) Validate ¶ added in v1.4.0
func (c *ManagerConfig) Validate() error
Validate checks that every required field on a ManagerConfig is set to a non-zero value and reports the missing fields in a single error. The error wraps ErrConfigInvalid; recover the field list via errors.As into *GISError and inspect Cause.Error().
Validate covers the publish-pipeline contract — every field needed for the walk → PostGIS-load → GeoServer-publish flow. Programmatic callers using only a subset of the manager's surface (e.g. OpenSource for ad-hoc reads) can skip Validate entirely; only FromConfig calls it automatically, since YAML callers signal "I intend a full publish setup" by writing the YAML in the first place.
func (*ManagerConfig) Walk ¶ added in v1.1.0
Walk returns an iterator over every layer of every supported GIS file under the manager's SourceConfig.Path. Iteration order is files-outer (in GetGISFiles order) and layers-inner (in OGR-index order).
For each discovered file Walk opens the source once, yields one WalkItem per layer in OGR-index order, then `defer source.Destroy()` releases the underlying C handle before moving to the next file. Memory is therefore bounded to one file's worth of OGR state at a time, even for very large source directories.
Per-file errors do NOT abort the iterator. If [(*ManagerConfig).OpenSource] fails for a path, Walk yields a zero WalkItem paired with the wrapped error and continues to the next file. Callers can:
for item, err := range mgr.Walk(ctx) {
if err != nil {
log.Printf("skip: %v", err)
continue
}
// use item.Layer
}
`break`-ing out of the for-range loop runs the deferred Destroy on the currently-open source, so early termination doesn't leak.
type Option ¶ added in v1.1.0
type Option func(*ManagerConfig)
Option configures a ManagerConfig at construction time. Pass options to New in any order.
Each option is a small function that mutates the partially-constructed manager. The functional-options pattern matches stdlib precedent (net/http.Server, log/slog.HandlerOptions) and keeps the public surface small while leaving room for additive growth — new configuration knobs can ship as new With* helpers without breaking existing callers.
func WithDatastore ¶ added in v1.1.0
func WithDatastore(cfg DatastoreConfig) Option
WithDatastore sets the PostGIS connection parameters and GeoServer datastore name the manager loads layers into.
func WithGeoserver ¶ added in v1.1.0
func WithGeoserver(cfg GeoserverConfig) Option
WithGeoserver sets the GeoServer endpoint, credentials, and workspace name the manager publishes feature types into.
func WithLogger ¶ added in v1.1.0
WithLogger sets the structured logger the manager and its sub-operations use for diagnostic output. Passing nil falls back to the default logger returned by GetLogger so callers can opt into the default explicitly.
func WithSource ¶ added in v1.1.0
func WithSource(cfg SourceConfig) Option
WithSource sets the source-directory configuration the manager scans for supported GIS files.
type PMTilesOption ¶ added in v1.4.0
type PMTilesOption func(*pmtilesConfig)
PMTilesOption configures ToPMTiles at call time.
func WithPMTilesDeduplicate ¶ added in v1.4.0
func WithPMTilesDeduplicate(dedupe bool) PMTilesOption
WithPMTilesDeduplicate controls whether the PMTiles writer deduplicates identical tile bodies (default: true). Deduplication shrinks output at the cost of one extra hash-and-compare per tile during the conversion. Pass `false` only if you have a very specific reason to preserve byte-identical duplicates (e.g. testing the writer).
func WithPMTilesLogger ¶ added in v1.4.0
func WithPMTilesLogger(l *slog.Logger) PMTilesOption
WithPMTilesLogger threads a custom *slog.Logger through ToPMTiles. The underlying go-pmtiles library uses stdlib *log.Logger; the gismanager wrapper bridges via slog.NewLogLogger so structured log records still flow through the manager's configured handler (file, JSON, OTel, etc.).
type RasterConvertOption ¶ added in v1.2.0
type RasterConvertOption func(*rasterConvertConfig)
RasterConvertOption configures ConvertRaster, ToCOG, and ReprojectRaster. Construct via the [WithRaster*] helpers.
func WithRasterBands ¶ added in v1.2.0
func WithRasterBands(bands ...int) RasterConvertOption
WithRasterBands selects a subset of source bands to copy, in the given order. Maps to `-b 1 -b 2 ...`. Empty means all bands.
func WithRasterCreationOption ¶ added in v1.2.0
func WithRasterCreationOption(key, val string) RasterConvertOption
WithRasterCreationOption appends a single driver-specific creation option (e.g. "COMPRESS=DEFLATE", "TILING_SCHEME=GoogleMapsCompatible", "BLOCKSIZE=512"). May be called multiple times to set several options. Maps to `-co KEY=VAL`.
func WithRasterCutline ¶ added in v1.2.0
func WithRasterCutline(ds, layer string) RasterConvertOption
WithRasterCutline points at a vector dataset (and an optional layer within it) to mask the output by. Pixels outside the cutline polygon are written as NoData. Maps to `-cutline <ds>` (and `-cl <layer>` if non-empty). Useful for cookie-cutter clipping of imagery.
func WithRasterFormat ¶ added in v1.2.0
func WithRasterFormat(driver string) RasterConvertOption
WithRasterFormat selects the GDAL output driver by name (e.g. "GTiff", "COG", "PNG", "JPEG"). Maps to gdal_translate's `-of` and gdalwarp's `-of`. When empty, GDAL infers from the destination path.
func WithRasterLogger ¶ added in v1.2.0
func WithRasterLogger(l *slog.Logger) RasterConvertOption
WithRasterLogger sets the structured logger used during conversion. nil falls back to GetLogger.
func WithRasterOutputBounds ¶ added in v1.2.0
func WithRasterOutputBounds(minX, minY, maxX, maxY float64) RasterConvertOption
WithRasterOutputBounds restricts the output to the given bounding box, in the source CRS units (for ConvertRaster's `-projwin`) or target CRS units (for ReprojectRaster's `-te`). The wrapper picks the right flag based on which entry point invoked it.
func WithRasterRawOptions ¶ added in v1.2.0
func WithRasterRawOptions(args ...string) RasterConvertOption
WithRasterRawOptions appends raw flag tokens to the generated argument list. Use this to reach gdal_translate / gdalwarp flags the typed helpers don't expose.
func WithRasterResamplingAlg ¶ added in v1.2.0
func WithRasterResamplingAlg(alg string) RasterConvertOption
WithRasterResamplingAlg sets the resampling algorithm for warp / translate. Common values: "near", "bilinear", "cubic", "cubicspline", "lanczos", "average", "mode", "max", "min". Maps to `-r`.
func WithRasterTargetResolution ¶ added in v1.2.0
func WithRasterTargetResolution(xRes, yRes float64) RasterConvertOption
WithRasterTargetResolution sets the output pixel size in target-CRS units. Pass non-zero values for both axes; zero means "use source resolution". Maps to `-tr xRes yRes`.
type RasterizeOption ¶ added in v1.3.0
type RasterizeOption func(*rasterizeConfig)
RasterizeOption configures a Rasterize call. Construct via the [WithRasterize*] helpers below; pass any number of options in any order. Each helper mutates a private config struct; nil options are tolerated.
func WithRasterizeAttribute ¶ added in v1.3.0
func WithRasterizeAttribute(name string) RasterizeOption
WithRasterizeAttribute burns the named attribute field's value into the raster (numeric attributes only). Mutually exclusive with WithRasterizeBurnValues. Maps to `-a`.
func WithRasterizeBurnValues ¶ added in v1.3.0
func WithRasterizeBurnValues(values ...float64) RasterizeOption
WithRasterizeBurnValues sets per-band burn values. One value per output band. Mutually exclusive with WithRasterizeAttribute — callers should use one or the other. Maps to repeated `-burn`.
func WithRasterizeCreationOption ¶ added in v1.3.0
func WithRasterizeCreationOption(key, val string) RasterizeOption
WithRasterizeCreationOption appends a single driver-specific creation option (e.g. "COMPRESS=DEFLATE"). May be called multiple times. Maps to repeated `-co KEY=VAL`.
func WithRasterizeFormat ¶ added in v1.3.0
func WithRasterizeFormat(driver string) RasterizeOption
WithRasterizeFormat selects the output GDAL driver by name (e.g. "GTiff", "COG", "PNG"). Maps to gdal_rasterize's `-of`. When empty, GDAL infers from the destination path.
func WithRasterizeLayer ¶ added in v1.3.0
func WithRasterizeLayer(name string) RasterizeOption
WithRasterizeLayer picks one named layer from a multi-layer source (e.g. a GeoPackage). Default is to rasterize all layers, which can produce unexpected output when the source has more than one layer. Maps to `-l`.
func WithRasterizeLogger ¶ added in v1.3.0
func WithRasterizeLogger(l *slog.Logger) RasterizeOption
WithRasterizeLogger sets the structured logger used during rasterization. nil falls back to GetLogger.
func WithRasterizeOutputBounds ¶ added in v1.3.0
func WithRasterizeOutputBounds(minX, minY, maxX, maxY float64) RasterizeOption
WithRasterizeOutputBounds restricts the output to the given bounding box in the *source* CRS units. Maps to `-te xmin ymin xmax ymax`. When omitted, GDAL uses the source layer's extent.
func WithRasterizeOutputSize ¶ added in v1.3.0
func WithRasterizeOutputSize(xSize, ySize int) RasterizeOption
WithRasterizeOutputSize sets the output dimensions in pixels. Maps to `-ts`. Mutually exclusive with WithRasterizeTargetResolution.
func WithRasterizeOutputType ¶ added in v1.3.0
func WithRasterizeOutputType(t string) RasterizeOption
WithRasterizeOutputType sets the output pixel data type (e.g. "Byte", "UInt16", "Float32"). Maps to `-ot`.
func WithRasterizeRawOptions ¶ added in v1.3.0
func WithRasterizeRawOptions(args ...string) RasterizeOption
WithRasterizeRawOptions appends raw `gdal_rasterize`-style flag tokens to the generated argument list. Use this to reach flags the typed helpers do not expose (e.g. `-init`, `-a_nodata`, `-add`).
func WithRasterizeTargetResolution ¶ added in v1.3.0
func WithRasterizeTargetResolution(xRes, yRes float64) RasterizeOption
WithRasterizeTargetResolution sets the output pixel size in target-CRS units. Maps to `-tr xRes yRes`. Mutually exclusive with WithRasterizeOutputSize.
func WithRasterizeWhere ¶ added in v1.3.0
func WithRasterizeWhere(sql string) RasterizeOption
WithRasterizeWhere applies an OGR SQL WHERE filter to the source features (without the WHERE keyword). Maps to `-where`.
type SourceConfig ¶
type SourceConfig struct {
Path string `yaml:"path"`
}
SourceConfig points at the directory (or single file) gismanager scans for supported GIS data files.
type VRTOption ¶ added in v1.3.0
type VRTOption func(*vrtConfig)
VRTOption configures a BuildVRT call. Construct via the [WithVRT*] helpers below; pass any number of options in any order.
func WithVRTAddAlpha ¶ added in v1.3.0
func WithVRTAddAlpha() VRTOption
WithVRTAddAlpha appends an alpha band to the output indicating which pixels are sourced from any input vs. NoData. Maps to `-addalpha`.
func WithVRTAllowProjectionDifference ¶ added in v1.3.0
func WithVRTAllowProjectionDifference() VRTOption
WithVRTAllowProjectionDifference relaxes the SRS-must-match check; useful when assembling near-equivalent SRSes (different EPSG codes resolving to identical projections). Maps to `-allow_projection_difference`.
func WithVRTBands ¶ added in v1.3.0
WithVRTBands selects a subset of bands from each input. Maps to repeated `-b N`.
func WithVRTHideNoData ¶ added in v1.3.0
func WithVRTHideNoData() VRTOption
WithVRTHideNoData omits the NoData value from the output VRT metadata so downstream readers treat those pixels as valid. Maps to `-hidenodata`.
func WithVRTLogger ¶ added in v1.3.0
WithVRTLogger sets the structured logger used during VRT build. nil falls back to GetLogger.
func WithVRTNoData ¶ added in v1.3.0
WithVRTNoData sets the NoData value(s) emitted on the output VRT. Maps to `-vrtnodata`.
func WithVRTRawOptions ¶ added in v1.3.0
WithVRTRawOptions appends raw `gdalbuildvrt`-style flag tokens to the generated argument list.
func WithVRTResamplingAlg ¶ added in v1.3.0
WithVRTResamplingAlg sets the resampling algorithm used when input resolutions differ from the output. "near", "bilinear", "cubic", etc. Maps to `-r`.
func WithVRTResolution ¶ added in v1.3.0
WithVRTResolution selects how the VRT picks output resolution from inputs of differing pixel sizes. Valid values: "highest", "lowest", "average", "user". When "user", call WithVRTUserResolution too. Maps to `-resolution`. Default GDAL behavior is "average".
func WithVRTSeparate ¶ added in v1.3.0
func WithVRTSeparate() VRTOption
WithVRTSeparate emits one VRT band per input dataset (instead of stacking them into a tile mosaic). Useful for assembling RGBA from single-band inputs. Maps to `-separate`.
func WithVRTSrcNoData ¶ added in v1.3.0
WithVRTSrcNoData sets the NoData value(s) interpreted on the source side, comma-separated for multi-band inputs. Maps to `-srcnodata`.
func WithVRTUserResolution ¶ added in v1.3.0
WithVRTUserResolution sets the explicit output pixel size. Only effective when WithVRTResolution is "user". Maps to `-tr`.
type VectorConvertOption ¶ added in v1.2.0
type VectorConvertOption func(*vectorConvertConfig)
VectorConvertOption configures a ConvertVector call. Construct via the [WithVector*] helpers below; pass any number of options in any order. Each helper mutates a private config struct; nil options are tolerated.
The pattern matches v1.1's manager Option precedent — functional options for additive growth without breaking the public surface.
func WithVectorBoundingBox ¶ added in v1.2.0
func WithVectorBoundingBox(minX, minY, maxX, maxY float64) VectorConvertOption
WithVectorBoundingBox restricts output to features intersecting the given bounding box. Coordinates are in the *source* CRS unless WithVectorSourceSRS also reinterprets them. Maps to ogr2ogr's `-spat`.
func WithVectorFormat ¶ added in v1.2.0
func WithVectorFormat(driverName string) VectorConvertOption
WithVectorFormat selects the OGR output driver by name (e.g. "GPKG", "GeoJSON", "FlatGeobuf", "ESRI Shapefile", "KML"). Maps to ogr2ogr's `-f` flag. When empty, GDAL infers the driver from the destination path's extension.
func WithVectorLayerName ¶ added in v1.2.0
func WithVectorLayerName(name string) VectorConvertOption
WithVectorLayerName renames the destination layer (e.g. forces a different table name when copying to PostGIS or a different layer name in GPKG). Maps to ogr2ogr's `-nln`.
func WithVectorLogger ¶ added in v1.2.0
func WithVectorLogger(l *slog.Logger) VectorConvertOption
WithVectorLogger sets the structured logger used for diagnostic output during conversion. Passing nil falls back to the default logger from GetLogger. Mirrors v1.1's WithLogger semantics for the manager.
func WithVectorOverwrite ¶ added in v1.2.0
func WithVectorOverwrite() VectorConvertOption
WithVectorOverwrite replaces an existing destination layer instead of failing with a "layer already exists" error. Maps to ogr2ogr's `-overwrite`.
func WithVectorRawOptions ¶ added in v1.2.0
func WithVectorRawOptions(args ...string) VectorConvertOption
WithVectorRawOptions appends raw `ogr2ogr`-style flags to the generated argument list, after every other option. Use this to reach flags the typed helpers do not yet expose (e.g. `-lco`, `-skipfailures`, `-nlt`). Each entry is one CLI token.
func WithVectorSelectFields ¶ added in v1.2.0
func WithVectorSelectFields(fields ...string) VectorConvertOption
WithVectorSelectFields restricts the output to the named attribute fields. The geometry column is always preserved. Maps to ogr2ogr's `-select`.
func WithVectorSimplify ¶ added in v1.2.0
func WithVectorSimplify(tolerance float64) VectorConvertOption
WithVectorSimplify applies Douglas-Peucker simplification with the given tolerance (in target-CRS units). Useful for thinning vector data before web delivery. Maps to ogr2ogr's `-simplify`.
func WithVectorSourceSRS ¶ added in v1.2.0
func WithVectorSourceSRS(srs string) VectorConvertOption
WithVectorSourceSRS overrides the input CRS. Accepts any GDAL SetFromUserInput-friendly form ("EPSG:4326", "+proj=longlat ...", well-known WKT). Use only when the source has a missing or wrong CRS. Maps to ogr2ogr's `-s_srs`.
func WithVectorTargetSRS ¶ added in v1.2.0
func WithVectorTargetSRS(srs string) VectorConvertOption
WithVectorTargetSRS reprojects features to the given CRS during the conversion. The most common use is `WithVectorTargetSRS("EPSG:3857")` for web tile pipelines. Maps to ogr2ogr's `-t_srs`.
func WithVectorWhere ¶ added in v1.2.0
func WithVectorWhere(sql string) VectorConvertOption
WithVectorWhere restricts output to features matching the given OGR SQL WHERE expression (without the `WHERE` keyword), e.g. `"CONTINENT = 'Africa'"`. Maps to ogr2ogr's `-where`.
type WalkItem ¶ added in v1.1.0
type WalkItem struct {
// Path is the source file path the layer was discovered under
// (e.g. "./data/cities.geojson"). For multi-layer files (most
// GeoPackages) the same Path is yielded once per layer.
Path string
// Layer is the wrapped GDAL layer, with the manager's logger
// stamped via [(*ManagerConfig).NewLayer]. Use it directly with
// helpers like [LayerToPostgis] / [PublishGeoserverLayer], or read
// its embedded *gdal.Layer for OGR-level operations.
Layer *GdalLayer
}
WalkItem is one yielded element of [(*ManagerConfig).Walk]: a (path, layer) pair the caller can consume.
Convention: when the iterator's second yield value is a non-nil error, the WalkItem is the zero value — Path is "" and Layer is nil. When the error is nil, both fields are populated.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
gisconvert
command
Command gisconvert exposes gismanager's conversion subsystem as a CLI: vector format conversion (the ogr2ogr equivalent), raster format conversion (the gdal_translate equivalent), Cloud-Optimized GeoTIFF generation, and raster reprojection (the gdalwarp equivalent).
|
Command gisconvert exposes gismanager's conversion subsystem as a CLI: vector format conversion (the ogr2ogr equivalent), raster format conversion (the gdal_translate equivalent), Cloud-Optimized GeoTIFF generation, and raster reprojection (the gdalwarp equivalent). |
|
gismanager
command
Command gismanager publishes every supported GIS file under the configured source directory into a PostGIS datastore and registers the resulting tables as GeoServer feature types.
|
Command gismanager publishes every supported GIS file under the configured source directory into a PostGIS datastore and registers the resulting tables as GeoServer feature types. |
|
internal/cli
Package cli provides shared scaffolding for gismanager's command-line binaries (gismanager, layerSchema, gisconvert).
|
Package cli provides shared scaffolding for gismanager's command-line binaries (gismanager, layerSchema, gisconvert). |
|
layerSchema
command
Command layerSchema prints the geometry + attribute schema of every supported GIS file under the configured source directory.
|
Command layerSchema prints the geometry + attribute schema of every supported GIS file under the configured source directory. |
|
examples
|
|
|
convert_pipeline
command
Example: a 30-line tile-prep pipeline that reprojects a Natural Earth countries GeoJSON to Web Mercator, clips to an Africa bounding box, filters by continent, and writes the result as a single-layer GeoPackage suitable for tile generation.
|
Example: a 30-line tile-prep pipeline that reprojects a Natural Earth countries GeoJSON to Web Mercator, clips to an Africa bounding box, filters by continent, and writes the result as a single-layer GeoPackage suitable for tile generation. |
|
internal
|
|
|
zipx
Package zipx provides a small stdlib-only zip extraction helper that preserves directory structure and refuses zip-slip paths.
|
Package zipx provides a small stdlib-only zip extraction helper that preserves directory structure and refuses zip-slip paths. |