private static IHorizontalDatum ReadHorizontalDatum(WktStreamTokenizer tokenizer) { //DATUM["OSGB 1936",SPHEROID["Airy 1830",6377563.396,299.3249646,AUTHORITY["EPSG","7001"]]TOWGS84[0,0,0,0,0,0,0],AUTHORITY["EPSG","6277"]] tokenizer.ReadToken("["); string name = tokenizer.ReadDoubleQuotedWord(); tokenizer.ReadToken(","); tokenizer.ReadToken("SPHEROID"); IEllipsoid ellipsoid = ReadEllipsoid(tokenizer); tokenizer.ReadToken("TOWGS84"); WGS84ConversionInfo wgsInfo = ReadWGS84ConversionInfo(tokenizer); tokenizer.ReadToken(","); string authority = ""; string authorityCode = ""; tokenizer.ReadAuthority(ref authority, ref authorityCode); // make an assumption about the datum type. DatumType datumType = DatumType.IHD_Geocentric; IHorizontalDatum horizontalDatum = new HorizontalDatum(name, datumType, ellipsoid, wgsInfo, "", authority, authorityCode, "", ""); tokenizer.ReadToken("]"); return(horizontalDatum); }
private static IEllipsoid ReadEllipsoid(WktStreamTokenizer tokenizer) { //SPHEROID["Airy 1830",6377563.396,299.3249646,AUTHORITY["EPSG","7001"]] tokenizer.ReadToken("["); string name = tokenizer.ReadDoubleQuotedWord(); tokenizer.ReadToken(","); tokenizer.NextToken(); double majorAxis = tokenizer.GetNumericValue(); tokenizer.ReadToken(","); tokenizer.NextToken(); double e = tokenizer.GetNumericValue(); tokenizer.ReadToken(","); string authority = ""; string authorityCode = ""; tokenizer.ReadAuthority(ref authority, ref authorityCode); tokenizer.ReadToken("]"); IEllipsoid ellipsoid = new Ellipsoid(majorAxis, 0.0, e, true, LinearUnit.Meters, "", authority, authorityCode, name, "", ""); return(ellipsoid); }
private static IVerticalCoordinateSystem ReadVerticalCoordinateSystem(WktStreamTokenizer tokenizer) { /* * VERT_CS["Newlyn", * VERT_DATUM["Ordnance Datum Newlyn",2005,AUTHORITY["EPSG","5101"]] * UNIT["metre",1,AUTHORITY["EPSG","9001"]] * AUTHORITY["EPSG","5701"] */ tokenizer.ReadToken("["); string name = tokenizer.ReadDoubleQuotedWord(); tokenizer.ReadToken(","); tokenizer.ReadToken("VERT_DATUM"); IVerticalDatum verticalDatum = ReadVerticalDatum(tokenizer); tokenizer.ReadToken("UNIT"); IUnit unit = ReadUnit(tokenizer); string authority = ""; string authorityCode = ""; tokenizer.ReadAuthority(ref authority, ref authorityCode); tokenizer.ReadToken("]"); IVerticalCoordinateSystem verticalCS = new VerticalCoordinateSystem(name, verticalDatum, "", authority, authorityCode, "", ""); return(verticalCS); }
public void TestReadAuthority1() { StringReader reader = new StringReader("AUTHORITY[\"EPSG\",\"9102\"]"); WktStreamTokenizer tokenizer = new WktStreamTokenizer(reader); string authority=""; string authorityCode=""; tokenizer.ReadAuthority(ref authority, ref authorityCode); Assertion.AssertEquals("test 1","EPSG",authority); Assertion.AssertEquals("test 2","9102",authorityCode); }
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); IAxisInfo axis0 = ReadAxisInfo(tokenizer); tokenizer.ReadToken(","); tokenizer.ReadToken("AXIS"); IAxisInfo axis1 = ReadAxisInfo(tokenizer); tokenizer.ReadToken(","); string authority = ""; string authorityCode = ""; tokenizer.ReadAuthority(ref authority, ref authorityCode); tokenizer.ReadToken("]"); IAxisInfo[] axisArray = new IAxisInfo[2]; axisArray[0] = axis0; axisArray[1] = axis1; ILinearUnit linearUnit = LinearUnit.Meters; IProjectedCoordinateSystem projectedCS = new ProjectedCoordinateSystem(null, axisArray, geographicCS, linearUnit, projection, "", authority, authorityCode, name, "", ""); return(projectedCS); }
public void TestReadAuthority2() { StringReader reader = new StringReader("OPPS[\"EPSG\",\"9102\"]"); WktStreamTokenizer tokenizer = new WktStreamTokenizer(reader); string authority=""; string authorityCode=""; try { tokenizer.ReadAuthority(ref authority, ref authorityCode); } catch(ParseException) { } }
private static IGeographicCoordinateSystem ReadGeographicCoordinateSystem(WktStreamTokenizer tokenizer) { /* * GEOGCS["OSGB 1936", * DATUM["OSGB 1936",SPHEROID["Airy 1830",6377563.396,299.3249646,AUTHORITY["EPSG","7001"]]TOWGS84[0,0,0,0,0,0,0],AUTHORITY["EPSG","6277"]] * PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]] * AXIS["Geodetic latitude","NORTH"] * AXIS["Geodetic longitude","EAST"] * AUTHORITY["EPSG","4277"] * ] */ tokenizer.ReadToken("["); string name = tokenizer.ReadDoubleQuotedWord(); tokenizer.ReadToken(","); tokenizer.ReadToken("DATUM"); IHorizontalDatum horizontalDatum = ReadHorizontalDatum(tokenizer); tokenizer.ReadToken("PRIMEM"); IPrimeMeridian primeMeridian = ReadPrimeMeridian(tokenizer); tokenizer.ReadToken("AXIS"); IAxisInfo axis0 = ReadAxisInfo(tokenizer); tokenizer.ReadToken(","); tokenizer.ReadToken("AXIS"); IAxisInfo axis1 = ReadAxisInfo(tokenizer); tokenizer.ReadToken(","); string authority = ""; string authorityCode = ""; tokenizer.ReadAuthority(ref authority, ref authorityCode); tokenizer.ReadToken("]"); // ?? assume angular unit is degrees. IAngularUnit angularUnit = new AngularUnit(180 / Math.PI); IGeographicCoordinateSystem geographicCS = new GeographicCoordinateSystem(angularUnit, horizontalDatum, primeMeridian, axis0, axis1, "", authority, authorityCode, name, "", ""); return(geographicCS); }
private static IVerticalDatum ReadVerticalDatum(WktStreamTokenizer tokenizer) { //VERT_DATUM["Ordnance Datum Newlyn",2005,AUTHORITY["5101","EPSG"]] tokenizer.ReadToken("["); string datumName = tokenizer.ReadDoubleQuotedWord(); tokenizer.ReadToken(","); tokenizer.NextToken(); string datumTypeNumber = tokenizer.GetStringValue(); tokenizer.ReadToken(","); string authority = ""; string authorityCode = ""; tokenizer.ReadAuthority(ref authority, ref authorityCode); DatumType datumType = (DatumType)Enum.Parse(typeof(DatumType), datumTypeNumber); IVerticalDatum verticalDatum = new VerticalDatum(datumType, "", authorityCode, authority, datumName, "", ""); tokenizer.ReadToken("]"); return(verticalDatum); }
private static IPrimeMeridian ReadPrimeMeridian(WktStreamTokenizer tokenizer) { //PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]] tokenizer.ReadToken("["); string name = tokenizer.ReadDoubleQuotedWord(); tokenizer.ReadToken(","); tokenizer.NextToken(); double longitude = tokenizer.GetNumericValue(); tokenizer.ReadToken(","); string authority = ""; string authorityCode = ""; tokenizer.ReadAuthority(ref authority, ref authorityCode); // make an assumption about the Angular units - degrees. IPrimeMeridian primeMeridian = new PrimeMeridian(name, new AngularUnit(180 / Math.PI), longitude, "", authority, authorityCode, "", ""); tokenizer.ReadToken("]"); return(primeMeridian); }
/// <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) { //UNIT["degree",0.01745329251994433,AUTHORITY["EPSG","9102"]] IUnit unit = null; tokenizer.ReadToken("["); string unitName = tokenizer.ReadDoubleQuotedWord(); tokenizer.ReadToken(","); tokenizer.NextToken(); double unitsPerUnit = tokenizer.GetNumericValue(); tokenizer.ReadToken(","); string authority = ""; string authorityCode = ""; tokenizer.ReadAuthority(ref authority, ref authorityCode); tokenizer.ReadToken("]"); switch (unitName) { // take into account the different spellings of the word meter/metre. case "meter": case "metre": unit = new LinearUnit(unitsPerUnit, "", authority, authorityCode, unitName, "", ""); break; case "degree": case "radian": unit = new AngularUnit(unitsPerUnit, "", authority, authorityCode, unitName, "", ""); break; default: throw new NotImplementedException(String.Format("{0} is not recognized a unit of measure.", unitName)); } return(unit); }
private static ICompoundCoordinateSystem ReadCompoundCoordinateSystem(WktStreamTokenizer tokenizer) { /* * COMPD_CS[ * "OSGB36 / British National Grid + ODN", * PROJCS[] * VERT_CS[] * AUTHORITY["EPSG","7405"] * ]*/ //TODO add a ReadCoordinateSystem - that determines the correct coordinate system to //read. Right now this hard coded for a projected and a vertical coord sys - so the UK //national grid works. tokenizer.ReadToken("["); string name = tokenizer.ReadDoubleQuotedWord(); tokenizer.ReadToken(","); tokenizer.NextToken(); string headCSCode = tokenizer.GetStringValue(); ICoordinateSystem headCS = ReadCoordinateSystem(headCSCode, tokenizer); tokenizer.ReadToken(","); tokenizer.NextToken(); string tailCSCode = tokenizer.GetStringValue(); ICoordinateSystem tailCS = ReadCoordinateSystem(tailCSCode, tokenizer); tokenizer.ReadToken(","); string authority = ""; string authorityCode = ""; tokenizer.ReadAuthority(ref authority, ref authorityCode); tokenizer.ReadToken("]"); ICompoundCoordinateSystem compoundCS = new CompoundCoordinateSystem(headCS, tailCS, "", authority, authorityCode, name, "", ""); return(compoundCS); }
private static IEllipsoid ReadEllipsoid(WktStreamTokenizer tokenizer) { //SPHEROID["Airy 1830",6377563.396,299.3249646,AUTHORITY["EPSG","7001"]] tokenizer.ReadToken("["); string name=tokenizer.ReadDoubleQuotedWord(); tokenizer.ReadToken(","); tokenizer.NextToken(); double majorAxis = tokenizer.GetNumericValue(); tokenizer.ReadToken(","); tokenizer.NextToken(); double e = tokenizer.GetNumericValue(); tokenizer.ReadToken(","); string authority=""; string authorityCode=""; tokenizer.ReadAuthority(ref authority, ref authorityCode); tokenizer.ReadToken("]"); IEllipsoid ellipsoid = new Ellipsoid(majorAxis,0.0,e,true,LinearUnit.Meters,"",authority,authorityCode,name,"",""); return ellipsoid; }
private static IGeographicCoordinateSystem ReadGeographicCoordinateSystem(WktStreamTokenizer tokenizer) { /* GEOGCS["OSGB 1936", DATUM["OSGB 1936",SPHEROID["Airy 1830",6377563.396,299.3249646,AUTHORITY["EPSG","7001"]]TOWGS84[0,0,0,0,0,0,0],AUTHORITY["EPSG","6277"]] PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]] AXIS["Geodetic latitude","NORTH"] AXIS["Geodetic longitude","EAST"] AUTHORITY["EPSG","4277"] ] */ tokenizer.ReadToken("["); string name=tokenizer.ReadDoubleQuotedWord(); tokenizer.ReadToken(","); tokenizer.ReadToken("DATUM"); IHorizontalDatum horizontalDatum = ReadHorizontalDatum(tokenizer); tokenizer.ReadToken("PRIMEM"); IPrimeMeridian primeMeridian = ReadPrimeMeridian(tokenizer); tokenizer.ReadToken("AXIS"); IAxisInfo axis0 = ReadAxisInfo(tokenizer); tokenizer.ReadToken(","); tokenizer.ReadToken("AXIS"); IAxisInfo axis1 = ReadAxisInfo(tokenizer); tokenizer.ReadToken(","); string authority=""; string authorityCode=""; tokenizer.ReadAuthority(ref authority, ref authorityCode); tokenizer.ReadToken("]"); // ?? assume angular unit is degrees. IAngularUnit angularUnit = new AngularUnit(180/Math.PI); IGeographicCoordinateSystem geographicCS = new GeographicCoordinateSystem(angularUnit, horizontalDatum, primeMeridian,axis0, axis1,"",authority,authorityCode,name,"",""); return geographicCS; }
private static IHorizontalDatum ReadHorizontalDatum(WktStreamTokenizer tokenizer) { //DATUM["OSGB 1936",SPHEROID["Airy 1830",6377563.396,299.3249646,AUTHORITY["EPSG","7001"]]TOWGS84[0,0,0,0,0,0,0],AUTHORITY["EPSG","6277"]] tokenizer.ReadToken("["); string name=tokenizer.ReadDoubleQuotedWord(); tokenizer.ReadToken(","); tokenizer.ReadToken("SPHEROID"); IEllipsoid ellipsoid = ReadEllipsoid(tokenizer); tokenizer.ReadToken("TOWGS84"); WGS84ConversionInfo wgsInfo = ReadWGS84ConversionInfo(tokenizer); tokenizer.ReadToken(","); string authority=""; string authorityCode=""; tokenizer.ReadAuthority(ref authority, ref authorityCode); // make an assumption about the datum type. DatumType datumType = DatumType.IHD_Geocentric; IHorizontalDatum horizontalDatum = new HorizontalDatum(name,datumType,ellipsoid, wgsInfo,"",authority,authorityCode,"",""); tokenizer.ReadToken("]"); return horizontalDatum; }
private static IPrimeMeridian ReadPrimeMeridian(WktStreamTokenizer tokenizer) { //PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]] tokenizer.ReadToken("["); string name=tokenizer.ReadDoubleQuotedWord(); tokenizer.ReadToken(","); tokenizer.NextToken(); double longitude = tokenizer.GetNumericValue(); tokenizer.ReadToken(","); string authority=""; string authorityCode=""; tokenizer.ReadAuthority(ref authority, ref authorityCode); // make an assumption about the Angular units - degrees. IPrimeMeridian primeMeridian = new PrimeMeridian(name,new AngularUnit(180/Math.PI),longitude,"",authority,authorityCode,"",""); tokenizer.ReadToken("]"); return primeMeridian; }
private static ICompoundCoordinateSystem ReadCompoundCoordinateSystem(WktStreamTokenizer tokenizer) { /* COMPD_CS[ "OSGB36 / British National Grid + ODN", PROJCS[] VERT_CS[] AUTHORITY["EPSG","7405"] ]*/ //TODO add a ReadCoordinateSystem - that determines the correct coordinate system to //read. Right now this hard coded for a projected and a vertical coord sys - so the UK //national grid works. tokenizer.ReadToken("["); string name=tokenizer.ReadDoubleQuotedWord(); tokenizer.ReadToken(","); tokenizer.NextToken(); string headCSCode = tokenizer.GetStringValue(); ICoordinateSystem headCS = ReadCoordinateSystem(headCSCode,tokenizer); tokenizer.ReadToken(","); tokenizer.NextToken(); string tailCSCode = tokenizer.GetStringValue(); ICoordinateSystem tailCS = ReadCoordinateSystem(tailCSCode,tokenizer); tokenizer.ReadToken(","); string authority=""; string authorityCode=""; tokenizer.ReadAuthority(ref authority, ref authorityCode); tokenizer.ReadToken("]"); ICompoundCoordinateSystem compoundCS = new CompoundCoordinateSystem(headCS,tailCS,"",authority,authorityCode,name,"",""); return compoundCS; }
private static IVerticalDatum ReadVerticalDatum(WktStreamTokenizer tokenizer) { //VERT_DATUM["Ordnance Datum Newlyn",2005,AUTHORITY["5101","EPSG"]] tokenizer.ReadToken("["); string datumName=tokenizer.ReadDoubleQuotedWord(); tokenizer.ReadToken(","); tokenizer.NextToken(); string datumTypeNumber = tokenizer.GetStringValue(); tokenizer.ReadToken(","); string authority=""; string authorityCode=""; tokenizer.ReadAuthority(ref authority, ref authorityCode); DatumType datumType = (DatumType)Enum.Parse(typeof(DatumType),datumTypeNumber); IVerticalDatum verticalDatum = new VerticalDatum(datumType,"",authorityCode,authority,datumName,"",""); tokenizer.ReadToken("]"); return verticalDatum; }
private static IVerticalCoordinateSystem ReadVerticalCoordinateSystem(WktStreamTokenizer tokenizer) { /* VERT_CS["Newlyn", VERT_DATUM["Ordnance Datum Newlyn",2005,AUTHORITY["EPSG","5101"]] UNIT["metre",1,AUTHORITY["EPSG","9001"]] AUTHORITY["EPSG","5701"] */ tokenizer.ReadToken("["); string name=tokenizer.ReadDoubleQuotedWord(); tokenizer.ReadToken(","); tokenizer.ReadToken("VERT_DATUM"); IVerticalDatum verticalDatum = ReadVerticalDatum(tokenizer); tokenizer.ReadToken("UNIT"); IUnit unit = ReadUnit(tokenizer); string authority=""; string authorityCode=""; tokenizer.ReadAuthority(ref authority, ref authorityCode); tokenizer.ReadToken("]"); IVerticalCoordinateSystem verticalCS = new VerticalCoordinateSystem(name,verticalDatum,"",authority,authorityCode,"",""); return verticalCS; }
/// <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) { //UNIT["degree",0.01745329251994433,AUTHORITY["EPSG","9102"]] IUnit unit=null; tokenizer.ReadToken("["); string unitName=tokenizer.ReadDoubleQuotedWord(); tokenizer.ReadToken(","); tokenizer.NextToken(); double unitsPerUnit = tokenizer.GetNumericValue(); tokenizer.ReadToken(","); string authority=""; string authorityCode=""; tokenizer.ReadAuthority(ref authority, ref authorityCode); tokenizer.ReadToken("]"); switch (unitName) { // take into account the different spellings of the word meter/metre. case "meter": case "metre": unit = new LinearUnit(unitsPerUnit,"",authority,authorityCode,unitName,"",""); break; case "degree": case "radian": unit = new AngularUnit(unitsPerUnit,"",authority,authorityCode,unitName,"",""); break; default: throw new NotImplementedException(String.Format(System.Globalization.CultureInfo.InvariantCulture, "{0} is not recognized a unit of measure.",unitName)); } return unit; }
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); IAxisInfo axis0 = ReadAxisInfo(tokenizer); tokenizer.ReadToken(","); tokenizer.ReadToken("AXIS"); IAxisInfo axis1 = ReadAxisInfo(tokenizer); tokenizer.ReadToken(","); string authority=""; string authorityCode=""; tokenizer.ReadAuthority(ref authority, ref authorityCode); tokenizer.ReadToken("]"); IAxisInfo[] axisArray = new IAxisInfo[2]; axisArray[0]=axis0; axisArray[1]=axis1; ILinearUnit linearUnit = LinearUnit.Meters; IProjectedCoordinateSystem projectedCS = new ProjectedCoordinateSystem(null,axisArray,geographicCS,linearUnit, projection,"",authority,authorityCode,name,"",""); return projectedCS; }