{"id":16708377,"url":"https://github.com/paulmach/go.geojson","last_synced_at":"2025-05-15T16:05:22.698Z","repository":{"id":20358913,"uuid":"23634037","full_name":"paulmach/go.geojson","owner":"paulmach","description":"Encoding and decoding GeoJSON \u003c-\u003e Go","archived":false,"fork":false,"pushed_at":"2023-07-08T23:59:04.000Z","size":32,"stargazers_count":304,"open_issues_count":1,"forks_count":59,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-04-07T21:13:35.751Z","etag":null,"topics":["decoding","encoding","geojson","golang"],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/paulmach.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2014-09-03T19:20:46.000Z","updated_at":"2025-04-07T13:31:20.000Z","dependencies_parsed_at":"2023-10-11T01:29:12.485Z","dependency_job_id":null,"html_url":"https://github.com/paulmach/go.geojson","commit_stats":{"total_commits":27,"total_committers":14,"mean_commits":"1.9285714285714286","dds":0.6666666666666667,"last_synced_commit":"1bf186acc906431ca10579ff12700f86d5da421f"},"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paulmach%2Fgo.geojson","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paulmach%2Fgo.geojson/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paulmach%2Fgo.geojson/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paulmach%2Fgo.geojson/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/paulmach","download_url":"https://codeload.github.com/paulmach/go.geojson/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254374411,"owners_count":22060610,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["decoding","encoding","geojson","golang"],"created_at":"2024-10-12T19:44:12.610Z","updated_at":"2025-05-15T16:05:22.660Z","avatar_url":"https://github.com/paulmach.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# go.geojson [![CI](https://github.com/paulmach/go.geojson/workflows/CI/badge.svg)](https://github.com/paulmach/go.geojson/actions?query=workflow%3ACI+event%3Apush) [![Godoc Reference](https://godoc.org/github.com/paulmach/go.geojson?status.svg)](https://godoc.org/github.com/paulmach/go.geojson)\n\nGo.geojson is a package for **encoding and decoding** [GeoJSON](http://geojson.org/) into Go structs.\nSupports both the [json.Marshaler](http://golang.org/pkg/encoding/json/#Marshaler) and [json.Unmarshaler](http://golang.org/pkg/encoding/json/#Unmarshaler)\ninterfaces as well as [sql.Scanner](http://golang.org/pkg/database/sql/#Scanner) for directly scanning PostGIS query results.\nThe package also provides helper functions such as `UnmarshalFeatureCollection`, `UnmarshalFeature` and `UnmarshalGeometry`.\n\n### Deprecated, use [orb/geojson](https://github.com/paulmach/orb/tree/master/geojson)\nThe [orb](https://github.com/paulmach/orb) package, and its subpackages, provide all the features here and more.\n\n## Examples\n\n* #### Unmarshalling  (JSON -\u003e Go)\n\n\tgo.geojson supports both the [json.Marshaler](http://golang.org/pkg/encoding/json/#Marshaler) and [json.Unmarshaler](http://golang.org/pkg/encoding/json/#Unmarshaler) interfaces as well as helper functions such as `UnmarshalFeatureCollection`, `UnmarshalFeature` and `UnmarshalGeometry`.\n\n\t\t// Feature Collection\n\t\trawFeatureJSON := []byte(`\n\t\t  { \"type\": \"FeatureCollection\",\n\t\t    \"features\": [\n\t\t      { \"type\": \"Feature\",\n\t\t        \"geometry\": {\"type\": \"Point\", \"coordinates\": [102.0, 0.5]},\n\t\t        \"properties\": {\"prop0\": \"value0\"}\n\t\t      }\n\t\t    ]\n\t\t  }`)\n\n\t\tfc1, err := geojson.UnmarshalFeatureCollection(rawFeatureJSON)\n\n\t\tfc2 := geojson.NewFeatureCollection()\n\t\terr := json.Unmarshal(rawJSON, fc2)\n\n\t\t// Geometry\n\t\trawGeometryJSON := []byte(`{\"type\": \"Point\", \"coordinates\": [102.0, 0.5]}`)\n\t\tg, err := geojson.UnmarshalGeometry(rawGeometryJSON)\n\n\t\tg.IsPoint() == true\n\t\tg.Point == []float64{102.0, 0.5}\n\n* #### Marshalling (Go -\u003e JSON)\n\n\t\tg := geojson.NewPointGeometry([]float64{1, 2})\n\t\trawJSON, err := g.MarshalJSON()\n\n\t\tfc := geojson.NewFeatureCollection()\n\t\tfc.AddFeature(geojson.NewPointFeature([]float64{1,2}))\n\t\trawJSON, err := fc.MarshalJSON()\n\n* #### Scanning PostGIS query results\n\n\t\trow := db.QueryRow(\"SELECT ST_AsGeoJSON(the_geom) FROM postgis_table)\n\n\t\tvar geometry *geojson.Geometry\n\t\trow.Scan(\u0026geometry)\n\n* #### Dealing with different Geometry types\n\n\tA geometry can be of several types, causing problems in a statically typed language.\n\tThus there is a separate attribute on Geometry for each type.\n\tSee the [Geometry object](https://godoc.org/github.com/paulmach/go.geojson#Geometry) for more details.\n\n\t\tg := geojson.UnmarshalGeometry([]byte(`\n\t\t\t{\n\t          \"type\": \"LineString\",\n\t          \"coordinates\": [\n\t            [102.0, 0.0], [103.0, 1.0], [104.0, 0.0], [105.0, 1.0]\n\t          ]\n\t        }`))\n\n\t\tswitch {\n\t\tcase g.IsPoint():\n\t\t\t// do something with g.Point\n\t\tcase g.IsLineString():\n\t\t\t// do something with g.LineString\n\t\t}\n\n## Feature Properties\n\nGeoJSON [Features](http://geojson.org/geojson-spec.html#feature-objects) can have properties of any type.\nThis can cause issues in a statically typed language such as Go.\nSo, included are some helper methods on the Feature object to ease the pain.\n\n\t// functions to do the casting for you\n\tfunc (f Feature) PropertyBool(key string) (bool, error) {\n\tfunc (f Feature) PropertyInt(key string) (int, error) {\n\tfunc (f Feature) PropertyFloat64(key string) (float64, error) {\n\tfunc (f Feature) PropertyString(key string) (string, error) {\n\n\t// functions that hide the error and let you define default\n\tfunc (f Feature) PropertyMustBool(key string, def ...bool) bool {\n\tfunc (f Feature) PropertyMustInt(key string, def ...int) int {\n\tfunc (f Feature) PropertyMustFloat64(key string, def ...float64) float64 {\n\tfunc (f Feature) PropertyMustString(key string, def ...string) string {\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpaulmach%2Fgo.geojson","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpaulmach%2Fgo.geojson","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpaulmach%2Fgo.geojson/lists"}