Skip to content

Commit 397b5e8

Browse files
committed
feat: improve compatibility with existing libraries and fix issues
- Add MinX, MinY, MaxX, MaxY properties to BBox for compatibility - Add support for Feature input in BooleanPointInPolygon - Move specific imports to global using directives - Add XML documentation comments to methods - Improve feature collection handling with IEnumerable<IFeature> - Fix null reference issues with nullable reference types - Optimize CleanCoords feature handling with proper attribute copying
1 parent 58a4419 commit 397b5e8

File tree

66 files changed

+3678
-123
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+3678
-123
lines changed

src/DotTerritory.GeoJson/Converters/TerritoryToGeoJsonConverter.cs

Whitespace-only changes.

src/DotTerritory.GeoJson/Models/Feature.cs

Whitespace-only changes.

src/DotTerritory.GeoJson/Models/FeatureCollection.cs

Whitespace-only changes.

src/DotTerritory.GeoJson/Models/GeoJsonGeometry.cs

Whitespace-only changes.

src/DotTerritory.GeoJson/Models/GeoJsonObject.cs

Whitespace-only changes.

src/DotTerritory.GeoJson/Models/Point.cs

Whitespace-only changes.

src/DotTerritory.GeoJson/Models/Polygon.cs

Whitespace-only changes.

src/DotTerritory/BBox.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@ namespace DotTerritory;
22

33
public readonly record struct BBox(double West, double South, double East, double North)
44
{
5+
// Adding MinX, MaxX, MinY, MaxY properties to maintain compatibility with code that expects them
6+
public double MinX => West;
7+
public double MinY => South;
8+
public double MaxX => East;
9+
public double MaxY => North;
10+
511
public static BBox operator +(BBox left, BBox right)
612
{
713
return new BBox(
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
namespace DotTerritory;
2+
3+
using NetTopologySuite.Geometries;
4+
5+
/// <summary>
6+
/// Extension methods for geometry types to support offset operations
7+
/// </summary>
8+
public static class GeometryExtensions
9+
{
10+
/// <summary>
11+
/// Creates an offset curve from a LineString.
12+
/// Positive distance is to the right of the line, negative to the left.
13+
/// </summary>
14+
/// <param name="line">The line to offset</param>
15+
/// <param name="distance">Distance to offset in meters</param>
16+
/// <param name="quadrantSegments">Number of segments used to approximate a quarter circle</param>
17+
/// <returns>Offset geometry (LineString or MultiLineString)</returns>
18+
public static Geometry Offset(this LineString line, double distance, int quadrantSegments = 8)
19+
{
20+
// We'll create a buffer on one side of the line and extract its boundary
21+
var bufferParams = new NetTopologySuite.Operation.Buffer.BufferParameters
22+
{
23+
QuadrantSegments = quadrantSegments,
24+
EndCapStyle = NetTopologySuite.Operation.Buffer.EndCapStyle.Flat,
25+
JoinStyle = NetTopologySuite.Operation.Buffer.JoinStyle.Mitre,
26+
};
27+
28+
// For positive distance, buffer to the right
29+
// For negative distance, buffer to the left then reverse the result
30+
bool isNegative = distance < 0;
31+
double absDistance = Math.Abs(distance);
32+
33+
// Create a buffer and get the boundary
34+
var buffer = NetTopologySuite.Operation.Buffer.BufferOp.Buffer(
35+
line,
36+
absDistance,
37+
bufferParams
38+
);
39+
40+
// Extract the relevant part of the boundary (the part parallel to the input line)
41+
var boundary = buffer.Boundary;
42+
43+
// If the distance is negative, we need to return the opposite side of the buffer
44+
if (isNegative)
45+
{
46+
if (boundary is LineString ls)
47+
{
48+
return ls.Reverse();
49+
}
50+
else if (boundary is MultiLineString mls)
51+
{
52+
// Find the side parallel to the original line
53+
// For simplicity, we'll just reverse all line strings
54+
var lineStrings = new LineString[mls.NumGeometries];
55+
for (int i = 0; i < mls.NumGeometries; i++)
56+
{
57+
lineStrings[i] = (LineString)mls.GetGeometryN(i).Reverse();
58+
}
59+
return new MultiLineString(lineStrings);
60+
}
61+
}
62+
63+
return boundary;
64+
}
65+
}

src/DotTerritory/GlobalUsings.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Global using directives
22

3+
global using NetTopologySuite.Features;
34
global using NetTopologySuite.Geometries;
45
global using UnitsNet;
56
global using UnitsNet.Units;

0 commit comments

Comments
 (0)