-
Notifications
You must be signed in to change notification settings - Fork 83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add proper handling of EXTENSION tag #111
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -244,6 +244,14 @@ public ProjectionParameter GetParameter(string name) | |
return _Parameters.Find(name); | ||
} | ||
|
||
/// <summary> | ||
/// Adds a parameter to the parameter list | ||
/// </summary> | ||
internal void AddParameter(string name, double value) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not needed to get the solution to compile. The parameters need to be present when the class is constructed anyway, so adding parameters afterwards will not do any good. |
||
{ | ||
_Parameters.Add(name, value); | ||
} | ||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -109,7 +109,7 @@ private static IUnit ReadUnit(WktStreamTokenizer tokenizer) | |
tokenizer.ReadAuthority(out authority, out authorityCode); | ||
tokenizer.ReadCloser(bracket); | ||
} | ||
else | ||
else | ||
tokenizer.CheckCloser(bracket); | ||
|
||
return new Unit(unitsPerUnit, unitName, authority, authorityCode, string.Empty, string.Empty, string.Empty); | ||
|
@@ -192,6 +192,7 @@ private static AxisInfo ReadAxis(WktStreamTokenizer tokenizer) | |
case "SOUTH": return new AxisInfo(axisName, AxisOrientationEnum.South); | ||
case "UP": return new AxisInfo(axisName, AxisOrientationEnum.Up); | ||
case "WEST": return new AxisInfo(axisName, AxisOrientationEnum.West); | ||
case "UNKNOWN": return new AxisInfo(axisName, AxisOrientationEnum.Other); | ||
default: | ||
throw new ArgumentException("Invalid axis name '" + unitname + "' in WKT"); | ||
} | ||
|
@@ -206,7 +207,7 @@ private static CoordinateSystem ReadCoordinateSystem(string coordinateSystem, Wk | |
case "PROJCS": | ||
return ReadProjectedCoordinateSystem(tokenizer); | ||
case "FITTED_CS": | ||
return ReadFittedCoordinateSystem (tokenizer); | ||
return ReadFittedCoordinateSystem(tokenizer); | ||
case "GEOCCS": | ||
return ReadGeocentricCoordinateSystem(tokenizer); | ||
case "COMPD_CS": | ||
|
@@ -285,7 +286,7 @@ private static Ellipsoid ReadEllipsoid(WktStreamTokenizer tokenizer) | |
return ellipsoid; | ||
} | ||
|
||
private static IProjection ReadProjection(WktStreamTokenizer tokenizer) | ||
private static Projection ReadProjection(WktStreamTokenizer tokenizer) | ||
{ | ||
if (tokenizer.GetStringValue() != "PROJECTION") | ||
tokenizer.ReadToken("PROJECTION"); | ||
|
@@ -303,34 +304,46 @@ private static IProjection ReadProjection(WktStreamTokenizer tokenizer) | |
else | ||
tokenizer.CheckCloser(bracket); | ||
|
||
tokenizer.ReadToken(",");//, | ||
tokenizer.ReadToken("PARAMETER"); | ||
var paramList = new List<ProjectionParameter>(); | ||
while (tokenizer.GetStringValue() == "PARAMETER") | ||
{ | ||
bracket = tokenizer.ReadOpener(); | ||
string paramName = tokenizer.ReadDoubleQuotedWord(); | ||
tokenizer.ReadToken(","); | ||
tokenizer.NextToken(); | ||
double paramValue = tokenizer.GetNumericValue(); | ||
tokenizer.ReadCloser(bracket); | ||
paramList.Add(new ProjectionParameter(paramName, paramValue)); | ||
//tokenizer.ReadToken(","); | ||
//tokenizer.NextToken(); | ||
tokenizer.NextToken(); | ||
if (tokenizer.GetStringValue() == ",") | ||
{ | ||
tokenizer.NextToken(); | ||
} | ||
else | ||
{ | ||
break; | ||
} | ||
} | ||
|
||
var projection = new Projection(projectionName, paramList, projectionName, authority, authorityCode, string.Empty, string.Empty, string.Empty); | ||
return projection; | ||
} | ||
|
||
private static void ReadParamater(WktStreamTokenizer tokenizer, Projection projection) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Typo |
||
{ | ||
var bracket = tokenizer.ReadOpener(); | ||
string paramName = tokenizer.ReadDoubleQuotedWord(); | ||
tokenizer.ReadToken(","); | ||
tokenizer.NextToken(); | ||
double paramValue = tokenizer.GetNumericValue(); | ||
tokenizer.ReadCloser(bracket); | ||
|
||
projection.AddParameter(paramName, paramValue); | ||
} | ||
|
||
private static void ReadExtension(WktStreamTokenizer tokenizer) | ||
{ | ||
var bracket = tokenizer.ReadOpener(); | ||
string paramName = tokenizer.ReadDoubleQuotedWord(); | ||
tokenizer.ReadToken(","); | ||
tokenizer.NextToken(); | ||
if (paramName == "PROJ4") | ||
{ | ||
string paramValue = tokenizer.ReadDoubleQuotedWord(); | ||
} | ||
else | ||
{ | ||
System.Diagnostics.Debug.WriteLine("What are you?"); | ||
} | ||
|
||
tokenizer.ReadCloser(bracket); | ||
|
||
System.Diagnostics.Debug.WriteLine("Now what do we do with you?"); | ||
} | ||
|
||
|
||
|
||
private static ProjectedCoordinateSystem ReadProjectedCoordinateSystem(WktStreamTokenizer tokenizer) | ||
{ | ||
/*PROJCS[ | ||
|
@@ -356,42 +369,64 @@ private static ProjectedCoordinateSystem ReadProjectedCoordinateSystem(WktStream | |
*/ | ||
var bracket = tokenizer.ReadOpener(); | ||
string name = tokenizer.ReadDoubleQuotedWord(); | ||
tokenizer.ReadToken(","); | ||
tokenizer.ReadToken("GEOGCS"); | ||
var geographicCS = ReadGeographicCoordinateSystem(tokenizer); | ||
tokenizer.ReadToken(","); | ||
tokenizer.ReadToken("PROJECTION"); | ||
var projection = ReadProjection(tokenizer); | ||
var unit = ReadLinearUnit(tokenizer); | ||
tokenizer.NextToken(); | ||
|
||
GeographicCoordinateSystem geographicCS = null; | ||
Projection projection = null; | ||
LinearUnit unit = null; | ||
var axisInfo = new List<AxisInfo>(2); | ||
string authority = string.Empty; | ||
long authorityCode = -1; | ||
|
||
tokenizer.NextToken(); | ||
if (tokenizer.GetStringValue() == ",") | ||
while (tokenizer.GetStringValue() == ",") | ||
{ | ||
tokenizer.NextToken(); | ||
while (tokenizer.GetStringValue() == "AXIS") | ||
{ | ||
axisInfo.Add(ReadAxis(tokenizer)); | ||
tokenizer.NextToken(); | ||
if (tokenizer.GetStringValue() == ",") tokenizer.NextToken(); | ||
} | ||
if (tokenizer.GetStringValue() == ",") tokenizer.NextToken(); | ||
if (tokenizer.GetStringValue() == "AUTHORITY") | ||
string nextToken = tokenizer.GetStringValue(); | ||
switch (nextToken) | ||
{ | ||
tokenizer.ReadAuthority(out authority, out authorityCode); | ||
tokenizer.ReadCloser(bracket); | ||
case "AUTHORITY": | ||
tokenizer.ReadAuthority(out authority, out authorityCode); | ||
break; | ||
case "AXIS": | ||
axisInfo.Add(ReadAxis(tokenizer)); | ||
break; | ||
case "GEOGCS": | ||
geographicCS = ReadGeographicCoordinateSystem(tokenizer); | ||
break; | ||
case "PARAMETER": | ||
ReadParamater(tokenizer, projection); | ||
break; | ||
case "PROJECTION": | ||
projection = ReadProjection(tokenizer); | ||
break; | ||
case "UNIT": | ||
unit = ReadLinearUnit(tokenizer); | ||
break; | ||
case "EXTENSION": | ||
ReadExtension(tokenizer); | ||
break; | ||
default: | ||
throw new ArgumentException("Token not found for {0]", nextToken); | ||
} | ||
|
||
tokenizer.NextToken(); | ||
} | ||
//This is default axis values if not specified. | ||
|
||
// we should be at the end already!? | ||
tokenizer.CheckCloser(bracket); | ||
|
||
if (axisInfo.Count == 0) | ||
{ | ||
axisInfo.Add(new AxisInfo("X", AxisOrientationEnum.East)); | ||
axisInfo.Add(new AxisInfo("Y", AxisOrientationEnum.North)); | ||
} | ||
var projectedCS = new ProjectedCoordinateSystem(geographicCS.HorizontalDatum, geographicCS, unit as LinearUnit, projection, axisInfo, name, authority, authorityCode, string.Empty, string.Empty, string.Empty); | ||
return projectedCS; | ||
|
||
if (geographicCS != null) | ||
{ | ||
return new ProjectedCoordinateSystem(geographicCS.HorizontalDatum, geographicCS, unit as LinearUnit, projection, axisInfo, name, authority, authorityCode, string.Empty, string.Empty, string.Empty); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
private static VerticalCoordinateSystem ReadVerticalCoordinateSystem(WktStreamTokenizer tokenizer) | ||
|
@@ -451,10 +486,10 @@ private static CompoundCoordinateSystem ReadCompoundCoordinateSystem(WktStreamTo | |
long authorityCode = -1; | ||
tokenizer.NextToken(); | ||
|
||
if ( tokenizer.GetStringValue() == ",") | ||
if (tokenizer.GetStringValue() == ",") | ||
{ | ||
tokenizer.NextToken(); | ||
if(tokenizer.GetStringValue() == "AUTHORITY") | ||
if (tokenizer.GetStringValue() == "AUTHORITY") | ||
{ | ||
tokenizer.ReadAuthority(out authority, out authorityCode); | ||
} | ||
|
@@ -541,23 +576,27 @@ private static GeographicCoordinateSystem ReadGeographicCoordinateSystem(WktStre | |
long authorityCode = -1; | ||
tokenizer.NextToken(); | ||
var info = new List<AxisInfo>(2); | ||
if (tokenizer.GetStringValue() == ",") | ||
while (tokenizer.GetStringValue() == ",") | ||
{ | ||
tokenizer.NextToken(); | ||
while (tokenizer.GetStringValue() == "AXIS") | ||
string nextToken = tokenizer.GetStringValue(); | ||
if (nextToken == "AXIS") | ||
{ | ||
info.Add(ReadAxis(tokenizer)); | ||
tokenizer.NextToken(); | ||
if (tokenizer.GetStringValue() == ",") tokenizer.NextToken(); | ||
} | ||
if (tokenizer.GetStringValue() == ",") tokenizer.NextToken(); | ||
if (tokenizer.GetStringValue() == "AUTHORITY") | ||
else if (nextToken == "AUTHORITY") | ||
{ | ||
tokenizer.ReadAuthority(out authority, out authorityCode); | ||
tokenizer.ReadCloser(bracket); | ||
} | ||
|
||
tokenizer.NextToken(); | ||
} | ||
|
||
//We should be closed already | ||
tokenizer.CheckCloser(bracket); | ||
//if (tokenizer.GetStringValue() != "]") | ||
// tokenizer.ReadCloser(bracket); | ||
|
||
//This is default axis values if not specified. | ||
if (info.Count == 0) | ||
{ | ||
|
@@ -575,6 +614,8 @@ private static HorizontalDatum ReadHorizontalDatum(WktStreamTokenizer tokenizer) | |
Wgs84ConversionInfo wgsInfo = null; | ||
string authority = string.Empty; | ||
long authorityCode = -1; | ||
string extension = string.Empty; | ||
string extensionMethod = string.Empty; | ||
|
||
var bracket = tokenizer.ReadOpener(); | ||
string name = tokenizer.ReadDoubleQuotedWord(); | ||
|
@@ -595,6 +636,11 @@ private static HorizontalDatum ReadHorizontalDatum(WktStreamTokenizer tokenizer) | |
tokenizer.ReadAuthority(out authority, out authorityCode); | ||
tokenizer.ReadCloser(bracket); | ||
} | ||
else if (tokenizer.GetStringValue() == "EXTENSION") | ||
{ | ||
tokenizer.ReadExtension(out extension, out extensionMethod); | ||
tokenizer.ReadCloser(bracket); | ||
} | ||
} | ||
// make an assumption about the datum type. | ||
var horizontalDatum = new HorizontalDatum(ellipsoid, wgsInfo, DatumType.HD_Geocentric, name, authority, authorityCode, string.Empty, string.Empty, string.Empty); | ||
|
@@ -612,7 +658,7 @@ private static VerticalDatum ReadVerticalDatum(WktStreamTokenizer tokenizer) | |
string name = tokenizer.ReadDoubleQuotedWord(); | ||
tokenizer.ReadToken(","); | ||
tokenizer.NextToken(); | ||
var datumType = (DatumType) tokenizer.GetNumericValue(); | ||
var datumType = (DatumType)tokenizer.GetNumericValue(); | ||
tokenizer.NextToken(); | ||
if (tokenizer.GetStringValue() == ",") | ||
{ | ||
|
@@ -623,7 +669,7 @@ private static VerticalDatum ReadVerticalDatum(WktStreamTokenizer tokenizer) | |
tokenizer.ReadCloser(bracket); | ||
} | ||
} | ||
var verticalDatum = new VerticalDatum( datumType, name, authority, authorityCode, string.Empty, string.Empty, string.Empty); | ||
var verticalDatum = new VerticalDatum(datumType, name, authority, authorityCode, string.Empty, string.Empty, string.Empty); | ||
|
||
return verticalDatum; | ||
} | ||
|
@@ -654,7 +700,7 @@ private static PrimeMeridian ReadPrimeMeridian(WktStreamTokenizer tokenizer) | |
return primeMeridian; | ||
} | ||
|
||
private static FittedCoordinateSystem ReadFittedCoordinateSystem (WktStreamTokenizer tokenizer) | ||
private static FittedCoordinateSystem ReadFittedCoordinateSystem(WktStreamTokenizer tokenizer) | ||
{ | ||
/* | ||
FITTED_CS[ | ||
|
@@ -676,21 +722,21 @@ private static FittedCoordinateSystem ReadFittedCoordinateSystem (WktStreamToken | |
] | ||
*/ | ||
var bracket = tokenizer.ReadOpener(); | ||
string name = tokenizer.ReadDoubleQuotedWord (); | ||
tokenizer.ReadToken (","); | ||
tokenizer.ReadToken ("PARAM_MT"); | ||
var toBaseTransform = MathTransformWktReader.ReadMathTransform (tokenizer); | ||
tokenizer.ReadToken (","); | ||
tokenizer.NextToken (); | ||
var baseCS = ReadCoordinateSystem (null, tokenizer); | ||
string name = tokenizer.ReadDoubleQuotedWord(); | ||
tokenizer.ReadToken(","); | ||
tokenizer.ReadToken("PARAM_MT"); | ||
var toBaseTransform = MathTransformWktReader.ReadMathTransform(tokenizer); | ||
tokenizer.ReadToken(","); | ||
tokenizer.NextToken(); | ||
var baseCS = ReadCoordinateSystem(null, tokenizer); | ||
|
||
string authority = string.Empty; | ||
long authorityCode = -1; | ||
|
||
var ct = tokenizer.NextToken (); | ||
var ct = tokenizer.NextToken(); | ||
while (ct != TokenType.Eol && ct != TokenType.Eof) | ||
{ | ||
switch (tokenizer.GetStringValue ()) | ||
switch (tokenizer.GetStringValue()) | ||
{ | ||
case ",": | ||
break; | ||
|
@@ -700,14 +746,14 @@ private static FittedCoordinateSystem ReadFittedCoordinateSystem (WktStreamToken | |
|
||
break; | ||
case "AUTHORITY": | ||
tokenizer.ReadAuthority (out authority, out authorityCode); | ||
tokenizer.ReadAuthority(out authority, out authorityCode); | ||
//tokenizer.ReadCloser(bracket); | ||
break; | ||
} | ||
ct = tokenizer.NextToken (); | ||
ct = tokenizer.NextToken(); | ||
} | ||
|
||
var fittedCS = new FittedCoordinateSystem (baseCS, toBaseTransform, name, authority, authorityCode, string.Empty, string.Empty, string.Empty); | ||
var fittedCS = new FittedCoordinateSystem(baseCS, toBaseTransform, name, authority, authorityCode, string.Empty, string.Empty, string.Empty); | ||
return fittedCS; | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use
Projection.Parameters.Add(new ProjectionParameter(name, value));
and remove this method