Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions MEOS.NET.Tests/ValueClassTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using MEOS.NET.Types;

namespace MEOS.NET.Tests
{
/// <summary>
/// A base value MEOS passes by reference is a class of its own, so a method
/// taking or answering one says which value it means rather than handing back
/// a pointer.
/// </summary>
[TestClass]
public class ValueClassTests : MeosTest
{
[TestMethod]
public void ATextAnswersTheTextMeosWritesItAs()
{
Text text = Text.In("mobility")!;

Assert.AreEqual("mobility", text.ToString());
Assert.AreEqual("MOBILITY", text.Upper()!.ToString());
Assert.AreEqual("Mobility", text.Initcap()!.ToString());
}

[TestMethod]
public void AGeometryIsAGeoAndAnswersItsOwnMeasures()
{
Geo square = Geo.FromText("POLYGON((0 0,0 2,2 2,2 0,0 0))", 4326)!;

Assert.IsInstanceOfType(square, typeof(Geo));
Assert.AreEqual(4326, square.SRID());
StringAssert.StartsWith(square.AsText(6), "POLYGON(");
}

[TestMethod]
public void ACbufferAnswersItsCentreAsAGeometry()
{
Cbuffer buffer = Cbuffer.In("Cbuffer(Point(1 1),5)")!;

Assert.AreEqual(5.0, buffer.Radius());

Geo? centre = buffer.Point();

Assert.IsNotNull(centre);
Assert.AreEqual("POINT(1 1)", centre!.AsText(6));
}

[TestMethod]
public void ATemporalGeoIsRestrictedByAGeometry()
{
Temporal trip = TGeomPoint.In(
"[POINT(0 0)@2024-12-06, POINT(4 4)@2024-12-08]")!;
Geo half = Geo.FromText("POLYGON((0 0,0 2,2 2,2 0,0 0))", 0)!;

Temporal? inside = ((TGeo)trip).AtGeom(half);

// The trip leaves the square at (2,2), halfway along, so what the
// restriction answers ends there rather than at the trip's own end.
Assert.IsNotNull(inside);
StringAssert.Contains(inside!.ToString(), "2024-12-07");
Assert.IsFalse(inside.ToString().Contains("2024-12-08"));

Check warning on line 59 in MEOS.NET.Tests/ValueClassTests.cs

View workflow job for this annotation

GitHub Actions / Regenerate, build and smoke-test against MEOS

Dereference of a possibly null reference.

Check warning on line 59 in MEOS.NET.Tests/ValueClassTests.cs

View workflow job for this annotation

GitHub Actions / Regenerate, build and smoke-test against MEOS

Dereference of a possibly null reference.
}
}
}
111 changes: 111 additions & 0 deletions MEOS.NET/Types/Cbuffer.g.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
#nullable enable

using System.Runtime.InteropServices;

using MEOS.NET.Enums;
using MEOS.NET.Functions;

namespace MEOS.NET.Types
{
/// <summary>The Cbuffer class of the MEOS object model.</summary>
[System.CodeDom.Compiler.GeneratedCode("MEOS.NET.ObjectGen", "0.1.0")]
public class Cbuffer : Value
{
internal Cbuffer(IntPtr ptr) : base(ptr) { }

/// <summary>The text MEOS writes this value as.</summary>
public override string ToString()
=> this.Out(15);

public string AsEWKT(int maxdd)
=> Meos.CbufferAsEwkt(this.Ptr, maxdd);

public string AsText(int maxdd)
=> Meos.CbufferAsText(this.Ptr, maxdd);

public int Cmp(Cbuffer cb2)
=> Meos.CbufferCmp(this.Ptr, cb2.Ptr);

public Cbuffer? Copy()
=> MEOSFactory.WrapCbuffer(Meos.CbufferCopy(this.Ptr));

public bool Eq(Cbuffer cb2)
=> Meos.CbufferEq(this.Ptr, cb2.Ptr);

public bool Ge(Cbuffer cb2)
=> Meos.CbufferGe(this.Ptr, cb2.Ptr);

public bool Gt(Cbuffer cb2)
=> Meos.CbufferGt(this.Ptr, cb2.Ptr);

public uint Hash()
=> Meos.CbufferHash(this.Ptr);

public ulong HashExtended(ulong seed)
=> Meos.CbufferHashExtended(this.Ptr, seed);

public bool Le(Cbuffer cb2)
=> Meos.CbufferLe(this.Ptr, cb2.Ptr);

public bool Lt(Cbuffer cb2)
=> Meos.CbufferLt(this.Ptr, cb2.Ptr);

public bool Ne(Cbuffer cb2)
=> Meos.CbufferNe(this.Ptr, cb2.Ptr);

public bool Nsame(Cbuffer cb2)
=> Meos.CbufferNsame(this.Ptr, cb2.Ptr);

public string Out(int maxdd)
=> Meos.CbufferOut(this.Ptr, maxdd);

public Geo? Point()
=> MEOSFactory.WrapGeo(Meos.CbufferPoint(this.Ptr));

public double Radius()
=> Meos.CbufferRadius(this.Ptr);

public Cbuffer? Round(int maxdd)
=> MEOSFactory.WrapCbuffer(Meos.CbufferRound(this.Ptr, maxdd));

public int SRID()
=> Meos.CbufferSrid(this.Ptr);

public bool Same(Cbuffer cb2)
=> Meos.CbufferSame(this.Ptr, cb2.Ptr);

public Cbuffer? SetSRID(int srid)
=> MEOSFactory.WrapCbuffer(Meos.CbufferSetSrid(this.Ptr, srid));

public STBox? TimestamptzToStbox(DateTime t)
=> MEOSFactory.WrapSTBox(Meos.CbufferTimestamptzToStbox(this.Ptr, MEOSConvert.ToTimestampTz(t)));

public Geo? ToGeom()
=> MEOSFactory.WrapGeo(Meos.CbufferToGeom(this.Ptr));

public Set? ToSet()
=> MEOSFactory.WrapSet(Meos.CbufferToSet(this.Ptr));

public STBox? ToStbox()
=> MEOSFactory.WrapSTBox(Meos.CbufferToStbox(this.Ptr));

public Cbuffer? Transform(int srid)
=> MEOSFactory.WrapCbuffer(Meos.CbufferTransform(this.Ptr, srid));

public Cbuffer? TransformPipeline(string pipelinestr, int srid, bool is_forward)
=> MEOSFactory.WrapCbuffer(Meos.CbufferTransformPipeline(this.Ptr, pipelinestr, srid, is_forward));

public STBox? TstzspanToStbox(Span s)
=> MEOSFactory.WrapSTBox(Meos.CbufferTstzspanToStbox(this.Ptr, s.Ptr));

public static Cbuffer? FromHEXWKB(string hexwkb)
=> MEOSFactory.WrapCbuffer(Meos.CbufferFromHexwkb(hexwkb));

public static Cbuffer? In(string str)
=> MEOSFactory.WrapCbuffer(Meos.CbufferIn(str));

public static Cbuffer? Make(Geo point, double radius)
=> MEOSFactory.WrapCbuffer(Meos.CbufferMake(point.Ptr, radius));

}
}
28 changes: 28 additions & 0 deletions MEOS.NET/Types/CbufferSet.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,39 @@ internal CbufferSet(IntPtr ptr) : base(ptr) { }
public override string ToString()
=> this.Out(15);

public Cbuffer? EndValue()
=> MEOSFactory.WrapCbuffer(Meos.CbuffersetEndValue(this.Ptr));

public string Out(int maxdd)
=> Meos.CbuffersetOut(this.Ptr, maxdd);

public Cbuffer? StartValue()
=> MEOSFactory.WrapCbuffer(Meos.CbuffersetStartValue(this.Ptr));

public Cbuffer?[] Values()
=> MEOSFactory.WrapCbufferArray(Meos.CbuffersetValues(this.Ptr));

public static Set? In(string str)
=> MEOSFactory.WrapSet(Meos.CbuffersetIn(str));

public static Set? Make(Cbuffer[] values)
{
IntPtr[] _valuesValues = new IntPtr[values.Length];
for (int i = 0; i < values.Length; i++)
{
_valuesValues[i] = values[i].Ptr;
}

GCHandle _values = GCHandle.Alloc(_valuesValues, GCHandleType.Pinned);
try
{
return MEOSFactory.WrapSet(Meos.CbuffersetMake(_values.AddrOfPinnedObject(), values.Length));
}
finally
{
_values.Free();
}
}

}
}
161 changes: 161 additions & 0 deletions MEOS.NET/Types/Geo.g.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
#nullable enable

using System.Runtime.InteropServices;

using MEOS.NET.Enums;
using MEOS.NET.Functions;

namespace MEOS.NET.Types
{
/// <summary>PostGIS-derived values, both of them a GSERIALIZED. Parent of Geometry and Geography exactly as TGeo parents TGeometry and TGeography, so a signature naming the C type alone is typed by the parent and the two spellings stay distinct classes.</summary>
[System.CodeDom.Compiler.GeneratedCode("MEOS.NET.ObjectGen", "0.1.0")]
public class Geo : Value
{
internal Geo(IntPtr ptr) : base(ptr) { }

/// <summary>The text MEOS writes this value as.</summary>
public override string ToString()
=> this.Out();

public string AsEWKT(int precision)
=> Meos.GeoAsEwkt(this.Ptr, precision);

public string AsGEOJSON(int option, int precision, string srs)
=> Meos.GeoAsGeojson(this.Ptr, option, precision, srs);

public string AsHexewkb(string endian)
=> Meos.GeoAsHexewkb(this.Ptr, endian);

public string AsText(int precision)
=> Meos.GeoAsText(this.Ptr, precision);

public Geo? Copy()
=> MEOSFactory.WrapGeo(Meos.GeoCopy(this.Ptr));

public int Equals(Geo gs2)
=> Meos.GeoEquals(this.Ptr, gs2.Ptr);

public Geo? GeoN(int n)
=> MEOSFactory.WrapGeo(Meos.GeoGeoN(this.Ptr, n));

public bool IsEmpty()
=> Meos.GeoIsEmpty(this.Ptr);

public bool IsUnitary()
=> Meos.GeoIsUnitary(this.Ptr);

public int NumGeos()
=> Meos.GeoNumGeos(this.Ptr);

public int NumPoints()
=> Meos.GeoNumPoints(this.Ptr);

public string Out()
=> Meos.GeoOut(this.Ptr);

public Geo?[] Pointarr()
=> MEOSFactory.WrapGeoArray(Meos.GeoPointarr(this.Ptr));

public Geo? Points()
=> MEOSFactory.WrapGeo(Meos.GeoPoints(this.Ptr));

public Geo? Reverse()
=> MEOSFactory.WrapGeo(Meos.GeoReverse(this.Ptr));

public Geo? Round(int maxdd)
=> MEOSFactory.WrapGeo(Meos.GeoRound(this.Ptr, maxdd));

public int SRID()
=> Meos.GeoSrid(this.Ptr);

public bool Same(Geo gs2)
=> Meos.GeoSame(this.Ptr, gs2.Ptr);

public Geo? SetSRID(int srid)
=> MEOSFactory.WrapGeo(Meos.GeoSetSrid(this.Ptr, srid));

public STBox?[] SplitEachNStboxes(int elem_count)
=> MEOSFactory.WrapSTBoxArray(Meos.GeoSplitEachNStboxes(this.Ptr, elem_count));

public STBox?[] SplitNStboxes(int box_count)
=> MEOSFactory.WrapSTBoxArray(Meos.GeoSplitNStboxes(this.Ptr, box_count));

public STBox?[] Stboxes()
=> MEOSFactory.WrapSTBoxArray(Meos.GeoStboxes(this.Ptr));

public STBox? TimestamptzToStbox(DateTime t)
=> MEOSFactory.WrapSTBox(Meos.GeoTimestamptzToStbox(this.Ptr, MEOSConvert.ToTimestampTz(t)));

public ulong ToH3indexCell(int resolution)
=> Meos.GeoToH3indexCell(this.Ptr, resolution);

public Set? ToH3indexSet(int resolution)
=> MEOSFactory.WrapSet(Meos.GeoToH3indexSet(this.Ptr, resolution));

public ulong ToQuadbinCell(int resolution)
=> Meos.GeoToQuadbinCell(this.Ptr, resolution);

public Set? ToSet()
=> MEOSFactory.WrapSet(Meos.GeoToSet(this.Ptr));

public STBox? ToStbox()
=> MEOSFactory.WrapSTBox(Meos.GeoToStbox(this.Ptr));

public Geo? Transform(int srid_to)
=> MEOSFactory.WrapGeo(Meos.GeoTransform(this.Ptr, srid_to));

public Geo? TransformPipeline(string pipeline, int srid_to, bool is_forward)
=> MEOSFactory.WrapGeo(Meos.GeoTransformPipeline(this.Ptr, pipeline, srid_to, is_forward));

public STBox? TstzspanToStbox(Span s)
=> MEOSFactory.WrapSTBox(Meos.GeoTstzspanToStbox(this.Ptr, s.Ptr));

public static Geo? CollectGarray(Geo[] gsarr)
{
IntPtr[] _gsarrValues = new IntPtr[gsarr.Length];
for (int i = 0; i < gsarr.Length; i++)
{
_gsarrValues[i] = gsarr[i].Ptr;
}

GCHandle _gsarr = GCHandle.Alloc(_gsarrValues, GCHandleType.Pinned);
try
{
return MEOSFactory.WrapGeo(Meos.GeoCollectGarray(_gsarr.AddrOfPinnedObject(), gsarr.Length));
}
finally
{
_gsarr.Free();
}
}

public static Geo? FromGEOJSON(string geojson)
=> MEOSFactory.WrapGeo(Meos.GeoFromGeojson(geojson));

public static Geo? FromText(string wkt, int srid)
=> MEOSFactory.WrapGeo(Meos.GeoFromText(wkt, srid));

public static Geo? MakelineGarray(Geo[] gsarr)
{
IntPtr[] _gsarrValues = new IntPtr[gsarr.Length];
for (int i = 0; i < gsarr.Length; i++)
{
_gsarrValues[i] = gsarr[i].Ptr;
}

GCHandle _gsarr = GCHandle.Alloc(_gsarrValues, GCHandleType.Pinned);
try
{
return MEOSFactory.WrapGeo(Meos.GeoMakelineGarray(_gsarr.AddrOfPinnedObject(), gsarr.Length));
}
finally
{
_gsarr.Free();
}
}

public static string? Typename(int type)
=> Meos.GeoTypename(type);

}
}
Loading
Loading