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); }
/// <summary> /// /// </summary> /// <param name="tokenizer"></param> /// <returns></returns> 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"]] Wgs84ConversionInfo wgsInfo = null; string authority = String.Empty; long authorityCode = -1; tokenizer.ReadToken("["); string name = tokenizer.ReadDoubleQuotedWord(); tokenizer.ReadToken(","); tokenizer.ReadToken("SPHEROID"); IEllipsoid ellipsoid = ReadEllipsoid(tokenizer); tokenizer.NextToken(); while (tokenizer.GetStringValue() == ",") { tokenizer.NextToken(); if (tokenizer.GetStringValue() == "TOWGS84") { wgsInfo = ReadWGS84ConversionInfo(tokenizer); tokenizer.NextToken(); } else if (tokenizer.GetStringValue() == "AUTHORITY") { tokenizer.ReadAuthority(ref authority, ref authorityCode); tokenizer.ReadToken("]"); } } // make an assumption about the datum type. IHorizontalDatum horizontalDatum = new HorizontalDatum(ellipsoid, wgsInfo, DatumType.HD_Geocentric, name, authority, authorityCode, String.Empty, String.Empty, String.Empty); return(horizontalDatum); }
/// <summary> /// Reads a horizontal datum. /// </summary> private static IHorizontalDatum ReadHorizontalDatum(WktStreamTokenizer tokenizer) { Wgs84ConversionInfo wgsInfo = null; string authority = String.Empty; long authorityCode = -1; tokenizer.ReadToken("["); string name = tokenizer.ReadDoubleQuotedWord(); tokenizer.ReadToken(","); tokenizer.ReadToken("SPHEROID"); IEllipsoid ellipsoid = ReadEllipsoid(tokenizer); tokenizer.NextToken(); while (tokenizer.GetStringValue() == ",") { tokenizer.NextToken(); if (tokenizer.GetStringValue() == "TOWGS84") { wgsInfo = ReadWGS84ConversionInfo(tokenizer); tokenizer.NextToken(); } else if (tokenizer.GetStringValue() == "AUTHORITY") { //tokenizer.ReadAuthority(ref authority, ref authorityCode); ReadAuthority(tokenizer, ref authority, ref authorityCode); tokenizer.ReadToken("]"); } } IHorizontalDatum horizontalDatum = new HorizontalDatum(ellipsoid, wgsInfo, DatumType.HD_Geocentric, name, authority, authorityCode, String.Empty, String.Empty, String.Empty); return(horizontalDatum); }
private static IHorizontalDatum ReadHorizontalDatum(XmlTextReader reader) { if (!(reader.NodeType == XmlNodeType.Element && reader.Name == "CS_HorizontalDatum")) { throw new ParseException(String.Format("Expected a IHorizontalDatum but got a {0} at line {1} col {2}", reader.Name, reader.LineNumber, reader.LinePosition)); } /* <IHorizontalDatum DatumType="1001"> * <IInfo AuthorityCode="6277" Authority="EPSG" Name="OSGB_1936"/> * <IEllipsoid SemiMajorAxis="6377563.396" SemiMinorAxis="6356256.90923729" InverseFlattening="299.3249646" IvfDefinitive="1"> * <IInfo AuthorityCode="7001" Authority="EPSG" Name="Airy 1830"/> * <ILinearUnit MetersPerUnit="1"> * <IInfo AuthorityCode="9001" Abbreviation="m" Authority="EPSG" Name="metre"/> * </ILinearUnit> * </IEllipsoid> * <IWGS84ConversionInfo Dx="375" Dy="-111" Dz="431" Ex="0" Ey="0" Ez="0" Ppm="0"/> * </IHorizontalDatum> */ string datumTypeString = reader.GetAttribute("DatumType"); DatumType datumType = (DatumType)Enum.Parse(typeof(DatumType), datumTypeString, true); string authority = "", authorityCode = "", abbreviation = "", name = ""; reader.Read(); ReadInfo(reader, ref authority, ref authorityCode, ref abbreviation, ref name); IEllipsoid ellipsoid = ReadEllipsoid(reader); WGS84ConversionInfo wgs84info = ReadWGS84ConversionInfo(reader); reader.Read(); HorizontalDatum horizontalDatum = new HorizontalDatum(name, datumType, ellipsoid, wgs84info, "", authority, authorityCode, "", abbreviation); return(horizontalDatum); }
/// <summary> /// /// </summary> /// <param name="tokenizer"></param> /// <returns></returns> private static GeoAPI.CoordinateSystems.IHorizontalDatum ReadHorizontalDatum(GisSharpBlog.NetTopologySuite.IO.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"); GeoAPI.CoordinateSystems.IEllipsoid ellipsoid = ReadEllipsoid(tokenizer); tokenizer.ReadToken(","); GeoAPI.CoordinateSystems.Wgs84ConversionInfo wgsInfo = new GeoAPI.CoordinateSystems.Wgs84ConversionInfo(); if (tokenizer.GetStringValue() == "TOWGS84") { tokenizer.ReadToken("TOWGS84"); wgsInfo = ReadWGS84ConversionInfo(tokenizer); tokenizer.ReadToken(","); } string authority = String.Empty; long authorityCode = -1; tokenizer.ReadAuthority(ref authority, ref authorityCode); // make an assumption about the datum type. GeoAPI.CoordinateSystems.IHorizontalDatum horizontalDatum = new HorizontalDatum(ellipsoid, wgsInfo, GeoAPI.CoordinateSystems.DatumType.HD_Geocentric, name, authority, authorityCode, String.Empty, String.Empty, String.Empty); tokenizer.ReadToken("]"); return(horizontalDatum); }
public void Test_Constructor() { IEllipsoid ellipsoid = new Ellipsoid(20926348, -1.0, 294.26068, true, new LinearUnit(1)); WGS84ConversionInfo wgsInfo = new WGS84ConversionInfo(); wgsInfo.Dx = 1.0; HorizontalDatum horizontalDatum = new HorizontalDatum("name", DatumType.IHD_Geocentric, ellipsoid, wgsInfo); Assertion.AssertEquals("test 1", "name", horizontalDatum.Name); Assertion.AssertEquals("test 2", DatumType.IHD_Geocentric, horizontalDatum.DatumType); Assertion.AssertEquals("test 3", ellipsoid, horizontalDatum.Ellipsoid); Assertion.AssertEquals("test 4", wgsInfo, horizontalDatum.WGS84Parameters); }
public void Test_Constructor() { IEllipsoid ellipsoid = new Ellipsoid(20926348, -1.0, 294.26068, true, new LinearUnit(1)); WGS84ConversionInfo wgsInfo = new WGS84ConversionInfo(); wgsInfo.Dx = 1.0; HorizontalDatum horizontalDatum = new HorizontalDatum("name", DatumType.IHD_Geocentric, ellipsoid, wgsInfo); IAxisInfo[] axisInfos = new IAxisInfo[2]; axisInfos[0] = AxisInfo.Latitude; axisInfos[1] = AxisInfo.Longitude; HorizontalCoordinateSystem horzCS = new HorizontalCoordinateSystem(horizontalDatum, axisInfos, "remarks", "authority", "code", "name", "alias", "abbreviation"); Assertion.AssertEquals("ctor1.", "remarks", horzCS.Remarks); Assertion.AssertEquals("ctor2.", "authority", horzCS.Authority); Assertion.AssertEquals("ctor3.", "code", horzCS.AuthorityCode); Assertion.AssertEquals("ctor4.", "name", horzCS.Name); Assertion.AssertEquals("ctor5.", "alias", horzCS.Alias); Assertion.AssertEquals("ctor6.", "abbreviation", horzCS.Abbreviation); Assertion.AssertEquals("test 7", horizontalDatum, horzCS.HorizontalDatum); //Assertion.AssertEquals("test 8",axisInfos[0],horzCS.GetAxis(0)); //Assertion.AssertEquals("test 9",axisInfos[1],horzCS.GetAxis(1)); }
private string WKTFromDatum(HorizontalDatum datum) { StringBuilder sb = new StringBuilder(); //CF needs a CultureInfo overload.This can likely be changed in the full framework version with no ill effect. System.Globalization.CultureInfo CI = new System.Globalization.CultureInfo(""); sb.AppendFormat(CI, "DATUM[\"{0}\", {1}", datum.Name, datum.Ellipsoid.WKT); if (datum.Wgs84Parameters != null) { sb.AppendFormat(CI, ", {0}", datum.Wgs84Parameters.WKT); } if (!String.IsNullOrEmpty(datum.Authority) && datum.AuthorityCode > 0) { sb.AppendFormat(CI, ", AUTHORITY[\"{0}\", \"{1}\"]", datum.Authority, datum.AuthorityCode); } if (!String.IsNullOrEmpty(datum.Abbreviation)) { sb.AppendFormat(CI, ", ABBREVIATION[\"{0}\"]", datum.Abbreviation); } sb.Append("]"); return(sb.ToString()); }
public void TestDatumTransform() { CoordinateSystemFactory cFac = new CoordinateSystemFactory(); //Define datums HorizontalDatum wgs72 = HorizontalDatum.WGS72; HorizontalDatum ed50 = HorizontalDatum.ED50; //Define geographic coordinate systems IGeographicCoordinateSystem gcsWGS72 = cFac.CreateGeographicCoordinateSystem("WGS72 Geographic", AngularUnit.Degrees, wgs72, PrimeMeridian.Greenwich, new AxisInfo("East", AxisOrientationEnum.East), new AxisInfo("North", AxisOrientationEnum.North)); IGeographicCoordinateSystem gcsWGS84 = cFac.CreateGeographicCoordinateSystem("WGS84 Geographic", AngularUnit.Degrees, HorizontalDatum.WGS84, PrimeMeridian.Greenwich, new AxisInfo("East", AxisOrientationEnum.East), new AxisInfo("North", AxisOrientationEnum.North)); IGeographicCoordinateSystem gcsED50 = cFac.CreateGeographicCoordinateSystem("ED50 Geographic", AngularUnit.Degrees, ed50, PrimeMeridian.Greenwich, new AxisInfo("East", AxisOrientationEnum.East), new AxisInfo("North", AxisOrientationEnum.North)); //Define geocentric coordinate systems IGeocentricCoordinateSystem gcenCsWGS72 = cFac.CreateGeocentricCoordinateSystem("WGS72 Geocentric", wgs72, LinearUnit.Metre, PrimeMeridian.Greenwich); IGeocentricCoordinateSystem gcenCsWGS84 = cFac.CreateGeocentricCoordinateSystem("WGS84 Geocentric", HorizontalDatum.WGS84, LinearUnit.Metre, PrimeMeridian.Greenwich); IGeocentricCoordinateSystem gcenCsED50 = cFac.CreateGeocentricCoordinateSystem("ED50 Geocentric", ed50, LinearUnit.Metre, PrimeMeridian.Greenwich); //Define projections List <ProjectionParameter> parameters = new List <ProjectionParameter>(5); parameters.Add(new ProjectionParameter("latitude_of_origin", 0)); parameters.Add(new ProjectionParameter("central_meridian", 9)); parameters.Add(new ProjectionParameter("scale_factor", 0.9996)); parameters.Add(new ProjectionParameter("false_easting", 500000)); parameters.Add(new ProjectionParameter("false_northing", 0)); IProjection projection = cFac.CreateProjection("Transverse Mercator", "Transverse_Mercator", parameters); IProjectedCoordinateSystem utmED50 = cFac.CreateProjectedCoordinateSystem("ED50 UTM Zone 32N", gcsED50, projection, LinearUnit.Metre, new AxisInfo("East", AxisOrientationEnum.East), new AxisInfo("North", AxisOrientationEnum.North)); IProjectedCoordinateSystem utmWGS84 = cFac.CreateProjectedCoordinateSystem("WGS84 UTM Zone 32N", gcsWGS84, projection, LinearUnit.Metre, new AxisInfo("East", AxisOrientationEnum.East), new AxisInfo("North", AxisOrientationEnum.North)); //Set TOWGS84 parameters wgs72.Wgs84Parameters = new Wgs84ConversionInfo(0, 0, 4.5, 0, 0, 0.554, 0.219); ed50.Wgs84Parameters = new Wgs84ConversionInfo(-81.0703, -89.3603, -115.7526, -0.48488, -0.02436, -0.41321, -0.540645); //Parameters for Denmark //Set up coordinate transformations CoordinateTransformationFactory ctFac = new CoordinateTransformationFactory(); ICoordinateTransformation ctForw = ctFac.CreateFromCoordinateSystems(gcsWGS72, gcenCsWGS72); //Geographic->Geocentric (WGS72) ICoordinateTransformation ctWGS84_Gcen2Geo = ctFac.CreateFromCoordinateSystems(gcenCsWGS84, gcsWGS84); //Geocentric->Geographic (WGS84) ICoordinateTransformation ctWGS84_Geo2UTM = ctFac.CreateFromCoordinateSystems(gcsWGS84, utmWGS84); //UTM ->Geographic (WGS84) ICoordinateTransformation ctED50_UTM2Geo = ctFac.CreateFromCoordinateSystems(utmED50, gcsED50); //UTM ->Geographic (ED50) ICoordinateTransformation ctED50_Geo2Gcen = ctFac.CreateFromCoordinateSystems(gcsED50, gcenCsED50); //Geographic->Geocentric (ED50) //Test datum-shift from WGS72 to WGS84 //Point3D pGeoCenWGS72 = ctForw.MathTransform.Transform(pLongLatWGS72) as Point3D; double[] pGeoCenWGS72 = new double[] { 3657660.66, 255768.55, 5201382.11 }; ICoordinateTransformation geocen_ed50_2_Wgs84 = ctFac.CreateFromCoordinateSystems(gcenCsWGS72, gcenCsWGS84); double[] pGeoCenWGS84 = geocen_ed50_2_Wgs84.MathTransform.Transform(pGeoCenWGS72); //Point3D pGeoCenWGS84 = wgs72.Wgs84Parameters.Apply(pGeoCenWGS72); Assert.IsTrue(ToleranceLessThan(new double[] { 3657660.78, 255778.43, 5201387.75 }, pGeoCenWGS84, 0.01)); ICoordinateTransformation utm_ed50_2_Wgs84 = ctFac.CreateFromCoordinateSystems(utmED50, utmWGS84); double[] pUTMED50 = new double[] { 600000, 6100000 }; double[] pUTMWGS84 = utm_ed50_2_Wgs84.MathTransform.Transform(pUTMED50); Assert.IsTrue(ToleranceLessThan(new double[] { 599928.6, 6099790.2 }, pUTMWGS84, 0.1)); //Perform reverse ICoordinateTransformation utm_Wgs84_2_Ed50 = ctFac.CreateFromCoordinateSystems(utmWGS84, utmED50); pUTMED50 = utm_Wgs84_2_Ed50.MathTransform.Transform(pUTMWGS84); Assert.IsTrue(ToleranceLessThan(new double[] { 600000, 6100000 }, pUTMED50, 0.1)); //Assert.IsTrue(Math.Abs((pUTMWGS84 as Point3D).Z - 36.35) < 0.5); //Point pExpected = Point.FromDMS(2, 7, 46.38, 53, 48, 33.82); //ED50_to_WGS84_Denmark: datum.Wgs84Parameters = new Wgs84ConversionInfo(-89.5, -93.8, 127.6, 0, 0, 4.5, 1.2); }
private void addDatum(HorizontalDatum datum) { if (!datumsHashTable.ContainsKey(datum.Alias)) { datumsHashTable.Add(datum.Alias, 0); datums.Add(datum); } }
private void parseDatumFiles() { string filename = null; string line = null; string[] parts = null; StreamReader sr = null; FileStream file = null; char[] chSplit = { ',' }; System.Globalization.CultureInfo ci = System.Globalization.CultureInfo.CurrentCulture; System.Globalization.NumberFormatInfo ni = null; ni = (System.Globalization.NumberFormatInfo)ci.NumberFormat.Clone(); ni.NumberDecimalSeparator = "."; for (int i = config.EllipsoidFilList.Count - 1; i >= 0; i--) { filename = String.Format("{0}//{1}", config.ApplicationDirectory, config.EllipsoidFilList[i]); if (File.Exists(filename)) { // test if there are valid ellipsoid information in and add them to our map try { file = new FileStream(filename, FileMode.Open, FileAccess.Read); sr = new StreamReader(file); while ((line = sr.ReadLine()) != null) { // the file is organized in this way: NAME,CODE,A,B,RF // A and B are double precission numbers with a decimal point "." try { parts = line.Split(chSplit); referenceEllipsoids.Add(parts[1].Trim(), new Ellipsoid(Double.Parse(parts[2], ni), Double.Parse(parts[3], ni), Double.Parse(parts[4], ni), false, LinearUnit.Metre, parts[0].Trim(), String.Empty, 0, parts[0].Trim(), parts[1].Trim(), String.Empty)); } catch { // just ignore the wrong line and keep on } } } catch (Exception) { // we ignore the errors, clean up and move on to the next file // if data has been inserted into the reference layers dicronary we will use it } finally { if (sr != null) sr.Close(); if (file != null) file.Close(); } } } // parse datum files Ellipsoid el = null; String tempStr = String.Empty; HorizontalDatum datum; for (int i = config.DatumFileList.Count - 1; i >= 0; i--) { filename = String.Format("{0}\\{1}", config.ApplicationDirectory, config.DatumFileList[i]); if (File.Exists(filename)) { // test if there is valid datum information in and add them to our dictionary try { file = new FileStream(filename, FileMode.Open, FileAccess.Read); sr = new StreamReader(file); while ((line = sr.ReadLine()) != null) { // the file is organized in this way: CODE,NAME,ELLIPSOID,DELTAX,SIGMAX,DELTAY,SIGMAY,DELTAZ,SIGMAZ,ROTX,ROTY,ROTZ,SCALE // A and B are double precission numbers with a decimal point "." try { parts = splitEx(line, chSplit, new char[] { '\"' }); if (referenceEllipsoids.TryGetValue(parts[2].Trim(), out el)) { tempStr = parts[0].Trim(); datum = new HorizontalDatum(el, new Wgs84ConversionInfo( Double.Parse(parts[3].Trim()), Double.Parse(parts[5].Trim()), Double.Parse(parts[7].Trim()), Double.Parse(parts[9].Trim()), Double.Parse(parts[10].Trim()), Double.Parse(parts[11].Trim()), Double.Parse(parts[12].Trim())), DatumType.HD_Geocentric, parts[1].Trim('\"'), String.Empty, 0, String.Empty, tempStr, String.Empty); addDatum(datum); } } catch { // just ignore the wrong line and keep going } } } catch (Exception) { // we ignore the errors, clean up and move on to the next file // if data has been inserted into the reference layers dicronary we will use it } finally { datum = null; if (sr != null) sr.Close(); if (file != null) file.Close(); } } } }
private string WKTFromDatum(HorizontalDatum datum) { StringBuilder sb = new StringBuilder(); //CF needs a CultureInfo overload.This can likely be changed in the full framework version with no ill effect. System.Globalization.CultureInfo CI = new System.Globalization.CultureInfo(""); sb.AppendFormat(CI, "DATUM[\"{0}\", {1}", datum.Name, datum.Ellipsoid.WKT); if (datum.Wgs84Parameters != null) sb.AppendFormat(CI, ", {0}", datum.Wgs84Parameters.WKT); if (!String.IsNullOrEmpty(datum.Authority) && datum.AuthorityCode > 0) sb.AppendFormat(CI, ", AUTHORITY[\"{0}\", \"{1}\"]", datum.Authority, datum.AuthorityCode); if (!String.IsNullOrEmpty(datum.Abbreviation)) sb.AppendFormat(CI, ", ABBREVIATION[\"{0}\"]", datum.Abbreviation); sb.Append("]"); return sb.ToString(); }
public void SetDefaults() { string personalFolder = Environment.GetFolderPath(Environment.SpecialFolder.Personal); this.searchDirList.Add(personalFolder); this.searchDirList.Add(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\" + programName); this.exPntLayerFile = personalFolder + "\\timberNet\\transferPunkt.shp"; this.exPLineLayerFile = personalFolder + "\\timberNet\\transferPolyline.shp"; this.exPGonLayerFile = personalFolder + "\\timberNet\\transferPolygon.shp"; this.categoryList.Add("Kommentar"); this.categoryList.Add("Baum"); this.categoryList.Add("Fläche"); this.horizontalDatum = HorizontalDatum.Bessel1841; this.GPSTrackingTimeInterval = 5000; this.GPSTrackingComment = "GPS"; this.GPSTrackingDiscardSamePositions = true; this.UseGPS = false; this.KeyMapping_Up = HardwareKeyMappings.None; this.KeyMapping_Down = HardwareKeyMappings.None; this.KeyMapping_Left = HardwareKeyMappings.GPSTrackingTrigger; this.KeyMapping_Right = HardwareKeyMappings.GPSTrackingStop; this.KeyMapping_Enter = HardwareKeyMappings.TempMove; InitStaticData(); }