Skip to content

Commit

Permalink
CreateFromWkt now uses the new WktTextReader and WktParser.
Browse files Browse the repository at this point in the history
- Fixed multiple errors
- Fixed support for FittedCoordinateSystem
- All unit tests except one now working. The one needs partial parsing which is not supported yet.
  • Loading branch information
driekus77 committed Jul 21, 2024
1 parent b982745 commit e425fe7
Show file tree
Hide file tree
Showing 18 changed files with 706 additions and 77 deletions.
58 changes: 41 additions & 17 deletions src/ProjNet/CoordinateSystems/CoordinateSystemFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,39 @@
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
//
// ProjNet is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.

// You should have received a copy of the GNU Lesser General Public License
// along with ProjNet; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using Pidgin;
using ProjNet.IO.CoordinateSystems;
using ProjNet.Wkt;

namespace ProjNet.CoordinateSystems
{
/// <summary>
/// Builds up complex objects from simpler objects or values.
/// </summary>
/// <remarks>
/// <para>CoordinateSystemFactory allows applications to make coordinate systems that
/// <para>CoordinateSystemFactory allows applications to make coordinate systems that
/// is very flexible, whereas the other factories are easier to use.</para>
/// <para>So this Factory can be used to make 'special' coordinate systems.</para>
/// <para>For example, the EPSG authority has codes for USA state plane coordinate systems
/// using the NAD83 datum, but these coordinate systems always use meters. EPSG does not
/// <para>For example, the EPSG authority has codes for USA state plane coordinate systems
/// using the NAD83 datum, but these coordinate systems always use meters. EPSG does not
/// have codes for NAD83 state plane coordinate systems that use feet units. This factory
/// lets an application create such a hybrid coordinate system.</para>
/// </remarks>
public class CoordinateSystemFactory
public class CoordinateSystemFactory
{
/// <summary>
/// Creates an instance of this class
Expand All @@ -59,12 +62,33 @@ public CoordinateSystem CreateFromXml(string xml)
/// <param name="WKT">The Well-known text representation for the spatial reference</param>
/// <returns>The resulting spatial reference object</returns>
public CoordinateSystem CreateFromWkt(string WKT)
{
using (var stringReader = new StringReader(WKT))
using (var wktReader = new WktTextReader(stringReader))
{
var wktResult = wktReader.ReadToEnd();

if (wktResult.Success)
{
var converter = new WktToProjConverter(this);
return converter.Convert(wktResult.Value);
}

throw new InvalidOperationException(wktResult.Error.RenderErrorMessage());
}
}

/// <summary>
///
/// </summary>
/// <param name="WKT"></param>
/// <returns></returns>
public CoordinateSystem CreateFromWktOld(string WKT)
{
var info = CoordinateSystemWktReader.Parse(WKT);
return info as CoordinateSystem;
}


/// <summary>
/// Creates a <see cref="CompoundCoordinateSystem"/> [NOT IMPLEMENTED].
/// </summary>
Expand All @@ -83,11 +107,11 @@ public CompoundCoordinateSystem CreateCompoundCoordinateSystem(string name, Coor
/// <summary>
/// Creates a <see cref="FittedCoordinateSystem"/>.
/// </summary>
/// <remarks>The units of the axes in the fitted coordinate system will be
/// <remarks>The units of the axes in the fitted coordinate system will be
/// inferred from the units of the base coordinate system. If the affine map
/// performs a rotation, then any mixed axes must have identical units. For
/// example, a (lat_deg,lon_deg,height_feet) system can be rotated in the
/// (lat,lon) plane, since both affected axes are in degrees. But you
/// example, a (lat_deg,lon_deg,height_feet) system can be rotated in the
/// (lat,lon) plane, since both affected axes are in degrees. But you
/// should not rotate this coordinate system in any other plane.</remarks>
/// <param name="name">Name of coordinate system</param>
/// <param name="baseCoordinateSystem">Base coordinate system</param>
Expand Down Expand Up @@ -122,9 +146,9 @@ public FittedCoordinateSystem CreateFittedCoordinateSystem(string name, Coordina
/// Creates a <see cref="ILocalCoordinateSystem">local coordinate system</see>.
/// </summary>
/// <remarks>
/// The dimension of the local coordinate system is determined by the size of
/// the axis array. All the axes will have the same units. If you want to make
/// a coordinate system with mixed units, then you can make a compound
/// The dimension of the local coordinate system is determined by the size of
/// the axis array. All the axes will have the same units. If you want to make
/// a coordinate system with mixed units, then you can make a compound
/// coordinate system from different local coordinate systems.
/// </remarks>
/// <param name="name">Name of local coordinate system</param>
Expand Down Expand Up @@ -219,9 +243,9 @@ public IProjection CreateProjection(string name, string wktProjectionClass, List
/// Creates <see cref="HorizontalDatum"/> from ellipsoid and Bursa-World parameters.
/// </summary>
/// <remarks>
/// Since this method contains a set of Bursa-Wolf parameters, the created
/// Since this method contains a set of Bursa-Wolf parameters, the created
/// datum will always have a relationship to WGS84. If you wish to create a
/// horizontal datum that has no relationship with WGS84, then you can
/// horizontal datum that has no relationship with WGS84, then you can
/// either specify a <see cref="DatumType">horizontalDatumType</see> of <see cref="DatumType.HD_Other"/>, or create it via WKT.
/// </remarks>
/// <param name="name">Name of ellipsoid</param>
Expand Down Expand Up @@ -294,7 +318,7 @@ public ILocalDatum CreateLocalDatum(string name, DatumType datumType)
/// </summary>
/// <param name="name">Name of datum</param>
/// <param name="datumType">Type of datum</param>
/// <returns>Vertical datum</returns>
/// <returns>Vertical datum</returns>
public VerticalDatum CreateVerticalDatum(string name, DatumType datumType)
{
if (string.IsNullOrWhiteSpace(name))
Expand Down Expand Up @@ -322,7 +346,7 @@ public VerticalCoordinateSystem CreateVerticalCoordinateSystem(string name, Vert
}

/// <summary>
/// Creates a <see cref="CreateGeocentricCoordinateSystem"/> from a <see cref="HorizontalDatum">datum</see>,
/// Creates a <see cref="CreateGeocentricCoordinateSystem"/> from a <see cref="HorizontalDatum">datum</see>,
/// <see cref="LinearUnit">linear unit</see> and <see cref="PrimeMeridian"/>.
/// </summary>
/// <param name="name">Name of geocentric coordinate system</param>
Expand Down
66 changes: 66 additions & 0 deletions src/ProjNet/Wkt/IWktTraverseHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,94 @@ public interface IWktTraverseHandler
/// <param name="authority"></param>
void Handle(WktAuthority authority);

/// <summary>
/// Handle method for WktAxis.
/// </summary>
/// <param name="axis"></param>
void Handle(WktAxis axis);

/// <summary>
/// Handle method for WktDatum.
/// </summary>
/// <param name="datum"></param>
void Handle(WktDatum datum);

/// <summary>
/// Handle method for WktEllipsoid.
/// </summary>
/// <param name="ellipsoid"></param>
void Handle(WktEllipsoid ellipsoid);

/// <summary>
/// Handle method for WktSpheroid.
/// </summary>
/// <param name="spheroid"></param>
void Handle(WktSpheroid spheroid);

/// <summary>
/// Handle method for WktExtension.
/// </summary>
/// <param name="extension"></param>
void Handle(WktExtension extension);

/// <summary>
/// Handle method for WktUnit.
/// </summary>
/// <param name="unit"></param>
void Handle(WktUnit unit);

/// <summary>
/// Handle method for WktParameter.
/// </summary>
/// <param name="parameter"></param>
void Handle(WktParameter parameter);

/// <summary>
/// Handle method for WktParameterMathTransform. (FittedCoordinateSystem related).
/// </summary>
/// <param name="pmt"></param>
void Handle(WktParameterMathTransform pmt);

/// <summary>
/// Handle method for WktPrimeMeridian.
/// </summary>
/// <param name="meridian"></param>
void Handle(WktPrimeMeridian meridian);

/// <summary>
/// Handle method for WktProjection.
/// </summary>
/// <param name="projection"></param>
void Handle(WktProjection projection);

/// <summary>
/// Handle method for WktToWgs84.
/// </summary>
/// <param name="toWgs84"></param>
void Handle(WktToWgs84 toWgs84);

/// <summary>
/// Handle method for WktGeocentricCoordinateSystem.
/// </summary>
/// <param name="cs"></param>
void Handle(WktGeocentricCoordinateSystem cs);

/// <summary>
/// Handle method for WktGeographicCoordinateSystem.
/// </summary>
/// <param name="cs"></param>
void Handle(WktGeographicCoordinateSystem cs);

/// <summary>
/// Handle method for WktProjectedCoordinateSystem.
/// </summary>
/// <param name="cs"></param>
void Handle(WktProjectedCoordinateSystem cs);

/// <summary>
/// Handle method for WktFittedCoordinateSystem.
/// </summary>
/// <param name="cs"></param>
void Handle(WktFittedCoordinateSystem cs);
}
}
4 changes: 4 additions & 0 deletions src/ProjNet/Wkt/Tree/AuthorityCitation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ public string ToWKT()
return sb.ToString();
}

/// <summary>
/// ToString basic override.
/// </summary>
/// <returns></returns>
public override string ToString()
{
return Citation;
Expand Down
4 changes: 4 additions & 0 deletions src/ProjNet/Wkt/Tree/IWktAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ namespace ProjNet.Wkt.v1.tree
/// </summary>
public interface IWktAttribute
{
/// <summary>
/// ToWKT.
/// </summary>
/// <returns></returns>
string ToWKT();
}
}
4 changes: 4 additions & 0 deletions src/ProjNet/Wkt/Tree/Identifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ public class Identifier : IWktAttribute
public Uri IdUri { get; set; }


/// <summary>
/// ToWKT.
/// </summary>
/// <returns></returns>
public string ToWKT()
{
var sb = new StringBuilder();
Expand Down
4 changes: 4 additions & 0 deletions src/ProjNet/Wkt/Tree/ScopeExtentIdentifierRemarkElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ public ScopeExtentIdentifierRemarkElement(
Remark = remark;
}

/// <summary>
/// ToWKT.
/// </summary>
/// <returns></returns>
public string ToWKT()
{
var sb = new StringBuilder();
Expand Down
4 changes: 4 additions & 0 deletions src/ProjNet/Wkt/Tree/Uri.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ public class Uri: IWktAttribute
/// </summary>
public string Ref { get; set; }

/// <summary>
/// Constructor.
/// </summary>
/// <param name="uriRef"></param>
public Uri(string uriRef)
{
Ref = uriRef;
Expand Down
8 changes: 7 additions & 1 deletion src/ProjNet/Wkt/Tree/WktDatum.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,15 @@ public class WktDatum : WktBaseObject, IEquatable<WktDatum>


/// <summary>
/// Constructor for WKT Datum.
/// Constructor for WktDatum.
/// </summary>
/// <param name="name"></param>
/// <param name="spheroid"></param>
/// <param name="toWgs84"></param>
/// <param name="authority"></param>
/// <param name="keyword"></param>
/// <param name="leftDelimiter"></param>
/// <param name="rightDelimiter"></param>
public WktDatum(string name, WktSpheroid spheroid, WktToWgs84 toWgs84, WktAuthority authority,
string keyword = "DATUM", char leftDelimiter = '[', char rightDelimiter = ']')
: base(keyword, leftDelimiter, rightDelimiter)
Expand Down
Loading

0 comments on commit e425fe7

Please sign in to comment.