项目作者: Froglich

项目描述 :
Geography manipulation and conversion for Go
高级语言: Go
项目地址: git://github.com/Froglich/gegography.git
创建时间: 2019-11-13T09:27:16Z
项目社区:https://github.com/Froglich/gegography

开源协议:GNU General Public License v3.0

下载



GPL v3
Go report card
Codefactor
GoDoc link

Gegography

Gegography is a library for reading, manipulating and converting
geographical formats, written i pure Go. Currently, support is limited to
GeoJSON, WKT (Well-Known-Text) and Shapefiles (read only). I plan on
implementing WKB (Well-Known-Binary).

I do not plan on supporting writing Shapefiles. Shapefile must die!

Gegography supports the following geographical types:

  • Point
  • LineString
  • Polygon
  • MultiPoint
  • MultiLineString
  • MultiPolygon

Currently, only XY geometries are supported.

What is it for?

I wrote Gegography primarily as a utility for processing geographical data
uploaded to websites with Go backends. For example, I manage several websites
with interactive mapping capabilities, and a common request is for users to
be able to upload Shapefiles or GeoJSON-documents and have them automatically
displayed on the map, or saved in the underlying database for viewing on demand.

With gegography you can read a Shapefile or a GeoJSON-document and easily export
all features to WKT-strings for storage as geometries inside a database engine
such as PostgreSQL or SQL Server.

How do I use it?

A typical use-case would look something like this (convert a shapefile to geojson)

  1. package main
  2. import (
  3. "os"
  4. "github.com/Froglich/gegography"
  5. "io/ioutil"
  6. )
  7. func main() {
  8. infile := os.Args[1]
  9. fc, err := gegography.ReadShapefile(infile)
  10. if err != nil {
  11. panic(err)
  12. }
  13. gj, err := fc.ToPrettyGeoJSON()
  14. if err != nil {
  15. panic(err)
  16. }
  17. err = ioutil.WriteFile(infile[:len(infile)-4] + ".geojson", gj, 0755)
  18. if err != nil {
  19. panic(err)
  20. }
  21. }

Installing

Install with go get github.com/Froglich/gegography .