protected override NpgsqlConnection OpenConnection(string connectionString = null) { NetTopologySuiteBootstrapper.Bootstrap(); var conn = base.OpenConnection(connectionString); conn.TypeMapper.UseNetTopologySuite(); return(conn); }
protected NpgsqlConnection OpenConnection(string connectionString = null, Ordinates handleOrdinates = Ordinates.None) { if (handleOrdinates == Ordinates.None) { handleOrdinates = Ordinates.XY; } NetTopologySuiteBootstrapper.Bootstrap(); var conn = base.OpenConnection(connectionString); conn.TypeMapper.UseNetTopologySuite( new DotSpatialAffineCoordinateSequenceFactory(handleOrdinates), handleOrdinates: handleOrdinates); return(conn); }
/// <summary> /// Sets up NetTopologySuite mappings for the PostGIS types. /// </summary> /// <param name="mapper">The type mapper to set up (global or connection-specific).</param> /// <param name="coordinateSequenceFactory">The factory which knows how to build a particular implementation of ICoordinateSequence from an array of Coordinates.</param> /// <param name="precisionModel">Specifies the grid of allowable points.</param> /// <param name="handleOrdinates">Specifies the ordinates which will be handled. Not specified ordinates will be ignored. /// If <see cref="F:GeoAPI.Geometries.Ordiantes.None" /> is specified, an actual value will be taken from /// the <see cref="P:GeoAPI.Geometries.ICoordinateSequenceFactory.Ordinates"/> property of <paramref name="coordinateSequenceFactory"/>.</param> /// <param name="geographyAsDefault">Specifies that the geography type is used for mapping by default.</param> public static INpgsqlTypeMapper UseNetTopologySuite( this INpgsqlTypeMapper mapper, ICoordinateSequenceFactory coordinateSequenceFactory = null, IPrecisionModel precisionModel = null, Ordinates handleOrdinates = Ordinates.None, bool geographyAsDefault = false) { if (coordinateSequenceFactory == null) { coordinateSequenceFactory = GeometryServiceProvider.Instance.DefaultCoordinateSequenceFactory; } if (precisionModel == null) { precisionModel = GeometryServiceProvider.Instance.DefaultPrecisionModel; } if (handleOrdinates == Ordinates.None) { handleOrdinates = coordinateSequenceFactory.Ordinates; } NetTopologySuiteBootstrapper.Bootstrap(); var typeHandlerFactory = new NetTopologySuiteHandlerFactory( new PostGisReader(coordinateSequenceFactory, precisionModel, handleOrdinates), new PostGisWriter() { HandleOrdinates = handleOrdinates }); return(mapper .AddMapping(new NpgsqlTypeMappingBuilder { PgTypeName = "geometry", NpgsqlDbType = NpgsqlDbType.Geometry, ClrTypes = geographyAsDefault ? Type.EmptyTypes : ClrTypes, InferredDbType = DbType.Object, TypeHandlerFactory = typeHandlerFactory }.Build()) .AddMapping(new NpgsqlTypeMappingBuilder { PgTypeName = "geography", NpgsqlDbType = NpgsqlDbType.Geography, ClrTypes = geographyAsDefault ? ClrTypes : Type.EmptyTypes, InferredDbType = DbType.Object, TypeHandlerFactory = typeHandlerFactory }.Build())); }
public static NpgsqlDbContextOptionsBuilder UseNetTopologySuite( [NotNull] this NpgsqlDbContextOptionsBuilder optionsBuilder, ICoordinateSequenceFactory coordinateSequenceFactory = null, IPrecisionModel precisionModel = null, Ordinates handleOrdinates = Ordinates.None) { Check.NotNull(optionsBuilder, nameof(optionsBuilder)); NetTopologySuiteBootstrapper.Bootstrap(); // TODO: Global-only setup at the ADO.NET level for now, optionally allow per-connection? NpgsqlConnection.GlobalTypeMapper.UseNetTopologySuite(); optionsBuilder.UsePlugin(new NetTopologySuitePlugin()); return(optionsBuilder); }
protected TestBase() { NetTopologySuiteBootstrapper.Bootstrap(); }