{"id":13413755,"url":"https://github.com/paulmach/orb","last_synced_at":"2025-05-14T03:08:31.899Z","repository":{"id":39815437,"uuid":"54856356","full_name":"paulmach/orb","owner":"paulmach","description":"Types and utilities for working with 2d geometry in Golang","archived":false,"fork":false,"pushed_at":"2024-08-07T15:43:29.000Z","size":1508,"stargazers_count":961,"open_issues_count":19,"forks_count":110,"subscribers_count":21,"default_branch":"master","last_synced_at":"2025-04-03T12:04:59.694Z","etag":null,"topics":["2d","geo","geojson","geospatial","gis","mapbox-vector-tile","wkb","wkt"],"latest_commit_sha":null,"homepage":"","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":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","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}},"created_at":"2016-03-28T01:19:01.000Z","updated_at":"2025-04-03T02:38:42.000Z","dependencies_parsed_at":"2024-10-30T13:00:34.445Z","dependency_job_id":"949bb9d2-5ec1-4109-93a4-312057f4ec97","html_url":"https://github.com/paulmach/orb","commit_stats":{"total_commits":284,"total_committers":26,"mean_commits":"10.923076923076923","dds":0.4823943661971831,"last_synced_commit":"1568d95d1bb8a0e5a1a3c318ca22b72fd39a1128"},"previous_names":[],"tags_count":25,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paulmach%2Forb","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paulmach%2Forb/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paulmach%2Forb/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paulmach%2Forb/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/paulmach","download_url":"https://codeload.github.com/paulmach/orb/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248261933,"owners_count":21074226,"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":["2d","geo","geojson","geospatial","gis","mapbox-vector-tile","wkb","wkt"],"created_at":"2024-07-30T20:01:48.272Z","updated_at":"2025-04-10T17:19:31.861Z","avatar_url":"https://github.com/paulmach.png","language":"Go","readme":"# orb [![CI](https://github.com/paulmach/orb/workflows/CI/badge.svg)](https://github.com/paulmach/orb/actions?query=workflow%3ACI+event%3Apush) [![codecov](https://codecov.io/gh/paulmach/orb/branch/master/graph/badge.svg?token=NuuTjLVpKW)](https://codecov.io/gh/paulmach/orb) [![Go Report Card](https://goreportcard.com/badge/github.com/paulmach/orb)](https://goreportcard.com/report/github.com/paulmach/orb) [![Go Reference](https://pkg.go.dev/badge/github.com/paulmach/orb.svg)](https://pkg.go.dev/github.com/paulmach/orb)\n\nPackage `orb` defines a set of types for working with 2d geo and planar/projected geometric data in Golang.\nThere are a set of sub-packages that use these types to do interesting things.\nThey each provide their own README with extra info.\n\n## Interesting features\n\n-   **Simple types** - allow for natural operations using the `make`, `append`, `len`, `[s:e]` builtins.\n-   **GeoJSON** - support as part of the [`geojson`](geojson) sub-package.\n-   **Mapbox Vector Tile** - encoding and decoding as part of the [`encoding/mvt`](encoding/mvt) sub-package.\n-   **Direct to type from DB query results** - by scanning WKB data directly into types.\n-   **Rich set of sub-packages** - including [`clipping`](clip), [`simplifing`](simplify), [`quadtree`](quadtree) and more.\n\n## Type definitions\n\n```go\ntype Point [2]float64\ntype MultiPoint []Point\n\ntype LineString []Point\ntype MultiLineString []LineString\n\ntype Ring LineString\ntype Polygon []Ring\ntype MultiPolygon []Polygon\n\ntype Collection []Geometry\n\ntype Bound struct { Min, Max Point }\n```\n\nDefining the types as slices allows them to be accessed in an idiomatic way\nusing Go's built-in functions such at `make`, `append`, `len`\nand with slice notation like `[s:e]`. For example:\n\n```go\nls := make(orb.LineString, 0, 100)\nls = append(ls, orb.Point{1, 1})\npoint := ls[0]\n```\n\n### Shared `Geometry` interface\n\nAll of the base types implement the `orb.Geometry` interface defined as:\n\n```go\ntype Geometry interface {\n    GeoJSONType() string\n    Dimensions() int // e.g. 0d, 1d, 2d\n    Bound() Bound\n}\n```\n\nThis interface is accepted by functions in the sub-packages which then act on the\nbase types correctly. For example:\n\n```go\nl := clip.Geometry(bound, geom)\n```\n\nwill use the appropriate clipping algorithm depending on if the input is 1d or 2d,\ne.g. a `orb.LineString` or a `orb.Polygon`.\n\nOnly a few methods are defined directly on these type, for example `Clone`, `Equal`, `GeoJSONType`.\nOther operation that depend on geo vs. planar contexts are defined in the respective sub-package.\nFor example:\n\n-   Computing the geo distance between two point:\n\n    ```go\n    p1 := orb.Point{-72.796408, -45.407131}\n    p2 := orb.Point{-72.688541, -45.384987}\n\n    geo.Distance(p1, p2)\n    ```\n\n-   Compute the planar area and centroid of a polygon:\n\n    ```go\n    poly := orb.Polygon{...}\n    centroid, area := planar.CentroidArea(poly)\n    ```\n\n## GeoJSON\n\nThe [geojson](geojson) sub-package implements Marshalling and Unmarshalling of GeoJSON data.\nFeatures are defined as:\n\n```go\ntype Feature struct {\n    ID         interface{}  `json:\"id,omitempty\"`\n    Type       string       `json:\"type\"`\n    Geometry   orb.Geometry `json:\"geometry\"`\n    Properties Properties   `json:\"properties\"`\n}\n```\n\nDefining the geometry as an `orb.Geometry` interface along with sub-package functions\naccepting geometries allows them to work together to create easy to follow code.\nFor example, clipping all the geometries in a collection:\n\n```go\nfc, err := geojson.UnmarshalFeatureCollection(data)\nfor _, f := range fc {\n    f.Geometry = clip.Geometry(bound, f.Geometry)\n}\n```\n\nThe library supports third party \"encoding/json\" replacements\nsuch [github.com/json-iterator/go](https://github.com/json-iterator/go).\nSee the [geojson](geojson) readme for more details.\n\nThe types also support BSON so they can be used directly when working with MongoDB.\n\n## Mapbox Vector Tiles\n\nThe [encoding/mvt](encoding/mvt) sub-package implements Marshalling and\nUnmarshalling [MVT](https://www.mapbox.com/vector-tiles/) data.\nThis package uses sets of `geojson.FeatureCollection` to define the layers,\nkeyed by the layer name. For example:\n\n```go\ncollections := map[string]*geojson.FeatureCollection{}\n\n// Convert to a layers object and project to tile coordinates.\nlayers := mvt.NewLayers(collections)\nlayers.ProjectToTile(maptile.New(x, y, z))\n\n// In order to be used as source for MapboxGL geometries need to be clipped\n// to max allowed extent. (uncomment next line)\n// layers.Clip(mvt.MapboxGLDefaultExtentBound)\n\n// Simplify the geometry now that it's in tile coordinate space.\nlayers.Simplify(simplify.DouglasPeucker(1.0))\n\n// Depending on use-case remove empty geometry, those too small to be\n// represented in this tile space.\n// In this case lines shorter than 1, and areas smaller than 2.\nlayers.RemoveEmpty(1.0, 2.0)\n\n// encoding using the Mapbox Vector Tile protobuf encoding.\ndata, err := mvt.Marshal(layers) // this data is NOT gzipped.\n\n// Sometimes MVT data is stored and transfered gzip compressed. In that case:\ndata, err := mvt.MarshalGzipped(layers)\n```\n\n## Decoding WKB/EWKB from a database query\n\nGeometries are usually returned from databases in WKB or EWKB format. The [encoding/ewkb](encoding/ewkb)\nsub-package offers helpers to \"scan\" the data into the base types directly.\nFor example:\n\n```go\ndb.Exec(\n  \"INSERT INTO postgis_table (point_column) VALUES (ST_GeomFromEWKB(?))\",\n  ewkb.Value(orb.Point{1, 2}, 4326),\n)\n\nrow := db.QueryRow(\"SELECT ST_AsBinary(point_column) FROM postgis_table\")\n\nvar p orb.Point\nerr := row.Scan(ewkb.Scanner(\u0026p))\n```\n\nFor more information see the readme in the [encoding/ewkb](encoding/ewkb) package.\n\n## List of sub-package utilities\n\n-   [`clip`](clip) - clipping geometry to a bounding box\n-   [`encoding/mvt`](encoding/mvt) - encoded and decoding from [Mapbox Vector Tiles](https://www.mapbox.com/vector-tiles/)\n-   [`encoding/wkb`](encoding/wkb) - well-known binary as well as helpers to decode from the database queries\n-   [`encoding/ewkb`](encoding/ewkb) - extended well-known binary format that includes the SRID\n-   [`encoding/wkt`](encoding/wkt) - well-known text encoding\n-   [`geojson`](geojson) - working with geojson and the types in this package\n-   [`maptile`](maptile) - working with mercator map tiles and quadkeys\n-   [`project`](project) - project geometries between geo and planar contexts\n-   [`quadtree`](quadtree) - quadtree implementation using the types in this package\n-   [`resample`](resample) - resample points in a line string geometry\n-   [`simplify`](simplify) - linear geometry simplifications like Douglas-Peucker\n","funding_links":[],"categories":["Miscellaneous","Science and Data Analysis","Go","科学和数据分析","Uncategorized","科学与数据分析","数据分析与数据科学","Geospatial Library","Relational Databases","Parsers \u0026 Generators"],"sub_categories":["Advanced Console UIs","HTTP Clients","Uncategorized","HTTP客户端","查询语","Go","交流"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpaulmach%2Forb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpaulmach%2Forb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpaulmach%2Forb/lists"}