A Go command-line tool that parses GeoJSON files and computes geographic centroids (latitude and longitude). It can output either:
- A JSON array of location records
- SQL statements to create and populate a database table
- Reads single or FeatureCollection GeoJSON files
- Computes centroids from raw polygon coordinates
- Outputs either JSON or SQL
- CLI-friendly with flag-based configuration
go build -o latlon
./latlon -input=/path/to/geojson -output=locations.json
./latlon -input=/path/to/geojson -output=locations.sql --sql --table=locations
make test
To view line-by-line test coverage in browser:
go test ./... -coverprofile=coverage.out
go tool cover -html=coverage.out
[
{
"province": "",
"municipality": "Adams",
"latitude": 18.5284,
"longitude": 120.9018
}
]
CREATE TABLE IF NOT EXISTS lookup_location (
id SERIAL PRIMARY KEY,
province TEXT,
municipality TEXT NOT NULL,
latitude DOUBLE PRECISION NOT NULL,
longitude DOUBLE PRECISION NOT NULL
);
INSERT INTO lookup_location (province, municipality, latitude, longitude)
VALUES ('', 'Adams', 18.5284, 120.9018);
latlon-generator/
├── main.go
├── geo/ # Centroid and polygon parsers
├── processor/ # File walker, SQL and JSON emitters
├── output.json/sql # Generated results