{"id":33204740,"url":"https://github.com/apdevelop/linq2db-postgis-extensions","last_synced_at":"2026-01-14T05:27:39.044Z","repository":{"id":49541613,"uuid":"83205706","full_name":"apdevelop/linq2db-postgis-extensions","owner":"apdevelop","description":".NET Standard 2.0 library with extensions methods for PostGIS geometries methods access with linq2db","archived":false,"fork":false,"pushed_at":"2024-05-09T15:27:50.000Z","size":403,"stargazers_count":24,"open_issues_count":7,"forks_count":5,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-10-24T06:27:37.178Z","etag":null,"topics":["csharp","dotnet","geometry","linq2db","netstandard20","nettopologysuite","npgsql","ogc","postgis","postgresql","spatial"],"latest_commit_sha":null,"homepage":"","language":"C#","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/apdevelop.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}},"created_at":"2017-02-26T12:09:04.000Z","updated_at":"2025-04-28T14:25:33.000Z","dependencies_parsed_at":"2023-01-18T03:01:02.876Z","dependency_job_id":null,"html_url":"https://github.com/apdevelop/linq2db-postgis-extensions","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/apdevelop/linq2db-postgis-extensions","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apdevelop%2Flinq2db-postgis-extensions","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apdevelop%2Flinq2db-postgis-extensions/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apdevelop%2Flinq2db-postgis-extensions/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apdevelop%2Flinq2db-postgis-extensions/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/apdevelop","download_url":"https://codeload.github.com/apdevelop/linq2db-postgis-extensions/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apdevelop%2Flinq2db-postgis-extensions/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28410391,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T01:52:23.358Z","status":"online","status_checked_at":"2026-01-14T02:00:06.678Z","response_time":107,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["csharp","dotnet","geometry","linq2db","netstandard20","nettopologysuite","npgsql","ogc","postgis","postgresql","spatial"],"created_at":"2025-11-16T10:00:19.101Z","updated_at":"2026-01-14T05:27:39.038Z","avatar_url":"https://github.com/apdevelop.png","language":"C#","readme":"# Linq2db PostGIS Extensions\r\n![PostGIS 2.5](https://github.com/apdevelop/linq2db-postgis-extensions/actions/workflows/test_on_postgis-2.5.yml/badge.svg)\r\n![PostGIS 3.0](https://github.com/apdevelop/linq2db-postgis-extensions/actions/workflows/test_on_postgis-3.0.yml/badge.svg)\r\n![PostGIS 3.1](https://github.com/apdevelop/linq2db-postgis-extensions/actions/workflows/test_on_postgis-3.1.yml/badge.svg)\r\n![PostGIS 3.2](https://github.com/apdevelop/linq2db-postgis-extensions/actions/workflows/test_on_postgis-3.2.yml/badge.svg)\r\n\r\n.NET Standard 2.0 library with OGC extensions methods on geometry (`NpgsqlTypes.PostgisGeometry` or `NetTopologySuite.Geometries.Geometry`) instances, providing strongly typed access to [PostGIS](http://postgis.net/) functions on server side while using [linq2db](https://github.com/linq2db/linq2db) LINQ to database provider.\r\n\r\n### Two implementations\r\n\r\n| Property       | LinqToDBPostGisNpgsqlTypes  | LinqToDBPostGisNetTopologySuite      |\r\n| -------------- |:---------------------------:|:------------------------------------:|\r\n| Extending type | `NpgsqlTypes.PostgisGeometry` | `NetTopologySuite.Geometries.Geometry` |\r\n| Npgsql version | 3.x                         | 4.x                                  |\r\n| PostGIS reference version     | 1.5                      | 3.0/3.1/3.2/3.3          |\r\n| Status         | Legacy                      | Active                               |\r\n| NuGet          |   \u0026mdash;       |  [![NuGet](https://img.shields.io/nuget/v/LinqToDBPostGisNTS.svg)](https://www.nuget.org/packages/LinqToDBPostGisNTS/) |\r\n| Dependencies   | linq2db, Npgsql           | linq2db (\u003e= 3.0.0),\u003cbr /\u003eNetTopologySuite (\u003e= 2.0.0),\u003cbr /\u003eNetTopologySuite.IO.PostGis (\u003e= 2.0.0),\u003cbr /\u003eNpgsql (\u003e= 4.1.0),\u003cbr /\u003eNpgsql.NetTopologySuite (\u003e= 4.1.0) |\r\n\r\n### Usage\r\n`NpgsqlTypes.PostgisGeometry` or `NetTopologySuite.Geometries.Geometry` gets additional methods, similar to `Microsoft.SqlServer.Types.SqlGeometry` \r\n[OGC Methods on Geometry Instances](https://docs.microsoft.com/sql/t-sql/spatial-geometry/ogc-methods-on-geometry-instances?view=sql-server-2016) or \r\n[NetTopologySuite plugin for Entity Framework Core for PostgreSQL](https://www.npgsql.org/efcore/mapping/nts.html).\r\nThese methods will be translated into PostGIS SQL operations, so evaluation will happen on the server side. Calling these methods on client side results in throwing `InvalidOperationException`.\r\nNaming convention follows OGC methods names, starting with `ST*` prefix.\r\n\r\nUsing extensions methods inside LINQ expression (Npgsql 4):\r\n\r\n```c#\r\nusing LinqToDBPostGisNetTopologySuite\r\n\r\nusing (var db = new PostGisTestDataConnection())\r\n{\r\n    NetTopologySuite.Geometries.Point point = new Point(new Coordinate(1492853, 6895498)) { SRID = 3857 };\r\n\r\n    var dms = db.Select(() =\u003e GeometryOutput.STAsLatLonText(point));\r\n\r\n    var nearestCity = db.Cities\r\n        .OrderBy(c =\u003e c.Geometry.STDistance(point))\r\n        .FirstOrDefault();\r\n\r\n    var selected = db.Polygons\r\n        .Where(p =\u003e p.Geometry.STArea() \u003e 150.0)\r\n        .OrderBy(p =\u003e p.Geometry.STDistance(point))\r\n        .ToList();\r\n\r\n    var stats = db.Polygons\r\n        .Select(c =\u003e new\r\n             {\r\n                 Id = c.Id,\r\n                 Name = c.Name,\r\n                 Area = c.Geometry.STArea(),\r\n                 Distance = c.Geometry.STDistance(point),\r\n                 NumPoints = c.Geometry.STNPoints(),\r\n                 Srid = c.Geometry.STSrId(),\r\n                 Wkt = c.Geometry.STAsText(),\r\n             })\r\n        .ToList();\r\n}\r\n```\r\n\r\n```c#\r\n[Table(\"test_geometry\", Schema = \"public\")]\r\npublic class PolygonEntity\r\n{\r\n    [Column(\"geom\")]\r\n    public NetTopologySuite.Geometries.Geometry Geometry { get; set; }\r\n}\r\n\r\n[Table(\"owm_cities\", Schema = \"public\")]\r\npublic class CityEntity\r\n{\r\n    [Column(\"geom\")]\r\n    public NetTopologySuite.Geometries.Geometry Geometry { get; set; }\r\n}\r\n\r\nclass PostGisTestDataConnection : LinqToDB.Data.DataConnection\r\n{\r\n    public ITable\u003cPolygonEntity\u003e Polygons { get { return GetTable\u003cPolygonEntity\u003e(); } }\r\n    public ITable\u003cCityEntity\u003e Cities { get { return GetTable\u003cCityEntity\u003e(); } }\r\n}\r\n```\r\n\r\n### Technologies\r\nDeveloped using MS Visual Studio 2019.\r\nTested on PostgreSQL version 9.6/11, PostGIS version 2.5/3.0/3.1/3.2.\r\nDepends on [linq2db](https://github.com/linq2db/linq2db), [Npgsql](https://github.com/npgsql/npgsql).\r\n\r\n### Getting started with demo application\r\n* Make sure you have PostgreSQL DBMS with PostGIS extension installed. Execute `SELECT PostGIS_Full_Version()` query to check PostGIS version.\r\n* Create new database named \"postgistest\" (or any other name), add support of spatial features for this database.\r\n* Execute SQL script `Sql\\create_tables.sql` in this database.\r\n* Open solution `LinqToDBPostGis.sln` in Visual Studio.\r\n* Check database connection string in `App.config` of all projects.\r\n* Run application, view table data along with PostGIS functions results in console output.\r\n\r\n### TODOs\r\n * Implement full set of PostGIS methods.\r\n * Add support for PostGIS `geography` data type.\r\n * Test on various versions of PostgreSQL/PostGIS and platforms (including .NET 5 and later).\r\n * More tests for corner cases.\r\n \r\n### References\r\n* [PostGIS Reference](https://postgis.net/docs/reference.html)\r\n* [PostGIS/NetTopologySuite Type Plugin](https://www.npgsql.org/doc/types/nts.html)\r\n* [Spatial Mapping with NetTopologySuite in Entity Framework Core](https://www.npgsql.org/efcore/mapping/nts.html)\r\n* [How to teach LINQ to DB convert custom .NET methods and objects to SQL - Sql.Function attribute](http://blog.linq2db.com/2016/06/how-to-teach-linq-to-db-convert-custom.html)\r\n","funding_links":[],"categories":["Geospatial Library"],"sub_categories":["C Sharp"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapdevelop%2Flinq2db-postgis-extensions","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fapdevelop%2Flinq2db-postgis-extensions","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapdevelop%2Flinq2db-postgis-extensions/lists"}