geojson

package module
v0.0.0-...-1d53ca0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 22, 2017 License: BSD-3-Clause Imports: 9 Imported by: 2

README

go-whosonfirst-geojson

Go tools for working with Who's On First documents

Important

This package not been officially deprecated yet but it will be as soon as the go-whosonfirst-geojson-v2 package is complete. Until then only immediate bug fixes will be addressed. No additional features will be added to this package.

Install

You will need to have both Go (specifically a version of Go more recent than 1.6 so let's just assume you need Go 1.8 or higher) and the make programs installed on your computer. Assuming you do just type:

make bin

All of this package's dependencies are bundled with the code in the vendor directory.

Usage

package main

import (
	"flag"
	"fmt"
	geojson "github.com/whosonfirst/go-whosonfirst-geojson/whosonfirst"
)

func main() {

	flag.Parse()
	args := flag.Args()

	for _, path := range args {

		// This is mostly just helper code to read the file
		// and call geojson.UnmarshalFeature (from a bag of bytes)

		f, parse_err := geojson.UnmarshalFile(path)

		if parse_err != nil {
			panic(parse_err)
		}

		fmt.Printf("# %s\n", path)
		fmt.Println(f.Dumps())
	}

}

The longer version

This isn't really a "GeoJSON" specific library, yet. Right now it's just a thin wrapper around the Gabs utility for wrangling unknown JSON structures in to a Go WOFFeature struct.

Eventually it would be nice to make Gabs hold hands with Paul Mach's go.geojson and use the former to handle the GeoJSON properties dictionary. But that day is not today.

The longer longer version

Right now this library has evolved and grown functionality on as-needed basis, targeting on Who's On First specific use-cases. As such it consists of a handful of WOF struct types - WOFFeature and WOFPolygon and WOFSpatial - that are wrappers around other people's heavy-lifting. There are not any WOF related interfaces but that's really the direction we want to head in... but we're not there yet. So things will probably change in the short-term. Not too much , hopefully.

Utilities

Things you can find in the cmd and ultimately the bin directories.

wof-geojson-contains

A tool for testing wether a given latitude and longitude is contained by one or more GeoJSON files. As of this writing this tool lacks command line parameters for defining latitide and longitude.

# ASSUMING
# lat := 45.523668
# lon := -73.600159

# PLAIN VANILLA POLYGON

$> ./bin/wof-geojson-contains /usr/local/mapzen/whosonfirst-data/data/404/529/181/404529181.geojson /usr/local/mapzen/whosonfirst-data/data/857/848/31/85784831.geojson
/usr/local/mapzen/whosonfirst-data/data/404/529/181/404529181.geojson has this many polygons: 1
/usr/local/mapzen/whosonfirst-data/data/404/529/181/404529181.geojson #1 has 3 interior rings
/usr/local/mapzen/whosonfirst-data/data/404/529/181/404529181.geojson #1 contains point false
/usr/local/mapzen/whosonfirst-data/data/404/529/181/404529181.geojson contains point: false
/usr/local/mapzen/whosonfirst-data/data/404/529/181/404529181.geojson f.Contains() point: false
---
/usr/local/mapzen/whosonfirst-data/data/857/848/31/85784831.geojson has this many polygons: 1
/usr/local/mapzen/whosonfirst-data/data/857/848/31/85784831.geojson #1 has 0 interior rings
/usr/local/mapzen/whosonfirst-data/data/857/848/31/85784831.geojson #1 contains point true
/usr/local/mapzen/whosonfirst-data/data/857/848/31/85784831.geojson contains point: true
/usr/local/mapzen/whosonfirst-data/data/857/848/31/85784831.geojson f.Contains() point: true
---

# MULTI POLYGON

$> ./bin/wof-geojson-contains /usr/local/mapzen/whosonfirst-data/data/136/251/273/136251273.geojson
/usr/local/mapzen/whosonfirst-data/data/136/251/273/136251273.geojson has this many polygons: 8
/usr/local/mapzen/whosonfirst-data/data/136/251/273/136251273.geojson #1 has 0 interior rings
/usr/local/mapzen/whosonfirst-data/data/136/251/273/136251273.geojson #1 contains point false
/usr/local/mapzen/whosonfirst-data/data/136/251/273/136251273.geojson #2 has 0 interior rings
/usr/local/mapzen/whosonfirst-data/data/136/251/273/136251273.geojson #2 contains point false
/usr/local/mapzen/whosonfirst-data/data/136/251/273/136251273.geojson #3 has 0 interior rings
/usr/local/mapzen/whosonfirst-data/data/136/251/273/136251273.geojson #3 contains point false
/usr/local/mapzen/whosonfirst-data/data/136/251/273/136251273.geojson #4 has 0 interior rings
/usr/local/mapzen/whosonfirst-data/data/136/251/273/136251273.geojson #4 contains point true
/usr/local/mapzen/whosonfirst-data/data/136/251/273/136251273.geojson #5 has 0 interior rings
/usr/local/mapzen/whosonfirst-data/data/136/251/273/136251273.geojson #5 contains point false
/usr/local/mapzen/whosonfirst-data/data/136/251/273/136251273.geojson #6 has 0 interior rings
/usr/local/mapzen/whosonfirst-data/data/136/251/273/136251273.geojson #6 contains point false
/usr/local/mapzen/whosonfirst-data/data/136/251/273/136251273.geojson #7 has 0 interior rings
/usr/local/mapzen/whosonfirst-data/data/136/251/273/136251273.geojson #7 contains point false
/usr/local/mapzen/whosonfirst-data/data/136/251/273/136251273.geojson #8 has 0 interior rings
/usr/local/mapzen/whosonfirst-data/data/136/251/273/136251273.geojson #8 contains point false
/usr/local/mapzen/whosonfirst-data/data/136/251/273/136251273.geojson contains point: true
/usr/local/mapzen/whosonfirst-data/data/136/251/273/136251273.geojson f.Contains() point: true
wof-geojson-dump

Print the ID, name and placetype for one or more GeoJSON files. This is a utility to test the Id and Name and Placetype methods for a GeoJSON document parsed by go-whosonfirst-geojson

$> ./bin/wof-geojson-dump /usr/local/mapzen/whosonfirst-data/data/101/736/545/101736545.geojson
# /usr/local/mapzen/whosonfirst-data/data/101/736/545/101736545.geojson
ID is 101736545
Name is Montréal
Placetype is locality
wof-geojson-enspatialize

This is a utility for testing the SpatializeGeom functionality for one or more GeoJSON files.

./bin/wof-geojson-enspatialize /usr/local/mapzen/whosonfirst-data/data/101/736/545/101736545.geojson
Enspatialize bounding box
&{0xc210038d20 101736545 Montréal locality -1}
101736545
Enspatialize geom
1
&{0xc210038de0 101736545 Montréal locality 0}
wof-geojson-polygons

This is a utility for testing the GeomToPolygons functionality, by printing the number of points in each outer ring, for one or more GeoJSON files.

./bin/wof-geojson-polygons /usr/local/mapzen/whosonfirst-data/data/101/736/545/101736545.geojson
5206 points
wof-geojson-validate

Validate a directory full of GeoJSON files. Specifically validate that they are valid JSON and nothing else. A more full-feature Who's On First validator in Go may be written in the future but today is not that day. You could take a look at py-mapzen-whosonfirst-validator for that.

$> /bin/wof-geojson-validate -source /usr/local/mapzen/whosonfirst-data/data/ -processes 200
time to validate 401499 files: 1m11.002168559s

See also

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type WOFFeature

type WOFFeature struct {
	Parsed *gabs.Container
}

func UnmarshalFeature

func UnmarshalFeature(raw []byte) (*WOFFeature, error)

func UnmarshalFeatureCollection

func UnmarshalFeatureCollection(raw []byte) ([]*WOFFeature, error)

func UnmarshalFile

func UnmarshalFile(path string) (*WOFFeature, error)

func (WOFFeature) Body

func (wof WOFFeature) Body() *gabs.Container

func (WOFFeature) Contains

func (wof WOFFeature) Contains(latitude float64, longitude float64) bool

func (WOFFeature) Deprecated

func (wof WOFFeature) Deprecated() bool

func (WOFFeature) DumpCoords

func (wof WOFFeature) DumpCoords(poly []interface{}) geo.Polygon

func (WOFFeature) DumpMultiPolygon

func (wof WOFFeature) DumpMultiPolygon(coordinates []interface{}) []*WOFPolygon

func (WOFFeature) DumpPolygon

func (wof WOFFeature) DumpPolygon(coordinates []interface{}) *WOFPolygon

func (WOFFeature) Dumps

func (wof WOFFeature) Dumps() string

func (WOFFeature) EnSpatialize

func (wof WOFFeature) EnSpatialize() (*WOFSpatial, error)

func (WOFFeature) EnSpatializeGeom

func (wof WOFFeature) EnSpatializeGeom() ([]*WOFSpatial, error)

func (WOFFeature) GeomToPolygons

func (wof WOFFeature) GeomToPolygons() []*WOFPolygon

func (WOFFeature) Hierarchy

func (wof WOFFeature) Hierarchy() []map[string]int

func (WOFFeature) Id

func (wof WOFFeature) Id() int

func (WOFFeature) IntProperty

func (wof WOFFeature) IntProperty(prop string) (int, bool)

func (WOFFeature) IntValue

func (wof WOFFeature) IntValue(path string) (int, bool)

func (WOFFeature) Name

func (wof WOFFeature) Name() string

func (WOFFeature) Placetype

func (wof WOFFeature) Placetype() string

func (WOFFeature) StringProperty

func (wof WOFFeature) StringProperty(prop string) (string, bool)

func (WOFFeature) StringValue

func (wof WOFFeature) StringValue(path string) (string, bool)

func (WOFFeature) Superseded

func (wof WOFFeature) Superseded() bool

type WOFPolygon

type WOFPolygon struct {
	OuterRing     geo.Polygon
	InteriorRings []geo.Polygon
}

func (*WOFPolygon) Contains

func (p *WOFPolygon) Contains(latitude float64, longitude float64) bool

func (*WOFPolygon) CountPoints

func (p *WOFPolygon) CountPoints() int

type WOFSpatial

type WOFSpatial struct {
	Id         int
	Name       string
	Placetype  string
	Offset     int // used when calling EnSpatializeGeom in order to know which polygon we care about
	Deprecated bool
	Superseded bool
	// contains filtered or unexported fields
}

func (WOFSpatial) Bounds

func (sp WOFSpatial) Bounds() *rtreego.Rect

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL