Go package to quick and easy create json data in geojson format.

#GEOJSON


Go package to easy and quick create datastructure which can be serialized to geojson format


INSTALLATION

$ go get github.com/kpawlik/geojson
$ go install github.com/kpawlik/geojson

USAGE EXAMPLE

package main

import (
    "fmt"
    gj "github.com/kpawlik/geojson"
)

func main() {
    fc := gj.NewFeatureCollection([]*gj.Feature {})

    // feature
    p := gj.NewPoint(gj.Coordinate{12, 3.123})
    f1 := gj.NewFeature(p, nil, nil)
    fc.AddFeatures(f1)

    // feature with propertises
    props := map[string]interface{}{"name": "location", "code": 107}
    f2 := gj.NewFeature(p, props, nil)
    fc.AddFeatures(f2)

    // feature with propertises and id
    f3 := gj.NewFeature(p, props, 11101)
    fc.AddFeatures(f3)

    ls := gj.NewLineString(gj.Coordinates{{1, 1}, {2.001, 3}, {4001, 1223}})
    f4 := gj.NewFeature(ls, nil, nil)
    fc.AddFeatures(f4)

    if gjstr, err := gj.Marshal(fc); err != nil {
        panic(err)
    } else {
        fmt.Println(gjstr)
    }
}
Comments
  • Use of base 10 decimal type rather than float64 for Coordtype?

    Use of base 10 decimal type rather than float64 for Coordtype?

    Seems like precision errors could crop up while interchanging data through this. Since GeoJSON coordinates are represented in strings as base 10 (WGS 84?), then they could (likely) wobble a bit when getting re-serialized back out after being stored in a Point struct from this project.

  • license

    license

    This is great! I plan on using this package in my project.

    Can you add an open source LICENSE file? GitHub has examples here: http://choosealicense.com/licenses/

  • Made Coordinate a slice

    Made Coordinate a slice

    The GeoJSON "coordinate" is just an array whose definition depends on the CRS (coordinate reference system). The Coordinate type that is used to express coordinates only supports two elements. I changed it to be a slice.

    I chiefly just wanted to have altitudes (GeoJSON defaults to the WGS84 datum as the CRS, which supports altitudes).

  • BSON Tags for Use with MGO MongoDB Driver

    BSON Tags for Use with MGO MongoDB Driver

    Thanks for all your work on this package. It would work well in a MongoDb geospatial workflow, and I'm forking it to add bson:"" tags in marshaling.

  • Add generic omitempty to all omitempty fields

    Add generic omitempty to all omitempty fields

    I'm using this library with the MongoDB driver "mgo". It has a function similar to json.Marshal which converts GeoJSON objects, but it doesn't follow "json: omitempty" on fields. So this is adding bbox: null and crs: null to all queries, and then my GeoJSON is not valid in MongoDB.

    I was able to fix my code by adding "$field, omitempty" to all fields where "json: omitempty" is currently used. I ran go test and all tests pass.

  • Example JSON returned invalid structure

    Example JSON returned invalid structure

    You were printing several Feature types on separate lines but they need to be contained within a FeatureCollection in order to be both valid GeoJSON and JSON. This simplified the code since there is just the one marshal/print at the end, now. I also created multiple value variables (rather than pointers) for the features since they are passed-in and stored as pointers. Every time we would reassign the pointer we'd effectively be updating the values that have already been added to the feature-collection as well.

    I also updated the README to correctly syntax-highlight the example, to correctly show the preformatting for the installation commands, and fixed one spelling error.

    Thanks for the project. From what I've seen it's simple and effective.

  • Removed unsupported bson flag

    Removed unsupported bson flag

    Most of this is noise due to gofmt removing white spaces.

    There was an unsupported float tag attached to the Polygon struct.

    See bson docs for some more info about supported tags, seems like its supported in json but not bson.

  • Unmarshaling generic GeoJSON

    Unmarshaling generic GeoJSON

    As far as I can see, this library only supports unmarshaling structs where you already know the type. If you want to be able to support parsing arbitrary GeoJSON structs, you have to do a partial unmarshal and do a big case statement like so:

    var partial struct{
      Type string `json:"type"`
    }
    err := json.Unmarshal(b, &partial)
    switch partial.Type {
      case "point":
        var p geojson.Point
        err = json.Unmarshal(b, &p)
    ...
    

    The private parseGeometry already does pretty much this. It would be nice to have it exposed as a public function, as well as a generic UnmarshalJSON that can do it straight from bytes. Thoughts?

Related tags
Publish Your GIS Data(Vector Data) to PostGIS and Geoserver
Publish Your GIS Data(Vector Data) to PostGIS and Geoserver

GISManager Publish Your GIS Data(Vector Data) to PostGIS and Geoserver How to install: go get -v github.com/hishamkaram/gismanager Usage: testdata fol

Sep 26, 2022
General purpose library for reading, writing and working with OpenStreetMap data

osm This package is a general purpose library for reading, writing and working with OpenStreetMap data in Go (golang). It has the ability to read OSM

Dec 30, 2022
A library provides spatial data and geometric algorithms

Geoos Our organization spatial-go is officially established! The first open source project Geoos(Using Golang) provides spatial data and geometric alg

Dec 27, 2022
Package kml provides convenince methods for creating and writing KML documents.

go-kml Package kml provides convenience methods for creating and writing KML documents. Key Features Simple API for building arbitrarily complex KML d

Jul 29, 2022
Package polyline implements a Google Maps Encoding Polyline encoder and decoder.

go-polyline Package polyline implements a Google Maps Encoding Polyline encoder and decoder. Encoding example func ExampleEncodeCoords() { coords :=

Dec 1, 2022
Go (golang) wrapper for GDAL, the Geospatial Data Abstraction Library

------------- About ------------- The gdal.go package provides a go wrapper for GDAL, the Geospatial Data Abstraction Library. More information about

Dec 24, 2022
Package geom implements efficient geometry types for geospatial applications.

go-geom Package geom implements efficient geometry types for geospatial applications. Key features OpenGeo Consortium-style geometries. Support for 2D

Jan 6, 2023
A pure Go package for coordinate transformations.

WGS84 A pure Go package for coordinate transformations. go get github.com/wroge/wgs84 Usage east, north, h := wgs84.LonLat().To(wgs84.ETRS89UTM(32)).R

Nov 25, 2022
yet another point in polygon package

piper Yet another point in polygon package. Piper makes use of ray casting and does account for holes in polygons. Installation go get -u github.com/i

Oct 17, 2022
Types and utilities for working with 2d geometry in Golang

orb Package orb defines a set of types for working with 2d geo and planar/projected geometric data in Golang. There are a set of sub-packages that use

Dec 28, 2022
Real-time Geospatial and Geofencing
Real-time Geospatial and Geofencing

Tile38 is an open source (MIT licensed), in-memory geolocation data store, spatial index, and realtime geofence. It supports a variety of object types

Dec 30, 2022
Prometheus Common Data Exporter can parse JSON, XML, yaml or other format data from various sources (such as HTTP response message, local file, TCP response message and UDP response message) into Prometheus metric data.
Prometheus Common Data Exporter can parse JSON, XML, yaml or other format data from various sources (such as HTTP response message, local file, TCP response message and UDP response message) into Prometheus metric data.

Prometheus Common Data Exporter Prometheus Common Data Exporter 用于将多种来源(如http响应报文、本地文件、TCP响应报文、UDP响应报文)的Json、xml、yaml或其它格式的数据,解析为Prometheus metric数据。

May 18, 2022
Quick and easy expression matching for JSON schemas used in requests and responses

schema schema makes it easier to check if map/array structures match a certain schema. Great for testing JSON API's or validating the format of incomi

Dec 24, 2022
A quick and easy password protected web server for your files. httpfolder makes downloading/uploading files from your current working directory easy, even for fairly large files.

httpfolder A quick and easy password protected web server for your files. httpfolder makes downloading/uploading files from your current working direc

Sep 12, 2022
Encoding and decoding GeoJSON <-> Go

go.geojson Go.geojson is a package for encoding and decoding GeoJSON into Go structs. Supports both the json.Marshaler and json.Unmarshaler interfaces

Jan 2, 2023
Input Geojson and utilize Dijkstra's formula to provide the best route between two sets of coordinates

Golang GeoJson Dijkstra Golang GeoJson Dijkstra utilizes GeoJson Feature Collections to find the best the shortest route between two points. Installat

Dec 27, 2022
A quick and easy way to setup a RESTful JSON API

Go-Json-Rest A quick and easy way to setup a RESTful JSON API Go-Json-Rest is a thin layer on top of net/http that helps building RESTful JSON APIs ea

Jan 3, 2023
Read metrics from a Message Queue in Json format and expose them in a Prometheus compatible format

mq2prom Read metrics from a Message Queue in Json format and expose them in a Prometheus compatible format. Currently only works for MQTT compatible M

Jan 24, 2022
API in Golang with CRUD to manipulate GeoJson

Golang API with Hexagonal Architecture API to manage point of navigation Object Point: - Name - Latitude - Longiture TODO ❏ Create point in Mongodb [X

Dec 24, 2022
Optimus is an easy-to-use, reliable, and performant workflow orchestrator for data transformation, data modeling, pipelines, and data quality management.

Optimus Optimus is an easy-to-use, reliable, and performant workflow orchestrator for data transformation, data modeling, pipelines, and data quality

Jan 6, 2023