Skip to content
This repository was archived by the owner on May 12, 2026. It is now read-only.

Commit f08e477

Browse files
Use a single GeometryFactory instance
1 parent 3be547a commit f08e477

14 files changed

Lines changed: 280 additions & 326 deletions

File tree

Alidade.Core/AlidadeCoreModule.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
using Alidade.Core.Consts;
12
using Autofac;
3+
using NetTopologySuite.Geometries;
24

35
namespace Alidade.Core;
46

@@ -11,5 +13,9 @@ public sealed class AlidadeCoreModule : Module
1113
protected override void Load(ContainerBuilder builder)
1214
{
1315
builder.RegisterType<SettingsStateService>().AsSelf().SingleInstance();
16+
17+
builder.RegisterInstance(new GeometryFactory(new PrecisionModel(), SpatialReferenceIDs.Wgs84))
18+
.AsSelf()
19+
.SingleInstance();
1420
}
1521
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
namespace Alidade.Core.Consts;
2+
3+
/// <summary>
4+
/// EPSG spatial reference system identifiers.
5+
/// </summary>
6+
public static class SpatialReferenceIDs
7+
{
8+
/// <summary>
9+
/// WGS 84 geographic coordinate system, EPSG:4326
10+
/// </summary>
11+
public const int Wgs84 = 4326;
12+
}

Alidade.Osm/Models/Imagery/ImageryEntry.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.Text.Json.Serialization;
22
using System.Text.RegularExpressions;
3+
using Alidade.Core.Consts;
34
using NetTopologySuite;
45
using NetTopologySuite.Geometries;
56

@@ -75,16 +76,13 @@ public int? MaxZoom
7576
/// Builds an NTS <see cref="Geometry"/> for the coverage polygons,
7677
/// or returns null for worldwide sources.
7778
/// </summary>
78-
public Geometry? BuildCoverageGeometry()
79+
public Geometry? BuildCoverageGeometry(GeometryFactory factory)
7980
{
8081
if (Polygon is not { Length: > 0 })
8182
{
8283
return null;
8384
}
8485

85-
GeometryFactory factory = NtsGeometryServices.Instance
86-
.CreateGeometryFactory(srid: 4326);
87-
8886
Polygon[] polys = [.. Polygon.Select(ring =>
8987
{
9088
Coordinate[] coords = [.. ring.Select(p => new Coordinate(p[0], p[1]))];

Alidade.Osm/Models/OsmGeoJsonExtensions.cs

Lines changed: 0 additions & 255 deletions
This file was deleted.

Alidade.Osm/Models/OsmNode.cs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
using NetTopologySuite.Features;
2+
using NetTopologySuite.Geometries;
3+
14
namespace Alidade.Osm.Models;
25

36
/// <summary>
@@ -17,7 +20,7 @@ namespace Alidade.Osm.Models;
1720
/// <param name="Lat">Latitude in decimal degrees (WGS 84), in the range −90 to +90.</param>
1821
/// <param name="Lon">Longitude in decimal degrees (WGS 84), in the range −180 to +180.</param>
1922
/// <param name="Tags">Key-value pairs describing the node. Empty for geometry-only nodes (e.g. way vertices).</param>
20-
public record OsmNode(
23+
public sealed record OsmNode(
2124
long Id,
2225
int Version,
2326
int? ChangesetId,
@@ -31,4 +34,30 @@ public record OsmNode(
3134
/// Returns a typed reference to this node.
3235
/// </summary>
3336
public OsmElementRef Ref => new(OsmElementTypes.Node, Id);
37+
38+
/// <summary>
39+
/// Converts this to an NTS <see cref="Feature"/> with a Point geometry.
40+
/// Tag key/value pairs are stored as attributes prefixed with <c>tag:</c>.
41+
/// </summary>
42+
/// <param name="factory">The geometry factory used to construct the Point.</param>
43+
/// <returns>A GeoJSON-serializable Point <see cref="Feature"/>.</returns>
44+
public Feature ToFeature(GeometryFactory factory)
45+
{
46+
AttributesTable attrs = new()
47+
{
48+
{ "id", Id.ToString() },
49+
{ "type", "node" },
50+
{ "version", Version },
51+
{ "editState", (int)EditState.Fetched },
52+
{ "fill", "#fff" },
53+
{ "stroke", "#555" }
54+
};
55+
56+
foreach ((string k, string v) in Tags)
57+
{
58+
attrs.Add("tag:" + k, v);
59+
}
60+
61+
return new Feature(factory.CreatePoint(new Coordinate(Lon, Lat)), attrs);
62+
}
3463
}

0 commit comments

Comments
 (0)