Skip to content

Commit 9d2c146

Browse files
author
Travis Yeik
committed
Changes to Add proper handling of EXTENSION tag NetTopologySuite#111
Removed the AddParameter method. Added async search methods to the database.
1 parent 265e768 commit 9d2c146

File tree

9 files changed

+70
-43
lines changed

9 files changed

+70
-43
lines changed

src/ProjNet.Sqlite/DatabaseCoordinateService.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,20 @@ public CoordinateSystem GetCoordinateSystem(int srid)
5151
return null;
5252
}
5353

54+
/// <summary>
55+
/// Returns the coordinate system by <paramref name="srid" /> identifier
56+
/// </summary>
57+
/// <param name="srid">The initialization for the coordinate system</param>
58+
/// <returns>The coordinate system.</returns>
59+
public async Task<CoordinateSystem> GetCoordinateSystemAsync(int srid)
60+
{
61+
var sysInfo = await _dbProvider.GetCoordinateSystemInfo(srid);
62+
if (sysInfo != null)
63+
return CsFactory.CreateFromWkt(sysInfo.WKT);
64+
65+
return null;
66+
}
67+
5468
/// <summary>
5569
/// Returns the coordinate system by <paramref name="authority" /> and <paramref name="code" />.
5670
/// </summary>
@@ -66,6 +80,16 @@ public CoordinateSystem GetCoordinateSystem(string authority, long code)
6680
return null;
6781
}
6882

83+
/// <summary>
84+
/// Searches the table names based on an expression
85+
/// </summary>
86+
/// <param name="name"></param>
87+
public Task<CoordinateSystemInfo[]> SearchCoordinateSystemAsync(string name)
88+
{
89+
return _dbProvider.SearchCoordinateSystemAsync(name);
90+
91+
}
92+
6993
/// <summary>
7094
/// Method to get the identifier, by which this coordinate system can be accessed.
7195
/// </summary>

src/ProjNet.Sqlite/DatabaseProvider.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,19 @@ public async Task<CoordinateSystemInfo> GetCoordinateSystemInfo(int srid)
5656
}
5757

5858
/// <summary>
59-
/// Returns the number of entries in the database
59+
/// Searches the table names based on an expression
6060
/// </summary>
61-
internal async Task<int> GetCount()
61+
/// <param name="name"></param>
62+
public async Task<CoordinateSystemInfo[]> SearchCoordinateSystemAsync(string name)
63+
{
64+
await Init();
65+
return await Database.Table<CoordinateSystemInfo>().Where(s => s.Name.ToLower().Contains(name)).ToArrayAsync();
66+
}
67+
68+
/// <summary>
69+
/// Returns the number of entries in the database
70+
/// </summary>
71+
internal async Task<int> GetCount()
6272
{
6373
await Init();
6474
return await Database.Table<CoordinateSystemInfo>().CountAsync();

src/ProjNet.Sqlite/ProjNet.Sqlite.csproj

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
44
<TargetFrameworks>net7.0;netstandard2.0</TargetFrameworks>
5-
<SignAssembly>true</SignAssembly>
65
<EnableApiCompat>true</EnableApiCompat>
76
<LangVersion>latest</LangVersion>
87
</PropertyGroup>
@@ -17,10 +16,6 @@
1716
<PackageDescription>Provides an extension to ProjNet's ICoordinateSystemService by providing a database for coordinate systems</PackageDescription>
1817
<PackageTags>OGC;SFS;Projection</PackageTags>
1918
</PropertyGroup>
20-
21-
<ItemGroup>
22-
<PackageReference Include="sqlite-net-pcl" Version="1.8.116" />
23-
</ItemGroup>
2419

2520
<ItemGroup>
2621
<None Remove="proj.db" />
@@ -32,6 +27,10 @@
3227
</Content>
3328
</ItemGroup>
3429

30+
<ItemGroup>
31+
<PackageReference Include="sqlite-net-pcl" Version="1.8.116" />
32+
</ItemGroup>
33+
3534
<ItemGroup>
3635
<ProjectReference Include="..\ProjNet\ProjNET.csproj" />
3736
</ItemGroup>

src/ProjNet/CoordinateSystems/CoordinateSystemFactory.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ namespace ProjNet.CoordinateSystems
2727
/// </summary>
2828
/// <remarks>
2929
/// <para>CoordinateSystemFactory allows applications to make coordinate systems that
30-
/// cannot be created by a <see cref="CoordinateSystemAuthorityFactory"/>. This factory is very
30+
/// cannot be created by a <see cref="CoordinateSystemFactory"/>. This factory is very
3131
/// flexible, whereas the authority factory is easier to use.</para>
32-
/// <para>So <see cref="ICoordinateSystemAuthorityFactory"/>can be used to make 'standard' coordinate
32+
/// <para>So <see cref="CoordinateSystemFactory"/>can be used to make 'standard' coordinate
3333
/// systems, and <see cref="CoordinateSystemFactory"/> can be used to make 'special'
3434
/// coordinate systems.</para>
3535
/// <para>For example, the EPSG authority has codes for USA state plane coordinate systems

src/ProjNet/CoordinateSystems/Info.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public abstract class Info : IInfo
3535
/// were specified in the Simple Features interfaces, so they have been kept here.</para>
3636
/// <para>This specification does not dictate what the contents of these items
3737
/// should be. However, the following guidelines are suggested:</para>
38-
/// <para>When <see cref="ICoordinateSystemAuthorityFactory"/> is used to create an object, the ‘Authority’
38+
/// <para>When <see cref="CoordinateSystemFactory"/> is used to create an object, the ‘Authority’
3939
/// and 'AuthorityCode' values should be set to the authority name of the factory object, and the authority
4040
/// code supplied by the client, respectively. The other values may or may not be set. (If the authority is
4141
/// EPSG, the implementer may consider using the corresponding metadata values in the EPSG tables.)</para>

src/ProjNet/CoordinateSystems/Projection.cs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -76,17 +76,6 @@ public ProjectionParameter GetParameter(int index)
7676
return _parameters[index];
7777
}
7878

79-
/// <summary>
80-
/// Adds a parameter to the parameter list
81-
/// </summary>
82-
/// <param name="name">The name of the projection to add</param>
83-
/// <param name="value">The projection value</param>
84-
public void AddParameter(string name, double value)
85-
{
86-
var param = new ProjectionParameter(name, value);
87-
_parameters.Add(param);
88-
}
89-
9079
/// <summary>
9180
/// Gets an named parameter of the projection.
9281
/// </summary>

src/ProjNet/CoordinateSystems/Projections/MapProjection.cs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -244,14 +244,6 @@ public ProjectionParameter GetParameter(string name)
244244
return _Parameters.Find(name);
245245
}
246246

247-
/// <summary>
248-
/// Adds a parameter to the parameter list
249-
/// </summary>
250-
public void AddParameter(string name, double value)
251-
{
252-
_Parameters.Add(name, value);
253-
}
254-
255247
/// <summary>
256248
///
257249
/// </summary>
@@ -1195,4 +1187,4 @@ protected static double hypot(double x, double y)
11951187
}
11961188
#endregion
11971189
}
1198-
}
1190+
}

src/ProjNet/IO/CoordinateSystems/CoordinateSystemWktReader.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -304,13 +304,13 @@ private static Projection ReadProjection(WktStreamTokenizer tokenizer)
304304
else
305305
tokenizer.CheckCloser(bracket);
306306

307-
var paramList = new List<ProjectionParameter>();
307+
var parameters = new List<ProjectionParameter>();
308308

309-
var projection = new Projection(projectionName, paramList, projectionName, authority, authorityCode, string.Empty, string.Empty, string.Empty);
309+
var projection = new Projection(projectionName, parameters, projectionName, authority, authorityCode, string.Empty, string.Empty, string.Empty);
310310
return projection;
311311
}
312312

313-
private static void ReadParamater(WktStreamTokenizer tokenizer, Projection projection)
313+
private static void ReadParameter(WktStreamTokenizer tokenizer, ICollection<ProjectionParameter> projections)
314314
{
315315
var bracket = tokenizer.ReadOpener();
316316
string paramName = tokenizer.ReadDoubleQuotedWord();
@@ -319,7 +319,7 @@ private static void ReadParamater(WktStreamTokenizer tokenizer, Projection proje
319319
double paramValue = tokenizer.GetNumericValue();
320320
tokenizer.ReadCloser(bracket);
321321

322-
projection.AddParameter(paramName, paramValue);
322+
projections.Add(new ProjectionParameter(paramName, paramValue));
323323
}
324324

325325
private static void ReadExtension(WktStreamTokenizer tokenizer)
@@ -334,12 +334,13 @@ private static void ReadExtension(WktStreamTokenizer tokenizer)
334334
}
335335
else
336336
{
337-
System.Diagnostics.Debug.WriteLine("What are you?");
337+
System.Diagnostics.Debug.WriteLine(string.Format("Unknown type of extension: {0}", paramName));
338338
}
339339

340340
tokenizer.ReadCloser(bracket);
341341

342-
System.Diagnostics.Debug.WriteLine("Now what do we do with you?");
342+
//TODO: store this extension as a variable? Do something with it?
343+
System.Diagnostics.Debug.WriteLine("An extension was read but not processed.");
343344
}
344345

345346

@@ -394,15 +395,15 @@ private static ProjectedCoordinateSystem ReadProjectedCoordinateSystem(WktStream
394395
geographicCS = ReadGeographicCoordinateSystem(tokenizer);
395396
break;
396397
case "PARAMETER":
397-
ReadParamater(tokenizer, projection);
398+
ReadParameter(tokenizer, projection.Parameters);
398399
break;
399400
case "PROJECTION":
400401
projection = ReadProjection(tokenizer);
401402
break;
402403
case "UNIT":
403404
unit = ReadLinearUnit(tokenizer);
404405
break;
405-
case "EXTENSION":
406+
case "EXTENSION":
406407
ReadExtension(tokenizer);
407408
break;
408409
default:

src/ProjNet/ProjNET.csproj

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,22 @@
88
<LangVersion>latest</LangVersion>
99
</PropertyGroup>
1010

11+
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net7.0|AnyCPU'">
12+
<NoWarn>1701;1702;1591</NoWarn>
13+
</PropertyGroup>
14+
15+
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net7.0|AnyCPU'">
16+
<NoWarn>1701;1702;1591</NoWarn>
17+
</PropertyGroup>
18+
19+
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|netstandard2.0|AnyCPU'">
20+
<NoWarn>1701;1702;1591</NoWarn>
21+
</PropertyGroup>
22+
23+
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|netstandard2.0|AnyCPU'">
24+
<NoWarn>1701;1702;1591</NoWarn>
25+
</PropertyGroup>
26+
1127
<PropertyGroup Label="Assembly Info">
1228
<AssemblyTitle>Proj.NET</AssemblyTitle>
1329
<Description>Proj.NET performs point-to-point coordinate conversions between geodetic coordinate systems for use in .Net, Geographic Information Systems (GIS) or GPS applications. The spatial reference model used adheres to the Simple Features specification.</Description>
@@ -26,10 +42,6 @@ Proj.NET performs point-to-point coordinate conversions between geodetic coordin
2642
<PackageTags>OGC;SFS;Projection</PackageTags>
2743
</PropertyGroup>
2844

29-
<ItemGroup>
30-
<Compile Remove="IO\SqlReaderHelper.cs" />
31-
</ItemGroup>
32-
3345
<ItemGroup>
3446
<PackageReference Include="System.Memory" Version="4.5.5" />
3547
<PackageReference Include="System.Numerics.Vectors" Version="4.5.0" />

0 commit comments

Comments
 (0)