-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #138 from nhibernate/feature/postgis-3
Add spatial dialect for PostGIS 3.0+
- Loading branch information
Showing
19 changed files
with
310 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
using NHibernate.SqlCommand; | ||
using System; | ||
|
||
namespace NHibernate.Spatial.Dialect | ||
{ | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
public class PostGis30Dialect : PostGis20Dialect | ||
{ | ||
public override SqlString GetSpatialRelationString(object geometry, SpatialRelation relation, object anotherGeometry, bool criterion) | ||
{ | ||
switch (relation) | ||
{ | ||
case SpatialRelation.Covers: | ||
case SpatialRelation.CoveredBy: | ||
case SpatialRelation.EqualsExact: | ||
return base.GetSpatialRelationString(geometry, relation, anotherGeometry, criterion); | ||
|
||
default: | ||
return new SqlStringBuilder(6) | ||
.Add(SpatialDialect.IsoPrefix) | ||
.Add(relation.ToString()) | ||
.Add("(") | ||
.AddObject(geometry) | ||
.Add(", ") | ||
.AddObject(anotherGeometry) | ||
.Add(")") | ||
.ToSqlString(); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Gets the spatial analysis string. | ||
/// </summary> | ||
/// <param name="geometry">The geometry.</param> | ||
/// <param name="analysis">The analysis.</param> | ||
/// <param name="extraArgument">The extra argument.</param> | ||
/// <returns></returns> | ||
public override SqlString GetSpatialAnalysisString(object geometry, SpatialAnalysis analysis, object extraArgument) | ||
{ | ||
switch (analysis) | ||
{ | ||
case SpatialAnalysis.Buffer: | ||
case SpatialAnalysis.ConvexHull: | ||
return base.GetSpatialAnalysisString(geometry, analysis, extraArgument); | ||
|
||
case SpatialAnalysis.Difference: | ||
case SpatialAnalysis.Distance: | ||
case SpatialAnalysis.Intersection: | ||
case SpatialAnalysis.SymDifference: | ||
case SpatialAnalysis.Union: | ||
return new SqlStringBuilder() | ||
.Add(SpatialDialect.IsoPrefix) | ||
.Add(analysis.ToString()) | ||
.Add("(") | ||
.AddObject(geometry) | ||
.Add(",") | ||
.AddObject(extraArgument) | ||
.Add(")") | ||
.ToSqlString(); | ||
|
||
default: | ||
throw new ArgumentException("Invalid spatial analysis argument"); | ||
} | ||
} | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
NHibernate.Spatial.PostGis/Metadata/GeometryColumn.PostGis30Dialect.hbm.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
|
||
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"> | ||
|
||
<class name="NHibernate.Spatial.Metadata.GeometryColumn, NHibernate.Spatial" | ||
schema="public" | ||
table="GEOMETRY_COLUMNS" | ||
lazy="false" | ||
mutable="false"> | ||
<composite-id> | ||
<key-property name="TableCatalog" column="F_TABLE_CATALOG" /> | ||
<key-property name="TableSchema" column="F_TABLE_SCHEMA" /> | ||
<key-property name="TableName" column="F_TABLE_NAME" /> | ||
<key-property name="Name" column="F_GEOMETRY_COLUMN" /> | ||
</composite-id> | ||
<property name="SRID" column="SRID" /> | ||
<property name="Subtype" column="TYPE" /> | ||
<property name="Dimension" column="COORD_DIMENSION" /> | ||
</class> | ||
</hibernate-mapping> |
17 changes: 17 additions & 0 deletions
17
NHibernate.Spatial.PostGis/Metadata/SpatialReferenceSystem.PostGis30Dialect.hbm.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
|
||
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"> | ||
|
||
<class name="NHibernate.Spatial.Metadata.SpatialReferenceSystem, NHibernate.Spatial" | ||
schema="public" | ||
table="SPATIAL_REF_SYS" | ||
lazy="false" | ||
mutable="true"> | ||
<id name="SRID" column="SRID" type="Int32"> | ||
<generator class="assigned" /> | ||
</id> | ||
<property name="AuthorityName" column="AUTH_NAME" type="String" /> | ||
<property name="AuthoritySRID" column="AUTH_SRID" type="Int32" /> | ||
<property name="WellKnownText" column="SRTEXT" type="String" /> | ||
</class> | ||
</hibernate-mapping> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
Tests.NHibernate.Spatial.PostGis30/PostGis30ConformanceItemsFixture.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using NHibernate.Cfg; | ||
using NUnit.Framework; | ||
|
||
namespace Tests.NHibernate.Spatial | ||
{ | ||
[TestFixture] | ||
public class PostGis30ConformanceItemsFixture : PostGis20ConformanceItemsFixture | ||
{ | ||
protected override void Configure(Configuration configuration) | ||
{ | ||
TestConfiguration.Configure(configuration); | ||
} | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
Tests.NHibernate.Spatial.PostGis30/PostGis30CriteriaFixture.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using NHibernate.Cfg; | ||
using NUnit.Framework; | ||
|
||
namespace Tests.NHibernate.Spatial | ||
{ | ||
[TestFixture] | ||
public class PostGis30CriteriaFixture : CriteriaFixture | ||
{ | ||
protected override void Configure(Configuration configuration) | ||
{ | ||
TestConfiguration.Configure(configuration); | ||
} | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
Tests.NHibernate.Spatial.PostGis30/PostGis30MiscTestsFixture.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using NHibernate.Cfg; | ||
using NUnit.Framework; | ||
|
||
namespace Tests.NHibernate.Spatial | ||
{ | ||
[TestFixture] | ||
public class PostGis30MiscTestsFixture : PostGis20MiscTestsFixture | ||
{ | ||
protected override void Configure(Configuration config) | ||
{ | ||
TestConfiguration.Configure(config); | ||
} | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
Tests.NHibernate.Spatial.PostGis30/PostGis30NtsTestCasesFixture.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using NHibernate.Cfg; | ||
using NUnit.Framework; | ||
using Tests.NHibernate.Spatial.NtsTestCases; | ||
|
||
namespace Tests.NHibernate.Spatial | ||
{ | ||
[TestFixture] | ||
public class PostGis30NtsTestCasesFixture : NtsTestCasesFixture | ||
{ | ||
protected override void Configure(Configuration configuration) | ||
{ | ||
TestConfiguration.Configure(configuration); | ||
} | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
Tests.NHibernate.Spatial.PostGis30/PostGis30ProjectionsFixture.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using NHibernate.Cfg; | ||
using NUnit.Framework; | ||
|
||
namespace Tests.NHibernate.Spatial | ||
{ | ||
[TestFixture] | ||
public class PostGis30ProjectionsFixture : PostGis20ProjectionsFixture | ||
{ | ||
protected override void Configure(Configuration configuration) | ||
{ | ||
TestConfiguration.Configure(configuration); | ||
} | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
Tests.NHibernate.Spatial.PostGis30/PostGis30SpatialQueriesFixture.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using NHibernate.Cfg; | ||
using NUnit.Framework; | ||
|
||
namespace Tests.NHibernate.Spatial | ||
{ | ||
[TestFixture] | ||
public class PostGis30SpatialQueriesFixture : PostGis20SpatialQueriesFixture | ||
{ | ||
protected override void Configure(Configuration configuration) | ||
{ | ||
TestConfiguration.Configure(configuration); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using Microsoft.Extensions.Configuration; | ||
using NHibernate.Bytecode; | ||
using NHibernate.Cfg; | ||
using NHibernate.Driver; | ||
using NHibernate.Spatial.Dialect; | ||
using Npgsql; | ||
using System.Collections.Generic; | ||
|
||
namespace Tests.NHibernate.Spatial | ||
{ | ||
internal static class TestConfiguration | ||
{ | ||
private static readonly IConfigurationRoot _configurationRoot; | ||
|
||
static TestConfiguration() | ||
{ | ||
_configurationRoot = new ConfigurationBuilder() | ||
.AddJsonFile("appsettings.json") | ||
.Build(); | ||
} | ||
|
||
public static void Configure(Configuration configuration) | ||
{ | ||
IDictionary<string, string> properties = new Dictionary<string, string> | ||
{ | ||
[Environment.ProxyFactoryFactoryClass] = typeof(StaticProxyFactoryFactory).AssemblyQualifiedName, | ||
[Environment.Dialect] = typeof(PostGis30Dialect).AssemblyQualifiedName, | ||
[Environment.ConnectionProvider] = typeof(DebugConnectionProvider).AssemblyQualifiedName, | ||
[Environment.ConnectionDriver] = typeof(NpgsqlDriver).AssemblyQualifiedName, | ||
[Environment.ConnectionString] = _configurationRoot.GetConnectionString("PostGis30") | ||
}; | ||
configuration.SetProperties(properties); | ||
|
||
// Use NTS plugin for mapping PostGIS types; see: | ||
// https://www.npgsql.org/doc/release-notes/4.0.html#improved-spatial-support-postgis | ||
NpgsqlConnection.GlobalTypeMapper.UseNetTopologySuite(); | ||
} | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
Tests.NHibernate.Spatial.PostGis30/Tests.NHibernate.Spatial.PostGis30.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
|
||
<IsPackable>false</IsPackable> | ||
|
||
<RootNamespace>Tests.NHibernate.Spatial</RootNamespace> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="nunit" Version="3.13.3" /> | ||
<PackageReference Include="NUnit3TestAdapter" Version="[3.15.1, 3.16.0)" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="[15.9.2, 16.0)" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\NHibernate.Spatial.PostGis\NHibernate.Spatial.PostGis.csproj" /> | ||
<ProjectReference Include="..\Tests.NHibernate.Spatial.PostGis20\Tests.NHibernate.Spatial.PostGis20.csproj" /> | ||
<ProjectReference Include="..\Tests.NHibernate.Spatial\Tests.NHibernate.Spatial.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<None Update="appsettings.json"> | ||
<CopyToOutputDirectory>Always</CopyToOutputDirectory> | ||
</None> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"ConnectionStrings": { | ||
"PostGis30": "Server=localhost;Port=15433;Database=nhsp_test;User Id=nhsp_test;Password=nhsp_test;" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* NHibernate.Spatial PostGIS 3 Test Database Creation Script */ | ||
|
||
-- Run this script as superuser using psql , i.e.: | ||
-- psql -h localhost -p 5432 -U postgres -f path-to-this-file.sql | ||
|
||
CREATE ROLE nhsp_test LOGIN | ||
PASSWORD 'nhsp_test' | ||
NOSUPERUSER NOINHERIT CREATEDB CREATEROLE; | ||
|
||
CREATE DATABASE nhsp_test | ||
WITH OWNER = nhsp_test | ||
ENCODING = 'UTF8'; | ||
|
||
\connect nhsp_test | ||
|
||
CREATE EXTENSION postgis; | ||
|
||
ALTER TABLE public.geometry_columns OWNER TO nhsp_test; | ||
ALTER TABLE public.spatial_ref_sys OWNER TO nhsp_test; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters