Skip to content

Commit

Permalink
Options cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
trasch committed Aug 14, 2024
1 parent 4b57a88 commit d888197
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 25 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,10 @@ Layers in GeoJSON files (containing a FeatureCollection) can be represented by a

```bash
# mvt -h
OVERVIEW: A utility for inspecting and working with vector tiles and GeoJSON files.
OVERVIEW: A utility for inspecting and working with vector tiles (MVT) and GeoJSON files.

The tile coordinate of vector tiles can be extracted from the path
if it's either in the form '/z/x/y' or 'z_x_y'.
A x/y/z tile coordinate is needed for encoding/decoding vector tiles (MVT).
This tile coordinate can be extracted from the file path/URL if it's either in the form '/z/x/y' or 'z_x_y'.
Tile coordinates are not necessary for GeoJSON input files.
Examples:
Expand Down
8 changes: 4 additions & 4 deletions Sources/MVTCLI/CLI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ struct CLI: AsyncParsableCommand {

static let configuration = CommandConfiguration(
commandName: "mvt",
abstract: "A utility for inspecting and working with vector tiles and GeoJSON files.",
abstract: "A utility for inspecting and working with vector tiles (MVT) and GeoJSON files.",
discussion: """
The tile coordinate of vector tiles can be extracted from the path
if it's either in the form '/z/x/y' or 'z_x_y'.
Tile coordinates are not necessary for GeoJSON input files.
A x/y/z tile coordinate is needed for encoding/decoding vector tiles (MVT).
This tile coordinate can be extracted from the path/URL if it's either in the form '/z/x/y' or 'z_x_y'.
Tile coordinates are not necessary for GeoJSON files.
Examples:
- Tests/MVTToolsTests/TestData/14_8716_8015.vector.mvt
Expand Down
9 changes: 6 additions & 3 deletions Sources/MVTCLI/Dump.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ extension CLI {
@Option(name: [.customShort("P"), .long], help: "Feature property to use for the layer name in input and output GeoJSONs.")
var propertyName: String = VectorTile.defaultLayerPropertyName

@Flag(name: [.customShort("D"), .long], help: "Don't add the layer name as a property to Features in the output GeoJSONs.")
@Flag(name: [.customLong("Di", withSingleDash: true), .long], help: "Don't parse the layer name (option 'property-name') from Feature properties in the input GeoJSONs. Might speed up GeoJSON parsing considerably.")
var disableInputLayerProperty: Bool = false

@Flag(name: [.customLong("Do", withSingleDash: true), .long], help: "Don't add the layer name (option 'property-name') as a Feature property in the output GeoJSONs.")
var disableOutputLayerProperty: Bool = false

@OptionGroup
Expand All @@ -34,8 +37,8 @@ extension CLI {

var tile = VectorTile(
contentsOfGeoJson: url,
layerProperty: propertyName,
layerWhitelist: layerAllowlist,
layerProperty: disableInputLayerProperty ? nil : propertyName,
layerWhitelist: disableInputLayerProperty ? nil : layerAllowlist,
logger: options.verbose ? CLI.logger : nil)

if tile == nil,
Expand Down
2 changes: 1 addition & 1 deletion Sources/MVTCLI/Export.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ extension CLI {
@Option(name: [.customShort("P"), .long], help: "Feature property to use for the layer name in the output GeoJSON.")
var propertyName: String = VectorTile.defaultLayerPropertyName

@Flag(name: [.customShort("D"), .long], help: "Don't add the layer name as a property to Features in the output GeoJSON.")
@Flag(name: [.customLong("Do", withSingleDash: true), .long], help: "Don't add the layer name (option 'property-name') as a Feature property in the output GeoJSONs.")
var disableOutputLayerProperty: Bool = false

@Flag(name: .shortAndLong, help: "Pretty-print the output GeoJSON.")
Expand Down
2 changes: 1 addition & 1 deletion Sources/MVTCLI/Import.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ extension CLI {
@Option(name: [.customShort("P"), .long], help: "Feature property to use for the layer name in input GeoJSONs. Fallback to 'layer-name' or a default if the property is not present.")
var propertyName: String = VectorTile.defaultLayerPropertyName

@Flag(name: [.customShort("D"), .long], help: "Don't try to find 'propert-name' in input GeoJSONs, just use 'layer-name' or a default. Might speed up things considerably.")
@Flag(name: [.customLong("Di", withSingleDash: true), .long], help: "Don't parse the layer name (option 'property-name') from Feature properties in the input GeoJSONs, just use 'layer-name' or a default. Might speed up GeoJSON parsing considerably.")
var disableInputLayerProperty: Bool = false

@OptionGroup
Expand Down
10 changes: 9 additions & 1 deletion Sources/MVTCLI/Info.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,15 @@ extension CLI {
case properties
}

static let configuration = CommandConfiguration(abstract: "Print information about the input file (MVT or GeoJSON)")
static let configuration = CommandConfiguration(
abstract: "Print information about the input file (MVT or GeoJSON)",
discussion: """
Available tables:
- features: Feature counts (points, linestrings, polygons) for each layer
in the input file.
- properties: Counts of all Feature properties for each layer in the
input file.
""")

@Option(name: .shortAndLong,
help: "The tables to print, comma separated list of '\(InfoTables.allCases.map(\.rawValue).joined(separator: ","))'.",
Expand Down
19 changes: 11 additions & 8 deletions Sources/MVTCLI/Merge.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,30 @@ extension CLI {

static let configuration = CommandConfiguration(
abstract: "Merge any number of MVTs or GeoJSONs",
discussion: "Vector tiles should all have the same tile coordinate, or you will get strange results.")
discussion: "Note: Vector tiles should all have the same tile coordinate or strange things will happen.")

@Option(name: [.short, .customLong("output")], help: "Output file (optional, default is console).")
var outputFile: String?

@Option(name: [.customShort("O"), .long], help: "Output file format (optional, one of 'auto', 'geojson', 'mvt').")
var outputFormat: OutputFormat = .auto

@Flag(name: .shortAndLong, help: "Force overwrite an existing --output file.")
@Flag(name: .shortAndLong, help: "Force overwrite an existing 'output' file.")
var forceOverwrite = false

@Flag(name: .shortAndLong, help: "Append to an existing --output file.")
@Flag(name: .shortAndLong, help: "Append to an existing 'output' file.")
var append = false

@Option(name: .shortAndLong, help: "Merge only the specified layers (can be repeated).")
var layer: [String] = []

@Option(name: [.customShort("P"), .long], help: "Feature property to use for the layer name in the output GeoJSON.")
@Option(name: [.customShort("P"), .long], help: "Feature property to use for the layer name in input and output GeoJSONs.")
var propertyName: String = VectorTile.defaultLayerPropertyName

@Flag(name: [.customShort("D"), .long], help: "Don't add the layer name as a property to Features in the output GeoJSON.")
@Flag(name: [.customLong("Di", withSingleDash: true), .long], help: "Don't parse the layer name (option 'property-name') from Feature properties in the input GeoJSONs. Might speed up GeoJSON parsing considerably.")
var disableInputLayerProperty: Bool = false

@Flag(name: [.customLong("Do", withSingleDash: true), .long], help: "Don't add the layer name (option 'property-name') as a Feature property in the output GeoJSONs.")
var disableOutputLayerProperty: Bool = false

@Flag(name: .shortAndLong, help: "Pretty-print the output GeoJSON.")
Expand Down Expand Up @@ -101,7 +104,7 @@ extension CLI {
}
else if let geoJsonTile = VectorTile(
contentsOfGeoJson: outputUrl,
layerProperty: propertyName,
layerProperty: disableInputLayerProperty ? nil : propertyName,
logger: options.verbose ? CLI.logger : nil)
{
tile = geoJsonTile
Expand Down Expand Up @@ -180,8 +183,8 @@ extension CLI {
}
else if let other = VectorTile(
contentsOfGeoJson: otherUrl,
layerProperty: propertyName,
layerWhitelist: layerAllowlist,
layerProperty: disableInputLayerProperty ? nil : propertyName,
layerWhitelist: disableInputLayerProperty ? nil : layerAllowlist,
logger: options.verbose ? CLI.logger : nil)
{
otherTile = other
Expand Down
11 changes: 7 additions & 4 deletions Sources/MVTCLI/Query.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,13 @@ extension CLI {
@Option(name: .shortAndLong, help: "Search only in this layer (can be repeated).")
var layer: [String] = []

@Option(name: [.customShort("P"), .long], help: "Feature property to use for the layer name in the output GeoJSON.")
@Option(name: [.customShort("P"), .long], help: "Feature property to use for the layer name in input and output GeoJSONs.")
var propertyName: String = VectorTile.defaultLayerPropertyName

@Flag(name: [.customShort("D"), .long], help: "Don't add the layer name as a property to Features in the output GeoJSON.")
@Flag(name: [.customLong("Di", withSingleDash: true), .long], help: "Don't parse the layer name (option 'property-name') from Feature properties in the input GeoJSONs. Might speed up GeoJSON parsing considerably.")
var disableInputLayerProperty: Bool = false

@Flag(name: [.customLong("Do", withSingleDash: true), .long], help: "Don't add the layer name (option 'property-name') as a Feature property in the output GeoJSONs.")
var disableOutputLayerProperty: Bool = false

@Flag(name: .shortAndLong, help: "Pretty-print the output GeoJSON.")
Expand Down Expand Up @@ -79,8 +82,8 @@ extension CLI {

var tile = VectorTile(
contentsOfGeoJson: url,
layerProperty: propertyName,
layerWhitelist: layerAllowlist,
layerProperty: disableInputLayerProperty ? nil : propertyName,
layerWhitelist: disableInputLayerProperty ? nil : layerAllowlist,
logger: options.verbose ? CLI.logger : nil)

if tile == nil,
Expand Down

0 comments on commit d888197

Please sign in to comment.