{"id":13413004,"url":"https://github.com/peterstace/simplefeatures","last_synced_at":"2026-01-30T06:19:17.686Z","repository":{"id":36458399,"uuid":"190707346","full_name":"peterstace/simplefeatures","owner":"peterstace","description":"Simple Features is a pure Go Implementation of the OpenGIS Simple Feature Access Specification","archived":false,"fork":false,"pushed_at":"2024-05-22T19:30:42.000Z","size":2530,"stargazers_count":119,"open_issues_count":47,"forks_count":19,"subscribers_count":8,"default_branch":"master","last_synced_at":"2024-05-23T04:15:42.284Z","etag":null,"topics":["2d","geometry","gis","go","golang","libgeos","library","opengis","postgis","spatial-analysis"],"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/peterstace.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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}},"created_at":"2019-06-07T07:52:01.000Z","updated_at":"2024-05-30T22:14:05.980Z","dependencies_parsed_at":"2023-09-26T22:58:32.291Z","dependency_job_id":"58801afc-0344-4ad6-988a-6e7930500b5b","html_url":"https://github.com/peterstace/simplefeatures","commit_stats":{"total_commits":1534,"total_committers":12,"mean_commits":"127.83333333333333","dds":0.09126466753585394,"last_synced_commit":"24d34187d2b337f975580b04f32cca7d34dd86e0"},"previous_names":[],"tags_count":59,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peterstace%2Fsimplefeatures","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peterstace%2Fsimplefeatures/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peterstace%2Fsimplefeatures/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peterstace%2Fsimplefeatures/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/peterstace","download_url":"https://codeload.github.com/peterstace/simplefeatures/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243635207,"owners_count":20322897,"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","geometry","gis","go","golang","libgeos","library","opengis","postgis","spatial-analysis"],"created_at":"2024-07-30T20:01:32.209Z","updated_at":"2026-01-30T06:19:17.676Z","avatar_url":"https://github.com/peterstace.png","language":"Go","funding_links":[],"categories":["Geographic","地理","Relational Databases"],"sub_categories":["Search and Analytic Databases","检索及分析资料库","Advanced Console UIs"],"readme":"# Simple Features\n\n[![Documentation](https://img.shields.io/badge/go.dev-reference-007d9c?logo=go\u0026logoColor=white\u0026style=flat)](https://pkg.go.dev/github.com/peterstace/simplefeatures/geom?tab=doc)\n[![Build Status](https://github.com/peterstace/simplefeatures/workflows/build/badge.svg)](https://github.com/peterstace/simplefeatures/actions)\n[![Go Report\nCard](https://goreportcard.com/badge/github.com/peterstace/simplefeatures)](https://goreportcard.com/report/github.com/peterstace/simplefeatures)\n[![Coverage\nStatus](https://coveralls.io/repos/github/peterstace/simplefeatures/badge.svg?branch=master)](https://coveralls.io/github/peterstace/simplefeatures?branch=master)\n\nSimple Features is a 2D geometry library that provides Go types that model\ngeometries, as well as algorithms that operate on them.\n\nIt's a pure Go Implementation of the OpenGIS Consortium's Simple\nFeature Access Specification (which can be found\n[here](http://www.opengeospatial.org/standards/sfa)). This is the same\nspecification that [GEOS](https://trac.osgeo.org/geos),\n[JTS](https://locationtech.github.io/jts/), and [PostGIS](https://postgis.net/)\nimplement, so the Simple Features API will be familiar to developers who have\nused those libraries before.\n\n#### Table of Contents\n\n- [Geometry Types](#geometry-types)\n- [Marshalling and Unmarshalling](#marshalling-and-unmarshalling)\n- [Geometry Algorithms](#geometry-algorithms)\n- [GEOS Wrapper](#geos-wrapper)\n- [PROJ Wrapper](#proj-wrapper)\n- [Examples](#examples)\n\n### Geometry Types\n\n\u003ctable\u003e\n\n\u003cthead\u003e\n\u003ctr\u003e\n\u003cth\u003eType\u003c/th\u003e\n\u003cth\u003eExample\u003c/th\u003e\n\u003cth\u003eDescription\u003c/th\u003e\n\u003c/tr\u003e\n\u003c/thead\u003e\n\n\u003ctr\u003e\n\u003ctd\u003e\u003ca href=\"https://pkg.go.dev/github.com/peterstace/simplefeatures/geom#Point\"\u003ePoint\u003c/a\u003e\u003c/td\u003e\n\u003ctd\u003e\u003ca href=\"https://commons.wikimedia.org/wiki/File:SFA_Point.svg\"\u003e\u003cimg width=51 height=51 src=\"https://upload.wikimedia.org/wikipedia/commons/c/c2/SFA_Point.svg\"\u003e\u003c/a\u003e\u003c/td\u003e\n\u003ctd\u003ePoint is a single location in space.\u003c/td\u003e\n\u003c/tr\u003e\n\n\u003ctr\u003e\n\u003ctd\u003e\u003ca href=\"https://pkg.go.dev/github.com/peterstace/simplefeatures/geom#MultiPoint\"\u003eMultiPoint\u003c/a\u003e\u003c/td\u003e\n\u003ctd\u003e\u003ca href=\"https://commons.wikimedia.org/wiki/File:SFA_MultiPoint.svg\"\u003e\u003cimg width=51 height=51  src=\"https://upload.wikimedia.org/wikipedia/commons/d/d6/SFA_MultiPoint.svg\"\u003e\u003c/a\u003e\u003c/td\u003e\n\u003ctd\u003eMultiPoint is collection of points in space.\u003c/td\u003e\n\u003c/tr\u003e\n\n\u003ctr\u003e\n\u003ctd\u003e\u003ca href=\"https://pkg.go.dev/github.com/peterstace/simplefeatures/geom#LineString\"\u003eLineString\u003c/a\u003e\u003c/td\u003e\n\u003ctd\u003e\u003ca href=\"https://commons.wikimedia.org/wiki/File:SFA_LineString.svg\"\u003e\u003cimg width=51 height=51  src=\"https://upload.wikimedia.org/wikipedia/commons/b/b9/SFA_LineString.svg\"\u003e\u003c/a\u003e\u003c/td\u003e\n\u003ctd\u003eLineString is curve defined by linear interpolation between a set of\ncontrol points.\u003c/td\u003e\n\u003c/tr\u003e\n\n\u003ctr\u003e\n\u003ctd\u003e\u003ca href=\"https://pkg.go.dev/github.com/peterstace/simplefeatures/geom#MultiLineString\"\u003eMultiLineString\u003c/a\u003e\u003c/td\u003e\n\u003ctd\u003e\u003ca href=\"https://commons.wikimedia.org/wiki/File:SFA_MultiLineString.svg\"\u003e\u003cimg width=51 height=51  src=\"https://upload.wikimedia.org/wikipedia/commons/8/86/SFA_MultiLineString.svg\"\u003e\u003c/a\u003e\u003c/td\u003e\n\u003ctd\u003eMultiLineString is a collection of LineStrings.\u003c/td\u003e\n\u003c/tr\u003e\n\n\u003ctr\u003e\n\u003ctd\u003e\u003ca href=\"https://pkg.go.dev/github.com/peterstace/simplefeatures/geom#Polygon\"\u003ePolygon\u003c/a\u003e\u003c/td\u003e\n\u003ctd\u003e\u003ca href=\"https://commons.wikimedia.org/wiki/File:SFA_Polygon.svg\"\u003e\u003cimg width=51 height=51  src=\"https://upload.wikimedia.org/wikipedia/commons/5/55/SFA_Polygon_with_hole.svg\"\u003e\u003c/a\u003e\u003c/td\u003e\n\u003ctd\u003ePolygon is a planar surface geometry that bounds some area. It may have holes.\u003c/td\u003e\n\u003c/tr\u003e\n\n\u003ctr\u003e\n\u003ctd\u003e\u003ca href=\"https://pkg.go.dev/github.com/peterstace/simplefeatures/geom#MultiPolygon\"\u003eMultiPolygon\u003c/a\u003e\u003c/td\u003e\n\u003ctd\u003e\u003ca href=\"https://commons.wikimedia.org/wiki/File:SFA_MultiPolygon.svg\"\u003e\u003cimg width=51 height=51  src=\"https://upload.wikimedia.org/wikipedia/commons/3/3b/SFA_MultiPolygon_with_hole.svg\"\u003e\u003c/a\u003e\u003c/td\u003e\n\u003ctd\u003eMultiPolygon is collection of Polygons (with some constraints on how the Polygons interact with each other).\u003c/td\u003e\n\u003c/tr\u003e\n\n\u003ctr\u003e\n\u003ctd\u003e\u003ca href=\"https://pkg.go.dev/github.com/peterstace/simplefeatures/geom#GeometryCollection\"\u003eGeometryCollection\u003c/a\u003e\u003c/td\u003e\n\u003ctd\u003e\u003ca href=\"https://commons.wikimedia.org/wiki/File:SFA_GeometryCollection.svg\"\u003e\u003cimg width=51 height=51  src=\"https://upload.wikimedia.org/wikipedia/commons/1/1d/SFA_GeometryCollection.svg\"\u003e\u003c/a\u003e\u003c/td\u003e\n\u003ctd\u003eGeometryCollection is an unconstrained collection of geometries.\u003c/td\u003e\n\u003c/tr\u003e\n\n\u003ctr\u003e\n\u003ctd\u003e\u003ca href=\"https://pkg.go.dev/github.com/peterstace/simplefeatures/geom#Geometry\"\u003eGeometry\u003c/a\u003e\u003c/td\u003e\n\u003ctd\u003e\u003ca href=\"https://commons.wikimedia.org/wiki/File:SFA_Polygon.svg\"\u003e\u003cimg width=51 height=51  src=\"https://upload.wikimedia.org/wikipedia/commons/5/55/SFA_Polygon_with_hole.svg\"\u003e\u003c/a\u003e\u003c/td\u003e\n\u003ctd\u003eGeometry holds any type of geometry (Point, MultiPoint, LineString, MultiLineString, Polygon, MultiPolygon, or GeometryCollection). It's the type that the Simple Features library uses when it needs to represent geometries in a generic way.\u003c/td\u003e\n\u003c/tr\u003e\n\n\u003ctr\u003e\n\u003ctd\u003e\u003ca href=\"https://pkg.go.dev/github.com/peterstace/simplefeatures/geom#Envelope\"\u003eEnvelope\u003c/a\u003e\u003c/td\u003e\n\u003ctd\u003e\u003cimg src=\"./.ci/assets/envelope.svg\"\u003e\u003c/td\u003e\n\u003ctd\u003eEnvelope is an axis aligned bounding box typically used to describe the spatial extent of other geometric entities.\u003c/td\u003e\n\u003c/tr\u003e\n\n\u003c/table\u003e\n\n### Marshalling and Unmarshalling\n\nSimple features supports the following external geometry representation formats:\n\n| Format  | Example                                                              | Description                                                                                                                                                                                                                                                                                                                                                        |\n| ---     | ---                                                                  | ---                                                                                                                                                                                                                                                                                                                                                                |\n| WKT     | `POLYGON((0 0,0 1,1 1,1 0,0 0))`                                     | [Well Known Text](https://en.wikipedia.org/wiki/Well-known_text_representation_of_geometry) is a human readable format for storing geometries. It's often the lowest common denominator geometry format, and is useful for integration with other GIS applications.                                                                                                |\n| WKB     | `\u003cbinary\u003e`                                                           | [Well Known Binary](https://en.wikipedia.org/wiki/Well-known_text_representation_of_geometry#Well-known_binary) is a machine readable format that is efficient for computers to use (both from a processing and storage space perspective). WKB is a good choice for transferring geometries to and from PostGIS and other databases that support geometric types. |\n| GeoJSON | `{\"type\":\"Polygon\",\"coordinates\":[[[0,0],[0,1],[1,1],[1,0],[0,0]]]}` | [GeoJSON](https://en.wikipedia.org/wiki/GeoJSON) represents geometries in a similar way to WKB, but is based on the JSON format. This makes it ideal to use with web APIs or other situations where JSON would normally be used.                                                                                                                                   |\n| TWKB    | `\u003cbinary\u003e`                                                           | [Tiny Well Known Binary](https://github.com/TWKB/Specification) is a multi-purpose compressed binary format for serialising vector geometries into a stream of bytes. It emphasises minimising the size of the serialised representation. It's a good choice when space is at a premium (e.g. for storage within a web token).                                     |\n\n### Geometry Algorithms\n\nThe following algorithms are supported:\n\n| Miscellaneous Algorithms                                                                               | Description                                                                            |\n| ---                                                                                                    | ---                                                                                    |\n| [Area](https://pkg.go.dev/github.com/peterstace/simplefeatures/geom#Geometry.Area)                     | Finds the area of the geometry (for Polygons and MultiPolygons).                       |\n| [Centroid](https://pkg.go.dev/github.com/peterstace/simplefeatures/geom#Geometry.Centroid)             | Finds the centroid of the geometry.                                                    |\n| [ConvexHull](https://pkg.go.dev/github.com/peterstace/simplefeatures/geom#Geometry.ConvexHull)         | Finds the convex hull of the geometry.                                                 |\n| [Distance](https://pkg.go.dev/github.com/peterstace/simplefeatures/geom#Distance)                      | Finds the shortest distance between two geometries.                                    |\n| [Envelope](https://pkg.go.dev/github.com/peterstace/simplefeatures/geom#Geometry.Envelope)             | Finds the smallest axis-aligned bounding-box that surrounds the geometry.              |\n| [ExactEquals](https://pkg.go.dev/github.com/peterstace/simplefeatures/geom#ExactEquals)                | Determines if two geometries are structurally equal.                                   |\n| [Length](https://pkg.go.dev/github.com/peterstace/simplefeatures/geom#Geometry.Length)                 | Finds the length of the geometry (for LineStrings and MultiLineStrings).               |\n| [PointOnSurface](https://pkg.go.dev/github.com/peterstace/simplefeatures/geom#Geometry.PointOnSurface) | Finds a point that lies inside the geometry.                                           |\n| [Relate](https://pkg.go.dev/github.com/peterstace/simplefeatures/geom#Relate)                          | Calculates the DE-9IM intersection describing the relationship between two geometries. |\n| [Simplify](https://pkg.go.dev/github.com/peterstace/simplefeatures/geom#Simplify)                      | Simplifies a geometry using the Ramer–Douglas–Peucker algorithm.                       |\n\n| Set Operations                                                                                          | Description                                                               |\n| ---                                                                                                     | ---                                                                       |\n| [Union](https://pkg.go.dev/github.com/peterstace/simplefeatures/geom#Union)                             | Joins the parts from two geometries together.                             |\n| [Intersection](https://pkg.go.dev/github.com/peterstace/simplefeatures/geom#Intersection)               | Finds the parts of two geometries that are in common.                     |\n| [Difference](https://pkg.go.dev/github.com/peterstace/simplefeatures/geom#Difference)                   | Finds the parts of a geometry that are not also part of another geometry. |\n| [SymmetricDifference](https://pkg.go.dev/github.com/peterstace/simplefeatures/geom#SymmetricDifference) | Finds the parts of two geometries that are not in common.                 |\n\n\n| Named Spatial Predicates                                                              | Description                                             |\n| ---                                                                                   | ---                                                     |\n| [Equals](https://pkg.go.dev/github.com/peterstace/simplefeatures/geom#Equals)         | Determines if two geometries are topologically equal.   |\n| [Intersects](https://pkg.go.dev/github.com/peterstace/simplefeatures/geom#Intersects) | Determines if two geometries intersect with each other. |\n| [Disjoint](https://pkg.go.dev/github.com/peterstace/simplefeatures/geom#Disjoint)     | Determines if two geometries have no common points.     |\n| [Contains](https://pkg.go.dev/github.com/peterstace/simplefeatures/geom#Contains)     | Determines if one geometry contains another.            |\n| [CoveredBy](https://pkg.go.dev/github.com/peterstace/simplefeatures/geom#CoveredBy)   | Determines if one geometry is covered by another.       |\n| [Covers](https://pkg.go.dev/github.com/peterstace/simplefeatures/geom#Covers)         | Determines if one geometry covers another.              |\n| [Overlaps](https://pkg.go.dev/github.com/peterstace/simplefeatures/geom#Overlaps)     | Determines if one geometry overlaps another.            |\n| [Touches](https://pkg.go.dev/github.com/peterstace/simplefeatures/geom#Touches)       | Determines if one geometry touches another.             |\n| [Within](https://pkg.go.dev/github.com/peterstace/simplefeatures/geom#Within)         | Determines if one geometry is within another.           |\n| [Crosses](https://pkg.go.dev/github.com/peterstace/simplefeatures/geom#Crosses)       | Determines if one geometry crosses another.             |\n\n### GEOS Wrapper\n\nA [GEOS](https://www.osgeo.org/projects/geos/) CGO wrapper is also provided,\ngiving access to functionality not yet implemented natively in Go. The [wrapper\nis implemented in a separate\npackage](https://pkg.go.dev/github.com/peterstace/simplefeatures/geos?tab=doc),\nmeaning that library users who don't need this additional functionality don't\nneed to expose themselves to CGO.\n\n### PROJ Wrapper\n\nA [PROJ](https://proj.org/) CGO wrapper is also provided, giving access to a\nvast array of transformations between various coordinate reference systems.\nThe [wrapper is implemented in a separate\npackage](https://pkg.go.dev/github.com/peterstace/simplefeatures/proj?tab=doc),\nmeaning that library users who don't need this additional functionality don't\nneed to expose themselves to CGO.\n\n### Examples\n\nThe following examples show some common operations (errors are omitted for\nbrevity).\n\n#### WKT\n\nEncoding and decoding WKT:\n\n```go\n// Unmarshal from WKT\ninput := \"POLYGON((0 0,0 1,1 1,1 0,0 0))\"\ng, _ := geom.UnmarshalWKT(input)\n\n// Marshal to WKT\noutput := g.AsText()\nfmt.Println(output) // Prints: POLYGON((0 0,0 1,1 1,1 0,0 0))\n```\n\n#### WKB\n\nEncoding and decoding WKB directly:\n\n```go\n// Marshal as WKB\ncoords := geom.Coordinates{XY: geom.XY{1.5, 2.5}}\npt := geom.NewPoint(coords)\nwkb := pt.AsBinary()\nfmt.Println(wkb) // Prints: [1 1 0 0 0 0 0 0 0 0 0 248 63 0 0 0 0 0 0 4 64]\n\n// Unmarshal from WKB\nfromWKB, _ := geom.UnmarshalWKB(wkb)\nfmt.Println(fromWKB.AsText()) // POINT(1.5 2.5)\n```\n\nEncoding and decoding WKB for integration with PostGIS:\n\n```go\ndb, _ := sql.Open(\"postgres\", \"postgres://...\")\n\ndb.Exec(`\n    CREATE TABLE my_table (\n        my_geom geometry(geometry, 4326),\n        population double precision\n    )`,\n)\n\n// Insert our geometry and population data into PostGIS via WKB.\ncoords := geom.Coordinates{XY: geom.XY{-74.0, 40.7}}\nnyc := geom.NewPoint(coords)\ndb.Exec(`\n    INSERT INTO my_table\n    (my_geom, population)\n    VALUES (ST_GeomFromWKB($1, 4326), $2)`,\n    nyc, 8.4e6,\n)\n\n// Get the geometry and population data back out of PostGIS via WKB.\nvar location geom.Geometry\nvar population float64\ndb.QueryRow(`\n    SELECT ST_AsBinary(my_geom), population\n    FROM my_table LIMIT 1`,\n).Scan(\u0026location, \u0026population)\nfmt.Println(location.AsText(), population) // Prints: POINT(-74 40.7) 8.4e+06\n```\n\n#### GeoJSON\n\nEncoding and decoding GeoJSON directly:\n\n```go\n// Unmarshal geometry from GeoJSON.\nraw := `{\"type\":\"Point\",\"coordinates\":[-74.0,40.7]}`\nvar g geom.Geometry\njson.NewDecoder(strings.NewReader(raw)).Decode(\u0026g)\nfmt.Println(g.AsText()) // Prints: POINT(-74 40.7)\n\n// Marshal back to GeoJSON.\nenc := json.NewEncoder(os.Stdout)\nenc.Encode(g) // Prints: {\"type\":\"Point\",\"coordinates\":[-74,40.7]}\n```\n\nGeometries can also be part of larger structs:\n\n```go\ntype CityPopulation struct {\n    Location   geom.Geometry `json:\"loc\"`\n    Population int           `json:\"pop\"`\n}\n\n// Unmarshal geometry from GeoJSON.\nraw := `{\"loc\":{\"type\":\"Point\",\"coordinates\":[-74.0,40.7]},\"pop\":8400000}`\nvar v CityPopulation\njson.NewDecoder(strings.NewReader(raw)).Decode(\u0026v)\nfmt.Println(v.Location.AsText()) // Prints: POINT(-74 40.7)\nfmt.Println(v.Population)        // Prints: 8400000\n\n// Marshal back to GeoJSON.\nenc := json.NewEncoder(os.Stdout)\nenc.Encode(v) // Prints: {\"loc\":{\"type\":\"Point\",\"coordinates\":[-74,40.7]},\"pop\":8400000}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpeterstace%2Fsimplefeatures","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpeterstace%2Fsimplefeatures","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpeterstace%2Fsimplefeatures/lists"}