Skip to content
This repository has been archived by the owner on May 13, 2022. It is now read-only.

whosonfirst/go-whosonfirst-geojson-v2

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-whosonfirst-geojson-v2

Go tools for working with Who's On First documents

Notice

This package is officially. It is still being used in other packages but they are slowly being updated.

Basically this package tries to do too many things, specifically around defining GeoJSON-related structs and interfaces. It's not really worth the effort and better to use paulmach/orb/geojson for geometry and GeoJSON-related operations and [tidwall/gjson](https://github.com/tidwall/gjson] for query-related operations using plain-vanilla []byte elements. This is the approach taken by the go-whosonfirst-feature package.

If you are using this package in your code it would be best to migrate it to use equivalent functionality defined in the go-whosonfirst-feature package.

History

The goal of this package was to replace the existing go-whosonfirst-geojson package.

geojson-v2?

Yeah, I don't really like it either but this package is basically 100% backwards incompatible with github.com/whosonfirst/go-whosonfirst-geojson and while I don't really think anyone else is using it I don't like the idea of suddenly breaking everyone's code.

Also, it was released before Go introduced formal versioning so the (unfortunate) decision was made to use -v2 instead of /v2.

Interfaces

Unlike the first go-whosonfirst-geojson package this one at least attempts to define a simplified interface for working with GeoJSON features. These are still in flux.

Please finish writing me.

geojson.Feature

type Feature interface {
	Type() string
	Id() int64
	Name() string
	Placetype() string
	ToString() string
	ToBytes() []byte
	BoundingBoxes() (BoundingBoxes, error)
	Polygons() ([]Polygon, error)
	ContainsCoord(geom.Coord) (bool, error)
}

geojson.BoundingBoxes

type BoundingBoxes interface {
	Bounds() []*geom.Rect
	MBR() geom.Rect
}

geojson.Centroid

type Centroid interface {
	Coord() geom.Coord
	Source() string
}

geojson.Polygon

type Polygon interface {
	ExteriorRing() geom.Polygon
	InteriorRings() []geom.Polygon
	ContainsCoord(geom.Coord) bool
}

Usage

Simple

import (
	"github.com/whosonfirst/go-whosonfirst-geojson-v2/whosonfirst"
	"log"
)

func main() {

	path := "/usr/local/data/whosonfirst-data/data/101/736/545/101736545.geojson"
	f, err := whosonfirst.LoadFeatureFromFile(path)

	if err != nil {
		log.Fatal(err)
	}

	// prints "Montreal"
	log.Println("Name is ", f.Name())
}

See also