{"id":26678952,"url":"https://github.com/pchchv/osm","last_synced_at":"2026-04-24T21:31:14.038Z","repository":{"id":278153626,"uuid":"934689287","full_name":"pchchv/osm","owner":"pchchv","description":"General purpose package for reading, writing and working with OpenStreetMap data","archived":false,"fork":false,"pushed_at":"2025-04-14T06:19:45.000Z","size":97991,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-15T14:39:45.308Z","etag":null,"topics":["geojson","go","go-lib","go-library","go-package","golang","golang-library","golang-package","map","openstreetmap","osm","osmapi","osmpbf","pbf","xml"],"latest_commit_sha":null,"homepage":"https://pkg.go.dev/github.com/pchchv/osm","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pchchv.png","metadata":{"files":{"readme":"README.md","changelog":"change.go","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,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-02-18T08:48:51.000Z","updated_at":"2025-04-14T07:11:06.000Z","dependencies_parsed_at":null,"dependency_job_id":"0b8ca372-1bbd-483e-aeb6-1074c8c1c0a6","html_url":"https://github.com/pchchv/osm","commit_stats":null,"previous_names":["pchchv/osm"],"tags_count":12,"template":false,"template_full_name":null,"purl":"pkg:github/pchchv/osm","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pchchv%2Fosm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pchchv%2Fosm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pchchv%2Fosm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pchchv%2Fosm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pchchv","download_url":"https://codeload.github.com/pchchv/osm/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pchchv%2Fosm/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32241529,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-24T13:21:15.438Z","status":"ssl_error","status_checked_at":"2026-04-24T13:21:15.005Z","response_time":64,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["geojson","go","go-lib","go-library","go-package","golang","golang-library","golang-package","map","openstreetmap","osm","osmapi","osmpbf","pbf","xml"],"created_at":"2025-03-26T05:17:45.932Z","updated_at":"2026-04-24T21:31:14.033Z","avatar_url":"https://github.com/pchchv.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# OSM [![CI](https://github.com/pchchv/osm/workflows/CI/badge.svg)](https://github.com/pchchv/osm/actions?query=workflow%3ACI+event%3Apush) [![Go Report Card](https://goreportcard.com/badge/github.com/pchchv/osm)](https://goreportcard.com/report/github.com/pchchv/osm) [![Godoc Reference](https://pkg.go.dev/badge/github.com/pchchv/osm)](https://pkg.go.dev/github.com/pchchv/osm)\n\n**OSM** package is a general purpose library for reading, writing and working with [OpenStreetMap](https://osm.org) data in Go.   \nIt has the ability to:\n- read/write [OSM XML](https://wiki.openstreetmap.org/wiki/OSM_XML)\n- read/write [OSM JSON](https://wiki.openstreetmap.org/wiki/OSM_JSON), a format returned by the Overpass API.\n- efficiently parse [OSM PBF](https://wiki.openstreetmap.org/wiki/PBF_Format) data files available at [planet.osm.org](https://planet.osm.org/)\n\nMade available by the package are the following types:\n- Node\n- Way\n- Relation\n- Changeset\n- Note\n- User\n\nFollowing “container” types:\n- OSM - container returned via API\n- Change - used by the replication API\n- Diff - corresponds to [Overpass Augmented Diffs](https://wiki.openstreetmap.org/wiki/Overpass_API/Augmented_Diffs)\n\n## Concepts\n\nIn the `osm` package, the core OSM data types are referred **Objects**. The Node, Way, Relation, Changeset, Note and User types implement the `osm.Object` interface and can be referenced using the `osm.ObjectID` type. As a result, it is possible to have a `[]osm.Object` slice containing nodes, changesets and users.\n\nIndividual versions of the core OSM map data types are referred **Elements**, and the set of versions for a given Node, Way or Relation is referred a **Feature**. For example, `osm.ElementID` might refer to \"Node with ID 10 and version 3\" and `osm.FeatureID` might refer to \"all versions of a node with ID 10\". In another way, features represent a road and how it has changed over time, and an element is a specific version of that feature.\n\nA number of helper methods are provided for working with features and elements. The idea is to simplify working with, for example, Way and its member nodes.\n\n## Working with JSON\n\n`osm` package supports reading and writing [OSM JSON](https://wiki.openstreetmap.org/wiki/OSM_JSON). This format is returned by the Overpass API and can be optionally returned by the [OSM API](https://wiki.openstreetmap.org/wiki/API_v0.6#JSON_Format).\n\nIf performance is important, third party \"encoding/json\" replacements such as [github.com/json-iterator/go](https://github.com/json-iterator/go) are supported.  \nThey can be enabled with something like this:\n\n```go\nimport (\n  jsoniter \"github.com/json-iterator/go\"\n  \"github.com/pchchv/osm\"\n)\n\nvar c = jsoniter.Config{\n  EscapeHTML:              true,\n  SortMapKeys:             false,\n  MarshalFloatWith6Digits: true,\n}.Froze()\n\nosm.CustomJSONMarshaler = c\nosm.CustomJSONUnmarshaler = c\n```\n\nThe above change can have significant performance implications, see the benchmarks below on a large OSM Change object.\n\n```\nbenchmark                            old ns/op     new ns/op     delta\nBenchmarkChange_MarshalJSON-12       604496        461349        -23.68%\nBenchmarkChange_UnmarshalJSON-12     1633834       1051630       -35.63%\n\nbenchmark                            old allocs    new allocs    delta\nBenchmarkChange_MarshalJSON-12       1277          1081          -15.35%\nBenchmarkChange_UnmarshalJSON-12     5133          8580          +67.15%\n\nbenchmark                            old bytes     new bytes     delta\nBenchmarkChange_MarshalJSON-12       180583        162727        -9.89%\nBenchmarkChange_UnmarshalJSON-12     287707        317723        +10.43%\n```\n\n## Scanning large data files\n\nFor small data it is possible to use the `encoding/xml` package in the Go stdlib to marshal/unmarshal the data. This is typically done using the `osm.OSM` or `osm.Change` \"container\" structs.\n\nFor large data the package defines the `Scanner` interface implemented in both the [osmxml](osmxml) and [osmpbf](osmpbf) sub-packages.\n\n```go\ntype osm.Scanner interface {\n\tScan() bool\n\tObject() osm.Object\n\tErr() error\n\tClose() error\n}\n```\n\nThis interface is designed to mimic the [bufio.Scanner](https://golang.org/pkg/bufio/#Scanner)\ninterface found in the Go standard library.\n\nExample usage:\n\n```go\nf, err := os.Open(\"./delaware-latest.osm.pbf\")\nif err != nil {\n\tpanic(err)\n}\ndefer f.Close()\n\nscanner := osmpbf.New(context.Background(), f, 3)\ndefer scanner.Close()\n\nfor scanner.Scan() {\n\to := scanner.Object()\n\t// do something\n}\n\nscanErr := scanner.Err()\nif scanErr != nil {\n\tpanic(scanErr)\n}\n```\n\n**Note:** Scanners are **not** safe for parallel use. Objects must be fed into the channel and workers must read from it.\n\n## CGO and zlib\n\nOSM PBF data comes in blocks, each block is zlib compressed. Decompressing this data takes about 33% of the total read time. [DataDog/czlib](https://github.com/DataDog/czlib) is used to speed this process. See [osmpbf/README.md](osmpbf#using-cgoczlib-for-decompression) for more details.\n\nAs a result, a C compiler is necessary to install this module. On macOS this may require installing pkg-config using something like `brew install pkg-config`\n\nCGO can be disabled at build time using the `CGO_ENABLED` ENV variable. For example, `CGO_ENABLED=0 go build`. The code will fallback to the stdlib implementation of zlib.\n\n## List of sub-package utilities\n\n- [`osmapi`](osmapi) - supports all the v0.6 read/data endpoints\n- [`osmpbf`](osmpbf) - stream processing of `*.osm.pbf` files\n- [`osmxml`](osmxml) - stream processing of `*.osm` xml files\n- [`annotate`](annotate) - adds lon/lat, version, changeset and orientation data to way and relation members\n- [`osmgeojson`](osmgeojson) - converts OSM data to GeoJSON\n- [`replication`](replication) - fetch replication state and change files","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpchchv%2Fosm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpchchv%2Fosm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpchchv%2Fosm/lists"}