本文整理汇总了C#中SharpMap.Converters.WellKnownText.WktStreamTokenizer类的典型用法代码示例。如果您正苦于以下问题:C# WktStreamTokenizer类的具体用法?C# WktStreamTokenizer怎么用?C# WktStreamTokenizer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
WktStreamTokenizer类属于SharpMap.Converters.WellKnownText命名空间,在下文中一共展示了WktStreamTokenizer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Parse
/// <summary>
/// Reads and parses a WKT-formatted projection string.
/// </summary>
/// <param name="wkt">String containing WKT.</param>
/// <returns>Object representation of the WKT.</returns>
/// <exception cref="System.ArgumentException">If a token is not recognised.</exception>
public static IInfo Parse(string wkt)
{
IInfo returnObject = null;
StringReader reader = new StringReader(wkt);
WktStreamTokenizer tokenizer = new WktStreamTokenizer(reader);
tokenizer.NextToken();
string objectName = tokenizer.GetStringValue();
switch (objectName)
{
case "UNIT":
returnObject = ReadUnit(tokenizer);
break;
//case "VERT_DATUM":
// IVerticalDatum verticalDatum = ReadVerticalDatum(tokenizer);
// returnObject = verticalDatum;
// break;
case "SPHEROID":
returnObject = ReadEllipsoid(tokenizer);
break;
case "DATUM":
returnObject = ReadHorizontalDatum(tokenizer); ;
break;
case "PRIMEM":
returnObject = ReadPrimeMeridian(tokenizer);
break;
case "VERT_CS":
case "GEOGCS":
case "PROJCS":
case "COMPD_CS":
case "GEOCCS":
case "FITTED_CS":
case "LOCAL_CS":
returnObject = ReadCoordinateSystem(wkt, tokenizer);
break;
default:
throw new ArgumentException(String.Format("'{0'} is not recongnized.", objectName));
}
reader.Close();
return returnObject;
}
示例2: ReadProjectedCoordinateSystem
/// <summary>
///
/// </summary>
/// <param name="tokenizer"></param>
/// <returns></returns>
private static IProjectedCoordinateSystem ReadProjectedCoordinateSystem(WktStreamTokenizer tokenizer)
{
/*PROJCS[
"OSGB 1936 / British National Grid",
GEOGCS[
"OSGB 1936",
DATUM[...]
PRIMEM[...]
AXIS["Geodetic latitude","NORTH"]
AXIS["Geodetic longitude","EAST"]
AUTHORITY["EPSG","4277"]
],
PROJECTION["Transverse Mercator"],
PARAMETER["latitude_of_natural_origin",49],
PARAMETER["longitude_of_natural_origin",-2],
PARAMETER["scale_factor_at_natural_origin",0.999601272],
PARAMETER["false_easting",400000],
PARAMETER["false_northing",-100000],
AXIS["Easting","EAST"],
AXIS["Northing","NORTH"],
AUTHORITY["EPSG","27700"]
]
*/
tokenizer.ReadToken("[");
string name = tokenizer.ReadDoubleQuotedWord();
tokenizer.ReadToken(",");
tokenizer.ReadToken("GEOGCS");
IGeographicCoordinateSystem geographicCS = ReadGeographicCoordinateSystem(tokenizer);
tokenizer.ReadToken(",");
IProjection projection = ReadProjection(tokenizer);
IUnit unit = ReadLinearUnit(tokenizer);
string authority = String.Empty;
long authorityCode = -1;
tokenizer.NextToken();
List<AxisInfo> axes = new List<AxisInfo>(2);
if (tokenizer.GetStringValue() == ",")
{
tokenizer.NextToken();
while (tokenizer.GetStringValue() == "AXIS")
{
axes.Add(ReadAxis(tokenizer));
tokenizer.NextToken();
}
if (tokenizer.GetStringValue() == "AUTHORITY")
{
tokenizer.ReadAuthority(ref authority, ref authorityCode);
tokenizer.ReadToken("]");
}
}
//This is default axis values if not specified.
if (axes.Count == 0)
{
axes.Add(new AxisInfo("X", AxisOrientationEnum.East));
axes.Add(new AxisInfo("Y", AxisOrientationEnum.North));
}
IProjectedCoordinateSystem projectedCS = new ProjectedCoordinateSystem(geographicCS.HorizontalDatum, geographicCS, unit as LinearUnit, projection, axes, name, authority, authorityCode, String.Empty, String.Empty, String.Empty);
return projectedCS;
}
示例3: ReadGeometryCollectionText
/// <summary>
/// Creates a <see cref="GeometryCollection"/> using the next token in the stream.
/// </summary>
/// <param name="tokenizer"> Tokenizer over a stream of text in Well-known Text
/// format. The next tokens must form a GeometryCollection Text.</param>
/// <returns>
/// A <see cref="GeometryCollection"/> specified by the next token in the stream.</returns>
private static GeometryCollection ReadGeometryCollectionText(WktStreamTokenizer tokenizer)
{
var arrgeometries = new List<IGeometry>();
string nextToken = GetNextEmptyOrOpener(tokenizer);
if (nextToken.Equals("EMPTY"))
return new GeometryCollection(arrgeometries.ToArray());
arrgeometries.Add(ReadGeometryTaggedText(tokenizer));
nextToken = GetNextCloserOrComma(tokenizer);
while (nextToken.Equals(","))
{
arrgeometries.Add(ReadGeometryTaggedText(tokenizer));
nextToken = GetNextCloserOrComma(tokenizer);
}
GeometryCollection geometries = new GeometryCollection(arrgeometries.ToArray());
return geometries;
}
示例4: ReadMultiLineStringText
/// <summary>
/// Creates a <see cref="MultiLineString"/> using the next token in the stream.
/// </summary>
/// <param name="tokenizer">tokenizer over a stream of text in Well-known Text format. The next tokens must form a MultiLineString Text</param>
/// <returns>a <see cref="MultiLineString"/> specified by the next token in the stream</returns>
private static MultiLineString ReadMultiLineStringText(WktStreamTokenizer tokenizer)
{
var arrlines = new List<ILineString>();
string nextToken = GetNextEmptyOrOpener(tokenizer);
if (nextToken == "EMPTY")
return new MultiLineString(arrlines.ToArray());
arrlines.Add(ReadLineStringText(tokenizer));
nextToken = GetNextCloserOrComma(tokenizer);
while (nextToken == ",")
{
arrlines.Add(ReadLineStringText(tokenizer));
nextToken = GetNextCloserOrComma(tokenizer);
}
MultiLineString lines = new MultiLineString(arrlines.ToArray());
return lines;
}
示例5: ReadPointText
/// <summary>
/// Creates a Point using the next token in the stream.
/// </summary>
/// <param name="tokenizer">Tokenizer over a stream of text in Well-known Text
/// format. The next tokens must form a <Point Text>.</param>
/// <returns>Returns a Point specified by the next token in
/// the stream.</returns>
/// <remarks>
/// ParseException is thrown if an unexpected token is encountered.
/// </remarks>
private static Point ReadPointText(WktStreamTokenizer tokenizer)
{
string nextToken = GetNextEmptyOrOpener(tokenizer);
if (nextToken == "EMPTY")
return new Point(0,0);
var X = GetNextNumber(tokenizer);
var Y = GetNextNumber(tokenizer);
Point p = new Point(X,Y);
GetNextCloser(tokenizer);
return p;
}
示例6: ReadMultiPolygonText
/// <summary>
/// Creates a <see cref="MultiPolygon"/> using the next token in the stream.
/// </summary>
/// <param name="tokenizer">tokenizer over a stream of text in Well-known Text
/// format. The next tokens must form a MultiPolygon.</param>
/// <returns>a <code>MultiPolygon</code> specified by the next token in the
/// stream, or if if the coordinates used to create the <see cref="Polygon"/>
/// shells and holes do not form closed linestrings.</returns>
private static MultiPolygon ReadMultiPolygonText(WktStreamTokenizer tokenizer)
{
var arrpolys = new List<IPolygon>();
string nextToken = GetNextEmptyOrOpener(tokenizer);
if (nextToken == "EMPTY")
return new MultiPolygon(arrpolys.ToArray());
Polygon polygon = ReadPolygonText(tokenizer);
arrpolys.Add(polygon);
nextToken = GetNextCloserOrComma(tokenizer);
while (nextToken == ",")
{
polygon = ReadPolygonText(tokenizer);
arrpolys.Add(polygon);
nextToken = GetNextCloserOrComma(tokenizer);
}
MultiPolygon polygons = new MultiPolygon(arrpolys.ToArray());
return polygons;
}
示例7: GetNextWord
/// <summary>
/// Returns the next word in the stream as uppercase text.
/// </summary>
/// <param name="tokenizer">Tokenizer over a stream of text in Well-known Text
/// format. The next token must be a word.</param>
/// <returns>Returns the next word in the stream as uppercase text.</returns>
/// <remarks>
/// Exception is thrown if the next token is not a word.
/// </remarks>
private static string GetNextWord(WktStreamTokenizer tokenizer)
{
TokenType type = tokenizer.NextToken();
string token = tokenizer.GetStringValue();
if (type == TokenType.Number)
throw new Exception("Expected a number but got " + token);
else if (type == TokenType.Word)
return token.ToUpper();
else if (token == "(")
return "(";
else if (token == ")")
return ")";
else if (token == ",")
return ",";
throw new Exception("Not a valid symbol in WKT format.");
}
示例8: GetNextCloserOrComma
/// <summary>
/// Returns the next ")" or "," in the stream.
/// </summary>
/// <param name="tokenizer">tokenizer over a stream of text in Well-known Text
/// format. The next token must be ")" or ",".</param>
/// <returns>Returns the next ")" or "," in the stream.</returns>
/// <remarks>
/// ParseException is thrown if the next token is not ")" or ",".
/// </remarks>
private static string GetNextCloserOrComma(WktStreamTokenizer tokenizer)
{
tokenizer.NextToken();
string nextWord = tokenizer.GetStringValue();
if (nextWord == "," || nextWord == ")")
{
return nextWord;
}
throw new Exception("Expected ')' or ',' but encountered '" + nextWord + "'");
}
示例9: ReadGeometryCollectionText
/// <summary>
/// Creates a <see cref="GeometryCollection"/> using the next token in the stream.
/// </summary>
/// <param name="tokenizer"> Tokenizer over a stream of text in Well-known Text
/// format. The next tokens must form a GeometryCollection Text.</param>
/// <returns>
/// A <see cref="GeometryCollection"/> specified by the next token in the stream.</returns>
private static GeometryCollection ReadGeometryCollectionText(WktStreamTokenizer tokenizer)
{
GeometryCollection geometries = new GeometryCollection();
string nextToken = GetNextEmptyOrOpener(tokenizer);
if (nextToken.Equals("EMPTY"))
return geometries;
geometries.Collection.Add(ReadGeometryTaggedText(tokenizer));
nextToken = GetNextCloserOrComma(tokenizer);
while (nextToken.Equals(","))
{
geometries.Collection.Add(ReadGeometryTaggedText(tokenizer));
nextToken = GetNextCloserOrComma(tokenizer);
}
return geometries;
}
示例10: GetCoordinates
/// <summary>
/// Returns the next array of Coordinates in the stream.
/// </summary>
/// <param name="tokenizer">Tokenizer over a stream of text in Well-known Text format. The
/// next element returned by the stream should be "(" (the beginning of "(x1 y1, x2 y2, ..., xn yn)" or
/// "EMPTY".</param>
/// <returns>The next array of Coordinates in the stream, or an empty array of "EMPTY" is the
/// next element returned by the stream.</returns>
private static List<SharpMap.Geometries.Point> GetCoordinates(WktStreamTokenizer tokenizer)
{
List<SharpMap.Geometries.Point> coordinates = new List<SharpMap.Geometries.Point>();
string nextToken = GetNextEmptyOrOpener(tokenizer);
if (nextToken=="EMPTY")
return coordinates;
SharpMap.Geometries.Point externalCoordinate = new SharpMap.Geometries.Point();
SharpMap.Geometries.Point internalCoordinate = new SharpMap.Geometries.Point();
externalCoordinate.X = GetNextNumber(tokenizer);
externalCoordinate.Y = GetNextNumber(tokenizer);
coordinates.Add(externalCoordinate);
nextToken = GetNextCloserOrComma(tokenizer);
while (nextToken==",")
{
internalCoordinate = new SharpMap.Geometries.Point();
internalCoordinate.X = GetNextNumber(tokenizer);
internalCoordinate.Y = GetNextNumber(tokenizer);
coordinates.Add(internalCoordinate);
nextToken = GetNextCloserOrComma(tokenizer);
}
return coordinates;
}
示例11: ReadLineStringText
/// <summary>
/// Creates a LineString using the next token in the stream.
/// </summary>
/// <param name="tokenizer">Tokenizer over a stream of text in Well-known Text format. The next
/// tokens must form a LineString Text.</param>
/// <returns>Returns a LineString specified by the next token in the stream.</returns>
/// <remarks>
/// ParseException is thrown if an unexpected token is encountered.
/// </remarks>
private static LineString ReadLineStringText(WktStreamTokenizer tokenizer)
{
return new LineString(GetCoordinates(tokenizer));
}
示例12: ReadWGS84ConversionInfo
/// <summary>
/// Reads either 3, 6 or 7 parameter Bursa-Wolf values from TOWGS84 token
/// </summary>
/// <param name="tokenizer"></param>
/// <returns></returns>
private static Wgs84ConversionInfo ReadWGS84ConversionInfo(WktStreamTokenizer tokenizer)
{
//TOWGS84[0,0,0,0,0,0,0]
tokenizer.ReadToken("[");
Wgs84ConversionInfo info = new Wgs84ConversionInfo();
tokenizer.NextToken();
info.Dx = tokenizer.GetNumericValue();
tokenizer.ReadToken(",");
tokenizer.NextToken();
info.Dy = tokenizer.GetNumericValue();
tokenizer.ReadToken(",");
tokenizer.NextToken();
info.Dz = tokenizer.GetNumericValue();
tokenizer.NextToken();
if (tokenizer.GetStringValue() == ",")
{
tokenizer.NextToken();
info.Ex = tokenizer.GetNumericValue();
tokenizer.ReadToken(",");
tokenizer.NextToken();
info.Ey = tokenizer.GetNumericValue();
tokenizer.ReadToken(",");
tokenizer.NextToken();
info.Ez = tokenizer.GetNumericValue();
tokenizer.NextToken();
if (tokenizer.GetStringValue() == ",")
{
tokenizer.NextToken();
info.Ppm = tokenizer.GetNumericValue();
}
}
if (tokenizer.GetStringValue() != "]")
tokenizer.ReadToken("]");
return info;
}
示例13: ReadUnit
/// <summary>
/// Returns a IUnit given a piece of WKT.
/// </summary>
/// <param name="tokenizer">WktStreamTokenizer that has the WKT.</param>
/// <returns>An object that implements the IUnit interface.</returns>
private static IUnit ReadUnit(WktStreamTokenizer tokenizer)
{
tokenizer.ReadToken("[");
string unitName = tokenizer.ReadDoubleQuotedWord();
tokenizer.ReadToken(",");
tokenizer.NextToken();
double unitsPerUnit = tokenizer.GetNumericValue();
string authority = String.Empty;
long authorityCode = -1;
tokenizer.NextToken();
if (tokenizer.GetStringValue() == ",")
{
tokenizer.ReadAuthority(ref authority, ref authorityCode);
tokenizer.ReadToken("]");
}
return new Unit(unitsPerUnit, unitName, authority, authorityCode, String.Empty, String.Empty, String.Empty);
}
示例14: ReadProjection
/// <summary>
///
/// </summary>
/// <param name="tokenizer"></param>
/// <returns></returns>
private static IProjection ReadProjection(WktStreamTokenizer tokenizer)
{
//tokenizer.NextToken();// PROJECTION
tokenizer.ReadToken("PROJECTION");
tokenizer.ReadToken("[");//[
string projectionName = tokenizer.ReadDoubleQuotedWord();
tokenizer.ReadToken("]");//]
tokenizer.ReadToken(",");//,
tokenizer.ReadToken("PARAMETER");
List<ProjectionParameter> paramList = new List<ProjectionParameter>();
while (tokenizer.GetStringValue() == "PARAMETER")
{
tokenizer.ReadToken("[");
string paramName = tokenizer.ReadDoubleQuotedWord();
tokenizer.ReadToken(",");
tokenizer.NextToken();
double paramValue = tokenizer.GetNumericValue();
tokenizer.ReadToken("]");
tokenizer.ReadToken(",");
paramList.Add(new ProjectionParameter(paramName, paramValue));
tokenizer.NextToken();
}
string authority = String.Empty;
long authorityCode = -1;
IProjection projection = new Projection(projectionName, paramList, projectionName, authority, authorityCode, String.Empty, String.Empty, string.Empty);
return projection;
}
示例15: GetNextNumber
/// <summary>
/// Returns the next number in the stream.
/// </summary>
/// <param name="tokenizer">Tokenizer over a stream of text in Well-known text format. The next token
/// must be a number.</param>
/// <returns>Returns the next number in the stream.</returns>
/// <remarks>
/// ParseException is thrown if the next token is not a number.
/// </remarks>
private static double GetNextNumber(WktStreamTokenizer tokenizer)
{
tokenizer.NextToken();
return tokenizer.GetNumericValue();
}