Skip to content

A Go command-line tool that parses GeoJSON files and computes geographic centroids (latitude and longitude)

Notifications You must be signed in to change notification settings

ozgen/latlon-generator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LatLon Generator

Test Coverage Latest Release

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

Features

  • Reads single or FeatureCollection GeoJSON files
  • Computes centroids from raw polygon coordinates
  • Outputs either JSON or SQL
  • CLI-friendly with flag-based configuration

Usage

Build

go build -o latlon

Run (default: JSON)

./latlon -input=/path/to/geojson -output=locations.json

Run with SQL output

./latlon -input=/path/to/geojson -output=locations.sql --sql --table=locations

Testing

make test

To view line-by-line test coverage in browser:

go test ./... -coverprofile=coverage.out
go tool cover -html=coverage.out

Output Format

JSON

[
  {
    "province": "",
    "municipality": "Adams",
    "latitude": 18.5284,
    "longitude": 120.9018
  }
]

SQL

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);

Structure

latlon-generator/
├── main.go
├── geo/                # Centroid and polygon parsers
├── processor/          # File walker, SQL and JSON emitters
├── output.json/sql     # Generated results

About

A Go command-line tool that parses GeoJSON files and computes geographic centroids (latitude and longitude)

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published