internal GeographicCoordinateSystem( IAngularUnit angularUnit, IHorizontalDatum horizontalDatum, IPrimeMeridian primeMeridian, IAxisInfo axis0, IAxisInfo axis1, string remarks, string authority, string authorityCode, string name, string alias, string abbreviation) : base(remarks, authority, authorityCode, name, alias, abbreviation) { _angularUnit = angularUnit; _horizontalDatum = horizontalDatum; _primeMeridian = primeMeridian; _axisInfo = new IAxisInfo[]{axis0,axis1}; CoordinatePoint minPt = new CoordinatePoint(); minPt.Ord= new Double[2]; minPt.Ord.SetValue(-180,0); minPt.Ord.SetValue(-90,1); CoordinatePoint maxPt = new CoordinatePoint(); maxPt.Ord= new Double[2]; maxPt.Ord.SetValue(-180,0); maxPt.Ord.SetValue(-90,1); // define the envelope. _defaultEnvelope = new Positioning.Envelope(); _defaultEnvelope.MinCP = minPt; _defaultEnvelope.MaxCP = maxPt; }
/// <summary> /// create a crazy coordinate system /// </summary> /// <returns></returns> private ISpatialReference CreateGeographicSpatialReference() { ISpatialReferenceFactory spatialRefFatcory = new SpatialReferenceEnvironmentClass(); IGeographicCoordinateSystem geoCoordSys; geoCoordSys = spatialRefFatcory.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_WGS1984); //assign a user defined datum to the SR (just for the test) IDatum datum = new DatumClass(); IDatumEdit datumEdit = (IDatumEdit)datum; ISpheroid spheroid = spatialRefFatcory.CreateSpheroid((int)esriSRSpheroidType.esriSRSpheroid_Clarke1880); datumEdit.DefineEx("MyDatum", "My Datum", "MDTM", "", spheroid); IPrimeMeridian primeMeridian = spatialRefFatcory.CreatePrimeMeridian((int)esriSRPrimeMType.esriSRPrimeM_Greenwich); IAngularUnit angularUnits = spatialRefFatcory.CreateUnit((int)esriSRUnitType.esriSRUnit_Degree) as IAngularUnit; IGeographicCoordinateSystemEdit geoCoordSysEdit = (IGeographicCoordinateSystemEdit)geoCoordSys; geoCoordSysEdit.DefineEx("MyGeoCoordSys", "MyGeoCoordSys", "MGCS", "", "", datum, primeMeridian, angularUnits); geoCoordSys.SetFalseOriginAndUnits(-180.0, -180.0, 5000000.0); geoCoordSys.SetZFalseOriginAndUnits(0.0, 100000.0); geoCoordSys.SetMFalseOriginAndUnits(0.0, 100000.0); return(geoCoordSys as ISpatialReference); }
/// <summary> /// Creates a prime meridian given a code. /// </summary> /// <param name="code">The EPSG code of the prime meridian.</param> /// <returns>An object that implements the IPrimeMeridian interface.</returns> public IPrimeMeridian CreatePrimeMeridian(string code) { if (code == null) { throw new ArgumentNullException("code"); } string sqlQuery = "SELECT PRIME_MERIDIAN_CODE, PRIME_MERIDIAN_NAME,GREENWICH_LONGITUDE," + " UOM_CODE,REMARKS,INFORMATION_SOURCE,DATA_SOURCE "+ "FROM [Prime Meridian]" + "WHERE PRIME_MERIDIAN_CODE={0}"; sqlQuery = String.Format(System.Globalization.CultureInfo.InvariantCulture, sqlQuery, code); IDataReader reader = Database.ExecuteQuery(_databaseConnection, sqlQuery); IPrimeMeridian primeMeridian = null; bool recordFound = reader.Read(); if (!recordFound) { throw new ArgumentOutOfRangeException(String.Format(System.Globalization.CultureInfo.InvariantCulture, "Prime meridian with a code of '{0}' was not found in the database.", code)); } double degreesFromGreenwich = (double)reader["GREENWICH_LONGITUDE"]; string remarks = reader["REMARKS"].ToString(); string name = reader["PRIME_MERIDIAN_NAME"].ToString(); string datasource = reader["DATA_SOURCE"].ToString(); string unitsOfMeasure = reader["UOM_CODE"].ToString(); Database.CheckOneRow(reader, code, "Prime meridian"); IAngularUnit degrees = this.CreateAngularUnit(unitsOfMeasure); primeMeridian = new PrimeMeridian(name, degrees, degreesFromGreenwich, remarks, datasource, code, "", ""); return(primeMeridian); }
private static IGeographicCoordinateSystem ReadGeographicCoordinateSystem(XmlTextReader reader) { if (!(reader.NodeType == XmlNodeType.Element && reader.Name == "CS_GeographicCoordinateSystem")) { throw new ParseException(String.Format("Expected a IGeographicCoordinateSystem but got a {0} at line {1} col {2}", reader.Name, reader.LineNumber, reader.LinePosition)); } string authority = "", authorityCode = "", abbreviation = "", name = ""; reader.Read(); ReadInfo(reader, ref authority, ref authorityCode, ref abbreviation, ref name); //reader.Read(); ArrayList list = new ArrayList(); while (reader.NodeType == XmlNodeType.Element && reader.Name == "CS_AxisInfo") { IAxisInfo axis = ReadAxisInfo(reader); list.Add(axis); reader.Read(); } IAxisInfo[] axisInfos = new IAxisInfo[list.Count]; axisInfos = (IAxisInfo[])list.ToArray(typeof(IAxisInfo)); IHorizontalDatum horizontalDatum = ReadHorizontalDatum(reader); //reader.Read(); IAngularUnit angularUnit = ReadAngularUnit(reader); //reader.Read(); IPrimeMeridian primeMeridian = ReadPrimeMeridian(reader); reader.Read(); IGeographicCoordinateSystem geographicCoordinateSystem = new GeographicCoordinateSystem(angularUnit, horizontalDatum, primeMeridian, axisInfos[0], axisInfos[1], "", authority, authorityCode, name, "", abbreviation); return(geographicCoordinateSystem); }
/// <summary> /// Creates an instance of a Geographic Coordinate System /// </summary> /// <param name="angularUnit">Angular units</param> /// <param name="horizontalDatum">Horizontal datum</param> /// <param name="primeMeridian">Prime meridian</param> /// <param name="axisInfo">Axis info</param> /// <param name="name">Name</param> /// <param name="authority">Authority name</param> /// <param name="authorityCode">Authority-specific identification code.</param> /// <param name="alias">Alias</param> /// <param name="abbreviation">Abbreviation</param> /// <param name="remarks">Provider-supplied remarks</param> internal GeographicCoordinateSystem(IAngularUnit angularUnit, IHorizontalDatum horizontalDatum, IPrimeMeridian primeMeridian, List<AxisInfo> axisInfo, string name, string authority, long authorityCode, string alias, string abbreviation, string remarks) : base(horizontalDatum, axisInfo, name, authority, authorityCode, alias, abbreviation, remarks) { _AngularUnit = angularUnit; _PrimeMeridian = primeMeridian; }
public void Test_PrimeMeridian() { IPrimeMeridian primeMeridian = _factory.CreatePrimeMeridian("8902"); Assertion.AssertEquals("PrimeMeridian - degress from Greenwich", -9.0754862, primeMeridian.Longitude); Assertion.AssertEquals("PrimeMeridian - remarks", "", primeMeridian.Remarks); }
/// <summary> /// Creates an instance of a Geographic Coordinate System /// </summary> /// <param name="angularUnit">Angular units</param> /// <param name="horizontalDatum">Horizontal datum</param> /// <param name="primeMeridian">Prime meridian</param> /// <param name="axisInfo">Axis info</param> /// <param name="name">Name</param> /// <param name="authority">Authority name</param> /// <param name="authorityCode">Authority-specific identification code.</param> /// <param name="alias">Alias</param> /// <param name="abbreviation">Abbreviation</param> /// <param name="remarks">Provider-supplied remarks</param> internal GeographicCoordinateSystem(IAngularUnit angularUnit, IHorizontalDatum horizontalDatum, IPrimeMeridian primeMeridian, List <AxisInfo> axisInfo, string name, string authority, long authorityCode, string alias, string abbreviation, string remarks) : base(horizontalDatum, axisInfo, name, authority, authorityCode, alias, abbreviation, remarks) { _AngularUnit = angularUnit; _PrimeMeridian = primeMeridian; }
internal GeographicCoordinateSystem( IAngularUnit angularUnit, IHorizontalDatum horizontalDatum, IPrimeMeridian primeMeridian, IAxisInfo axis0, IAxisInfo axis1, string remarks, string authority, string authorityCode, string name, string alias, string abbreviation) : base(remarks, authority, authorityCode, name, alias, abbreviation) { _angularUnit = angularUnit; _horizontalDatum = horizontalDatum; _primeMeridian = primeMeridian; _axisInfo = new IAxisInfo[] { axis0, axis1 }; CoordinatePoint minPt = new CoordinatePoint(); minPt.Ord = new Double[2]; minPt.Ord.SetValue(-180, 0); minPt.Ord.SetValue(-90, 1); CoordinatePoint maxPt = new CoordinatePoint(); maxPt.Ord = new Double[2]; maxPt.Ord.SetValue(-180, 0); maxPt.Ord.SetValue(-90, 1); // define the envelope. _defaultEnvelope = new Positioning.Envelope(); _defaultEnvelope.MinCP = minPt; _defaultEnvelope.MaxCP = maxPt; }
private static void WritePrimeMeridian(IPrimeMeridian primeMeridian, XmlTextWriter writer) { writer.WriteStartElement("CS_PrimeMeridian"); writer.WriteAttributeString("Longitude", primeMeridian.Longitude.ToString()); WriteCSInfo(primeMeridian, writer); WriteAngularUnit(primeMeridian.AngularUnit, writer); writer.WriteEndElement(); }
/// <summary> /// Reads a geographic coordinate system. /// </summary> private static IGeographicCoordinateSystem ReadGeographicCoordinateSystem(WktStreamTokenizer tokenizer) { tokenizer.ReadToken("["); string name = tokenizer.ReadDoubleQuotedWord(); tokenizer.ReadToken(","); tokenizer.ReadToken("DATUM"); IHorizontalDatum horizontalDatum = ReadHorizontalDatum(tokenizer); tokenizer.ReadToken(","); tokenizer.ReadToken("PRIMEM"); IPrimeMeridian primeMeridian = ReadPrimeMeridian(tokenizer); tokenizer.ReadToken(","); tokenizer.ReadToken("UNIT"); IAngularUnit angularUnit = ReadAngularUnit(tokenizer); string authority = String.Empty; long authorityCode = -1; tokenizer.NextToken(); List <AxisInfo> info = new List <AxisInfo>(2); if (tokenizer.GetStringValue() == ",") { tokenizer.NextToken(); while (tokenizer.GetStringValue() == "AXIS") { info.Add(ReadAxis(tokenizer)); tokenizer.NextToken(); if (tokenizer.GetStringValue() == ",") { tokenizer.NextToken(); } } if (tokenizer.GetStringValue() == ",") { tokenizer.NextToken(); } if (tokenizer.GetStringValue() == "AUTHORITY") { //tokenizer.ReadAuthority(ref authority, ref authorityCode); ReadAuthority(tokenizer, ref authority, ref authorityCode); tokenizer.ReadToken("]"); } } // значения по умолчанию для осей if (info.Count == 0) { info.Add(new AxisInfo("Lon", AxisOrientationEnum.East)); info.Add(new AxisInfo("Lat", AxisOrientationEnum.North)); } IGeographicCoordinateSystem geographicCS = new GeographicCoordinateSystem(angularUnit, horizontalDatum, primeMeridian, info, name, authority, authorityCode, String.Empty, String.Empty, String.Empty); return(geographicCS); }
internal GeographicCoordinateSystem(string name, IAngularUnit angularUnit, IHorizontalDatum horizontalDatum, IPrimeMeridian primeMeridian, IAxisInfo axis0, IAxisInfo axis1) : this(angularUnit, horizontalDatum, primeMeridian, axis0, axis1, "", "", "", name, "", "") { }
private static void WritePrimeMeridian(IPrimeMeridian primeMeridian, IndentedTextWriter writer) { writer.WriteLine("PRIMEM["); writer.Indent = writer.Indent + 1; writer.WriteLine(String.Format(System.Globalization.CultureInfo.InvariantCulture, "\"{0}\",{1},", primeMeridian.Name, primeMeridian.Longitude)); writer.WriteLine(String.Format(System.Globalization.CultureInfo.InvariantCulture, "AUTHORITY[\"{0}\",\"{1}\"]", primeMeridian.Authority, primeMeridian.AuthorityCode)); writer.Indent = writer.Indent - 1; writer.WriteLine("]"); }
internal GeographicCoordinateSystem(string name, IAngularUnit angularUnit, IHorizontalDatum horizontalDatum, IPrimeMeridian primeMeridian, IAxisInfo axis0, IAxisInfo axis1) : this(angularUnit,horizontalDatum,primeMeridian, axis0, axis1,"","","",name,"","") { }
/// <summary> /// /// </summary> /// <param name="tokenizer"></param> /// <returns></returns> 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(","); tokenizer.ReadToken("PRIMEM"); IPrimeMeridian primeMeridian = ReadPrimeMeridian(tokenizer); tokenizer.ReadToken(","); tokenizer.ReadToken("UNIT"); IAngularUnit angularUnit = ReadAngularUnit(tokenizer); string authority = String.Empty; long authorityCode = -1; tokenizer.NextToken(); List <AxisInfo> info = new List <AxisInfo>(2); if (tokenizer.GetStringValue() == ",") { tokenizer.NextToken(); while (tokenizer.GetStringValue() == "AXIS") { info.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 (info.Count == 0) { info.Add(new AxisInfo("Lon", AxisOrientationEnum.East)); info.Add(new AxisInfo("Lat", AxisOrientationEnum.North)); } IGeographicCoordinateSystem geographicCS = new GeographicCoordinateSystem(angularUnit, horizontalDatum, primeMeridian, info, name, authority, authorityCode, String.Empty, String.Empty, String.Empty); return(geographicCS); }
private static void WritePrimeMeridian(IPrimeMeridian primeMeridian, IndentedTextWriter writer) { writer.WriteLine("PRIMEM["); writer.Indent = writer.Indent + 1; writer.WriteLine(String.Format("\"{0}\",{1},", primeMeridian.Name, primeMeridian.Longitude)); writer.WriteLine(String.Format("AUTHORITY[\"{0}\",\"{1}\"]", primeMeridian.Authority, primeMeridian.AuthorityCode)); writer.Indent = writer.Indent - 1; writer.WriteLine("]"); }
public void TestCreatePrimeMeridian1() { IAngularUnit angularUnit = new AngularUnit(1); IPrimeMeridian primeMeridian = _csFactory.CreatePrimeMeridian("name", angularUnit, 2.0); Assertion.AssertEquals("ctor. 1 ", "name", primeMeridian.Name); Assertion.AssertEquals("ctor. 2", angularUnit, primeMeridian.AngularUnit); Assertion.AssertEquals("ctor. 3 ", 2.0, primeMeridian.Longitude); }
public void TestReadPrimeMeridian2() { string testFile = Global.GetUnitTestRootDirectory() + @"\IO\PrimeMeridian.txt"; string wkt1 = FileToString(testFile); IPrimeMeridian primeMeridian = CoordinateSystemWktReader.Create(wkt1) as IPrimeMeridian; string wkt2 = primeMeridian.WKT; bool same = Compare.CompareAgainstString(testFile, wkt2); Assertion.AssertEquals("Prime Meridian 1", true, same); }
/// <summary> /// Creates instance prime meridian transform /// </summary> /// <param name="source"></param> /// <param name="target"></param> public PrimeMeridianTransform(IPrimeMeridian source, IPrimeMeridian target) : base() { if (!source.AngularUnit.EqualParams(target.AngularUnit)) { throw new NotImplementedException("The method or operation is not implemented."); } _source = source; _target = target; }
/// <summary> /// /// </summary> public void Test_PrimeMeridian2() { try { IPrimeMeridian primeMeridian2 = _factory.CreatePrimeMeridian("1"); Assertion.Fail("Prime Meridian - Exception should be thrown."); } catch (ArgumentOutOfRangeException) { } }
internal GeocentricCoordinateSystem(IHorizontalDatum datum, ILinearUnit linearUnit, IPrimeMeridian primeMeridian, List <AxisInfo> axisinfo, string name, string authority, long code, string alias, string remarks, string abbreviation) : base(name, authority, code, alias, abbreviation, remarks) { this._HorizontalDatum = datum; this._LinearUnit = linearUnit; this._Primemeridan = primeMeridian; if (axisinfo.Count != 3) { throw new ArgumentException("Axis info should contain three axes for geocentric coordinate systems"); } base.AxisInfo = axisinfo; }
public void TestWritePrimeMeridian() { IPrimeMeridian PrimeMeridian = _factory.CreatePrimeMeridian("8901"); TextWriter textwriter = new StringWriter(); IndentedTextWriter indentedTextWriter = new IndentedTextWriter(textwriter); CoordinateSystemWktWriter.Write(PrimeMeridian, indentedTextWriter); bool same = Compare.CompareAgainstString(Global.GetUnitTestRootDirectory() + @"\IO\PrimeMeridian.txt", textwriter.ToString()); Assertion.AssertEquals("test 1", true, same); }
public void TestCreatePrimeMeridian2() { try { IPrimeMeridian primeMeridian = _csFactory.CreatePrimeMeridian("name", null, 2.0); Assertion.Fail("ArgumentNullException should have been thrown."); } catch (ArgumentNullException) { } }
internal GeocentricCoordinateSystem(IHorizontalDatum datum, ILinearUnit linearUnit, IPrimeMeridian primeMeridian, List<AxisInfo> axisinfo, string name, string authority, long code, string alias, string remarks, string abbreviation) : base(name, authority, code, alias, abbreviation, remarks) { _HorizontalDatum = datum; _LinearUnit = linearUnit; _Primemeridan = primeMeridian; if (axisinfo.Count != 3) throw new ArgumentException("Axis info should contain three axes for geocentric coordinate systems"); base.AxisInfo = axisinfo; }
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); }
public void Test_Constructor() { ICoordinateSystemFactory csFactory = new CoordinateSystemFactory(); IAngularUnit angularUnit = new AngularUnit(1); ILinearUnit linearUnit = new LinearUnit(1); IEllipsoid ellipsoid = csFactory.CreateFlattenedSphere("test", 1, 2, linearUnit); IAxisInfo axis0 = new AxisInfo("axis0name", AxisOrientation.Up); IAxisInfo axis1 = new AxisInfo("axis1name", AxisOrientation.Up); WGS84ConversionInfo wgs = new WGS84ConversionInfo(); IPrimeMeridian primeMeridian = csFactory.CreatePrimeMeridian("name", angularUnit, 2.0); IHorizontalDatum horizontalDatum = csFactory.CreateHorizontalDatum("datum", DatumType.IHD_Geocentric, ellipsoid, wgs); IGeographicCoordinateSystem gcs = csFactory.CreateGeographicCoordinateSystem("name", angularUnit, horizontalDatum, primeMeridian, axis0, axis1); //PrimeMeridian primeMeridian = new PrimeMeridian("name", angularUnit, 0.5); IAxisInfo[] axisArray = new IAxisInfo[2]; axisArray[0] = axis0; axisArray[1] = axis1; ProjectionParameter[] paramList = new ProjectionParameter[1]; paramList[0].Name = "test"; paramList[0].Value = 2.2; Projection projection = new Projection("mercator", paramList, "class", "remarks", "authority", "authoritycode"); ProjectedCoordinateSystem pjc = new ProjectedCoordinateSystem(horizontalDatum, axisArray, gcs, linearUnit, projection, "remarks", "authority", "authorityCode", "name", "alias", "abbreviation"); Assertion.AssertEquals("Test 1", linearUnit, pjc.LinearUnit); Assertion.AssertEquals("Test 2", horizontalDatum, pjc.HorizontalDatum); Assertion.AssertEquals("Test 3", axis0, pjc.GetAxis(0)); Assertion.AssertEquals("Test 4", axis1, pjc.GetAxis(1)); Assertion.AssertEquals("Test 5", gcs, pjc.GeographicCoordinateSystem); Assertion.AssertEquals("Test 6", "abbreviation", pjc.Abbreviation); Assertion.AssertEquals("Test 7", "alias", pjc.Alias); Assertion.AssertEquals("Test 8", "authority", pjc.Authority); Assertion.AssertEquals("Test 9", "authorityCode", pjc.AuthorityCode); Assertion.AssertEquals("Test 10", "name", pjc.Name); Assertion.AssertEquals("Test 11", "remarks", pjc.Remarks); }
public void Test_Constructor() { ICoordinateSystemFactory csFactory = new CoordinateSystemFactory(); IAngularUnit angularUnit = new AngularUnit(1); ILinearUnit linearUnit = new LinearUnit(1); IEllipsoid ellipsoid = csFactory.CreateFlattenedSphere("test", 1, 2, linearUnit); IAxisInfo axis0 = new AxisInfo("axis0name", AxisOrientation.Up); IAxisInfo axis1 = new AxisInfo("axis1name", AxisOrientation.Up); WGS84ConversionInfo wgs = new WGS84ConversionInfo(); IPrimeMeridian primeMeridian = csFactory.CreatePrimeMeridian("name", angularUnit, 2.0); IHorizontalDatum horizontalDatum = csFactory.CreateHorizontalDatum("datum", DatumType.IHD_Geocentric, ellipsoid, wgs); IGeographicCoordinateSystem gcs = csFactory.CreateGeographicCoordinateSystem("name", angularUnit, horizontalDatum, primeMeridian, axis0, axis1); Assertion.AssertEquals("ctor 1", "name", gcs.Name); Assertion.AssertEquals("ctor 2", angularUnit, gcs.AngularUnit); Assertion.AssertEquals("ctor 3", horizontalDatum, gcs.HorizontalDatum); Assertion.AssertEquals("ctor 4", primeMeridian, gcs.PrimeMeridian); Assertion.AssertEquals("ctor 5", axis0, gcs.GetAxis(0)); Assertion.AssertEquals("ctor 5", axis1, gcs.GetAxis(1)); }
private IProjectedCoordinateSystem createExpectedCoordinateSystem() { ICoordinateSystemFactory factory = new CoordinateSystemFactory <BufferedCoordinate2D>( _geoFactory.CoordinateFactory, _geoFactory); IEllipsoid grs80 = Ellipsoid.Grs80; IHorizontalDatum harn = factory.CreateHorizontalDatum( DatumType.HorizontalGeocentric, grs80, null, "D_North_American_1983_HARN"); IPrimeMeridian greenwich = PrimeMeridian.Greenwich; IAxisInfo axis0 = new AxisInfo(AxisOrientation.East, "Lon"); IAxisInfo axis1 = new AxisInfo(AxisOrientation.North, "Lat"); // Made the first parameter - the IExtents - null, which should be improved IGeographicCoordinateSystem gcs = factory.CreateGeographicCoordinateSystem(null, AngularUnit.Degrees, harn, greenwich, axis0, axis1, "GCS_North_American_1983_HARN"); IProjection prj = factory.CreateProjection( "Lambert_Conformal_Conic", new ProjectionParameter[] { new ProjectionParameter("False_Easting", 8202099.737532808), new ProjectionParameter("False_Northing", 0), new ProjectionParameter("Central_Meridian", -120.5), new ProjectionParameter("Standard_Parallel_1", 44.33333333333334), new ProjectionParameter("Standard_Parallel_2", 46.0), new ProjectionParameter("Latitude_Of_Origin", 43.66666666666666) }, "Lambert_Conformal_Conic"); IProjectedCoordinateSystem expected = factory.CreateProjectedCoordinateSystem( gcs, prj, LinearUnit.Foot, axis0, axis1, "NAD_1983_HARN_StatePlane_Oregon_North_FIPS_3601"); // TODO: Check if this is correct, since on line 184 of CoorindateSystemFactory.cs, // HorizontalDatum is passed in as null return(expected); }
private void CreateGeographicCoordinateSystem() { ISpatialReferenceFactory3 spatialReferenceFactory = new SpatialReferenceEnvironmentClass(); IDatum datum = spatialReferenceFactory.CreateDatum((int)esriSRDatumType.esriSRDatum_OSGB1936); IPrimeMeridian primeMeridian = spatialReferenceFactory.CreatePrimeMeridian((int)esriSRPrimeMType.esriSRPrimeM_Greenwich); IUnit unit = spatialReferenceFactory.CreateUnit((int)esriSRUnitType.esriSRUnit_Degree); IGeographicCoordinateSystemEdit geographicCoordinateSystemEdit = new GeographicCoordinateSystemClass(); object name = "UserDefined Geographic Coordinate System"; object alias = "UserDefined GCS"; object abbreviation = "UserDefined"; object remarks = "User Defined Geographic Coordinate System based on OSGB1936"; object usage = "Suitable for the UK"; object datumObject = datum as object; object primeMeridianObject = primeMeridian as object; object unitObject = unit as object; geographicCoordinateSystemEdit.Define(ref name, ref alias, ref abbreviation, ref remarks, ref usage, ref datumObject, ref primeMeridianObject, ref unitObject); IGeographicCoordinateSystem userDefinedGeographicCoordinateSystem = geographicCoordinateSystemEdit as IGeographicCoordinateSystem; m_map.SpatialReference = userDefinedGeographicCoordinateSystem; m_activeView.Refresh(); MessageBox.Show("已将当前坐标系统转换为自定义GeographicCoordinateSystem!"); }
/// <summary> /// Creates a <see cref="GeographicCoordinateSystem"/>, which could be Lat/Lon or Lon/Lat. /// </summary> /// <param name="name">Name of geographical coordinate system</param> /// <param name="angularUnit">Angular units</param> /// <param name="datum">Horizontal datum</param> /// <param name="primeMeridian">Prime meridian</param> /// <param name="axis0">First axis</param> /// <param name="axis1">Second axis</param> /// <returns>Geographic coordinate system</returns> public IGeographicCoordinateSystem CreateGeographicCoordinateSystem(string name, IAngularUnit angularUnit, IHorizontalDatum datum, IPrimeMeridian primeMeridian, AxisInfo axis0, AxisInfo axis1) { if (String.IsNullOrEmpty(name)) { throw new ArgumentException("Invalid name"); } List <AxisInfo> info = new List <AxisInfo>(2); info.Add(axis0); info.Add(axis1); return(new GeographicCoordinateSystem(angularUnit, datum, primeMeridian, info, name, String.Empty, -1, String.Empty, String.Empty, String.Empty)); }
/// <summary> /// Creates a <see cref="GeographicCoordinateSystem"/>, which could be Lat/Lon or Lon/Lat. /// </summary> /// <param name="name">Name of geographical coordinate system</param> /// <param name="angularUnit">Angular units</param> /// <param name="datum">Horizontal datum</param> /// <param name="primeMeridian">Prime meridian</param> /// <param name="axis0">First axis</param> /// <param name="axis1">Second axis</param> /// <returns>Geographic coordinate system</returns> public IGeographicCoordinateSystem CreateGeographicCoordinateSystem(string name, IAngularUnit angularUnit, IHorizontalDatum datum, IPrimeMeridian primeMeridian, AxisInfo axis0, AxisInfo axis1) { if (string.IsNullOrEmpty(name)) throw new ArgumentException("Invalid name"); List<AxisInfo> info = new List<AxisInfo>(2); info.Add(axis0); info.Add(axis1); return new GeographicCoordinateSystem(angularUnit, datum, primeMeridian,info, name, String.Empty, -1, String.Empty, String.Empty, String.Empty); }
private static void WritePrimeMeridian(IPrimeMeridian primeMeridian, IndentedTextWriter writer) { writer.WriteLine("PRIMEM["); writer.Indent=writer.Indent+1; writer.WriteLine(String.Format("\"{0}\",{1},", primeMeridian.Name, primeMeridian.Longitude)); writer.WriteLine(String.Format("AUTHORITY[\"{0}\",\"{1}\"]", primeMeridian.Authority, primeMeridian.AuthorityCode)); writer.Indent=writer.Indent-1; writer.WriteLine("]"); }
public IGeographicCoordinateSystem CreateGeographicCoordinateSystem(string name, IAngularUnit angularUnit, IHorizontalDatum datum, IPrimeMeridian primeMeridian, AxisInfo axis0, AxisInfo axis1) { throw new NotImplementedException(); }
/// <summary> /// Creates a <see cref="CreateGeocentricCoordinateSystem"/> from a <see cref="IHorizontalDatum">datum</see>, /// <see cref="ILinearUnit">linear unit</see> and <see cref="IPrimeMeridian"/>. /// </summary> /// <param name="name">Name of geocentric coordinate system</param> /// <param name="datum">Horizontal datum</param> /// <param name="linearUnit">Linear unit</param> /// <param name="primeMeridian">Prime meridian</param> /// <returns>Geocentric Coordinate System</returns> public IGeocentricCoordinateSystem CreateGeocentricCoordinateSystem(string name, IHorizontalDatum datum, ILinearUnit linearUnit, IPrimeMeridian primeMeridian) { if (string.IsNullOrEmpty(name)) throw new ArgumentException("Invalid name"); List<AxisInfo> info = new List<AxisInfo>(3); info.Add(new AxisInfo("X", AxisOrientationEnum.Other)); info.Add(new AxisInfo("Y", AxisOrientationEnum.Other)); info.Add(new AxisInfo("Z", AxisOrientationEnum.Other)); return new GeocentricCoordinateSystem(datum, linearUnit, primeMeridian, info, name,String.Empty,-1,String.Empty,String.Empty,String.Empty); }
private static void WritePrimeMeridian(IPrimeMeridian primeMeridian, IndentedTextWriter writer) { writer.WriteLine("PRIMEM["); writer.Indent=writer.Indent+1; writer.WriteLine(String.Format(System.Globalization.CultureInfo.InvariantCulture, "\"{0}\",{1},", primeMeridian.Name, primeMeridian.Longitude)); writer.WriteLine(String.Format(System.Globalization.CultureInfo.InvariantCulture, "AUTHORITY[\"{0}\",\"{1}\"]", primeMeridian.Authority, primeMeridian.AuthorityCode)); writer.Indent=writer.Indent-1; writer.WriteLine("]"); }
/// <summary> /// Creates a GCS, which could be Lat/Lon or Lon/Lat. /// </summary> /// <param name="name">The name of the coordinae system.</param> /// <param name="angularUnit">The angular units to use.</param> /// <param name="horizontalDatum">Ghe horizontal datum to use.</param> /// <param name="primeMeridian">The prime meridian to use.</param> /// <param name="axis0">Information about the x axis.</param> /// <param name="axis1">Information about the y axis.</param> /// <returns>an object that implements the IGeographicCoordinateSystem interface.</returns> public IGeographicCoordinateSystem CreateGeographicCoordinateSystem(string name, IAngularUnit angularUnit, IHorizontalDatum horizontalDatum, IPrimeMeridian primeMeridian, IAxisInfo axis0, IAxisInfo axis1) { return new GeographicCoordinateSystem(name, angularUnit, horizontalDatum, primeMeridian, axis0, axis1); }
/// <summary> /// Creates a <see cref="CreateGeocentricCoordinateSystem"/> from a <see cref="IHorizontalDatum">datum</see>, /// <see cref="ILinearUnit">linear unit</see> and <see cref="IPrimeMeridian"/>. /// </summary> /// <param name="name">Name of geocentric coordinate system</param> /// <param name="datum">Horizontal datum</param> /// <param name="linearUnit">Linear unit</param> /// <param name="primeMeridian">Prime meridian</param> /// <returns>Geocentric Coordinate System</returns> public IGeocentricCoordinateSystem CreateGeocentricCoordinateSystem(string name, IHorizontalDatum datum, ILinearUnit linearUnit, IPrimeMeridian primeMeridian) { if (String.IsNullOrEmpty(name)) { throw new ArgumentException("Invalid name"); } List <AxisInfo> info = new List <AxisInfo>(3); info.Add(new AxisInfo("X", AxisOrientationEnum.Other)); info.Add(new AxisInfo("Y", AxisOrientationEnum.Other)); info.Add(new AxisInfo("Z", AxisOrientationEnum.Other)); return(new GeocentricCoordinateSystem(datum, linearUnit, primeMeridian, info, name, String.Empty, -1, String.Empty, String.Empty, String.Empty)); }
/// <summary> /// Returns a GeographicCoordinateSystem object from a code. /// </summary> /// <param name="code">The EPSG code.</param> /// <returns>An object that implements the IGeographicCoordinateSystem interface.</returns> public IGeographicCoordinateSystem CreateGeographicCoordinateSystem(string code) { if (code == null) { throw new ArgumentNullException("code"); } string sqlQuery = "SELECT COORD_REF_SYS_NAME, COORD_REF_SYS_CODE, AREA_OF_USE_CODE, " + " COORD_REF_SYS_KIND, DATUM_CODE, COORD_SYS_CODE, " + " SOURCE_GEOGCRS_CODE, PROJECTION_CONV_CODE, CMPD_VERTCRS_CODE, CRS_SCOPE, CMPD_HORIZCRS_CODE, REMARKS, DATA_SOURCE " + "FROM [Coordinate Reference System] " + "WHERE COORD_REF_SYS_CODE = {0}"; sqlQuery = String.Format(System.Globalization.CultureInfo.InvariantCulture, sqlQuery, code); IDataReader reader = Database.ExecuteQuery(_databaseConnection, sqlQuery); if (!reader.Read()) { throw new ArgumentException(String.Format(System.Globalization.CultureInfo.InvariantCulture, "Geographic Coordinate System with a code {0} not found in the CRS table in the EPSG database.", code)); } ; string coordSysCode = reader["COORD_SYS_CODE"].ToString().ToLower(); string coordSysName = reader["COORD_REF_SYS_NAME"].ToString(); string name = reader["COORD_REF_SYS_NAME"].ToString(); string horizontalDatumCode = reader["DATUM_CODE"].ToString(); string coordRefKind = reader["COORD_REF_SYS_KIND"].ToString(); string datasource = reader["DATA_SOURCE"].ToString(); // should always be EPSG?? string remarks = reader["REMARKS"].ToString(); if (coordRefKind.ToLower() != "geographic 2d") { throw new ArgumentException(String.Format("CRS code {0} is not a geographic coordinate system but a {1}.", code, coordRefKind)); } Database.CheckOneRow(reader, code, "Geographic CRC code"); string primeMeridianCode = ""; IPrimeMeridian primeMeridian = null; IHorizontalDatum horizontalDatum = null; if (horizontalDatumCode == "") { horizontalDatum = HorizontalDatum.WGS84; //this.CreateHorizontalDatum( horizontalDatumCode ); primeMeridianCode = this.CreatePrimeMeridianCodeFromDatum(horizontalDatumCode); primeMeridian = this.CreatePrimeMeridian(primeMeridianCode); } else { horizontalDatum = this.CreateHorizontalDatum(horizontalDatumCode); primeMeridianCode = this.CreatePrimeMeridianCodeFromDatum(horizontalDatumCode); primeMeridian = this.CreatePrimeMeridian(primeMeridianCode); } // we get the information for the axis IAxisInfo[] axisInfos = GetAxisInfo(coordSysCode); IAngularUnit angularUnit = new AngularUnit(1); IAxisInfo axisInfo1 = axisInfos[0]; IAxisInfo axisInfo2 = axisInfos[1]; IGeographicCoordinateSystem geographicCoordSys = new GeographicCoordinateSystem(angularUnit, horizontalDatum, primeMeridian, axisInfo1, axisInfo2, remarks, datasource, code, name, "", ""); return(geographicCoordSys); }
/// <summary> /// Creates the appropriate object given a string containing XML. /// </summary> /// <param name="wkt">String containing XML.</param> /// <returns>Object representation of the XML.</returns> /// <exception cref="ParseException">If a token is not recognised.</exception> public static object Create(string wkt) { object returnObject = null; StringReader reader = new StringReader(wkt); WktStreamTokenizer tokenizer = new WktStreamTokenizer(reader); tokenizer.NextToken(); string objectName = tokenizer.GetStringValue(); switch (objectName) { case "UNIT": IUnit unit = ReadUnit(tokenizer); returnObject = unit; break; case "VERT_DATUM": IVerticalDatum verticalDatum = ReadVerticalDatum(tokenizer); returnObject = verticalDatum; break; case "SPHEROID": IEllipsoid ellipsoid = ReadEllipsoid(tokenizer); returnObject = ellipsoid; break; case "TOWGS84": WGS84ConversionInfo wgsInfo = ReadWGS84ConversionInfo(tokenizer); returnObject = wgsInfo; break; case "DATUM": IHorizontalDatum horizontalDatum = ReadHorizontalDatum(tokenizer); returnObject = horizontalDatum; break; case "PRIMEM": IPrimeMeridian primeMeridian = ReadPrimeMeridian(tokenizer); returnObject = primeMeridian; break; case "VERT_CS": IVerticalCoordinateSystem verticalCS = ReadVerticalCoordinateSystem(tokenizer); returnObject = verticalCS; break; case "GEOGCS": IGeographicCoordinateSystem geographicCS = ReadGeographicCoordinateSystem(tokenizer); returnObject = geographicCS; break; case "PROJCS": IProjectedCoordinateSystem projectedCS = ReadProjectedCoordinateSystem(tokenizer); returnObject = projectedCS; break; case "COMPD_CS": ICompoundCoordinateSystem compoundCS = ReadCompoundCoordinateSystem(tokenizer); returnObject = compoundCS; break; case "GEOCCS": case "FITTED_CS": case "LOCAL_CS": throw new NotSupportedException(String.Format("{0} is not implemented.", objectName)); default: throw new ParseException(String.Format("'{0'} is not recongnized.", objectName)); } reader.Close(); return(returnObject); }
/// <summary> /// Creates a GCS, which could be Lat/Lon or Lon/Lat. /// </summary> /// <param name="name">The name of the coordinae system.</param> /// <param name="angularUnit">The angular units to use.</param> /// <param name="horizontalDatum">Ghe horizontal datum to use.</param> /// <param name="primeMeridian">The prime meridian to use.</param> /// <param name="axis0">Information about the x axis.</param> /// <param name="axis1">Information about the y axis.</param> /// <returns>an object that implements the IGeographicCoordinateSystem interface.</returns> public IGeographicCoordinateSystem CreateGeographicCoordinateSystem(string name, IAngularUnit angularUnit, IHorizontalDatum horizontalDatum, IPrimeMeridian primeMeridian, IAxisInfo axis0, IAxisInfo axis1) { return(new GeographicCoordinateSystem(name, angularUnit, horizontalDatum, primeMeridian, axis0, axis1)); }
/// <summary> /// Creates a projected coordinate system using the given code. /// </summary> /// <param name="code">The EPSG code.</param> /// <returns>A IProjectedCoordinateSystem object.</returns> public IProjectedCoordinateSystem CreateProjectedCoordinateSystem(string code) { if (code == null) { throw new ArgumentNullException("code"); } string sqlQuery = "SELECT COORD_REF_SYS_NAME, COORD_REF_SYS_CODE, AREA_OF_USE_CODE, " + " COORD_REF_SYS_KIND, DATUM_CODE, COORD_SYS_CODE, " + " SOURCE_GEOGCRS_CODE, PROJECTION_CONV_CODE, CMPD_VERTCRS_CODE, CRS_SCOPE, CMPD_HORIZCRS_CODE, DATA_SOURCE, REMARKS " + "FROM [Coordinate Reference System] " + "WHERE COORD_REF_SYS_CODE = {0}"; sqlQuery = String.Format(System.Globalization.CultureInfo.InvariantCulture, sqlQuery, code); IDataReader reader = Database.ExecuteQuery(_databaseConnection, sqlQuery); if (!reader.Read()) { throw new ArgumentException(String.Format(System.Globalization.CultureInfo.InvariantCulture, "Geographic Coordinate System with a code {0} not found in the CRS table in the EPSG database.", code)); } string coordSysCode = reader["COORD_SYS_CODE"].ToString().ToLower(); string coordSysName = reader["COORD_REF_SYS_NAME"].ToString(); string name = reader["COORD_REF_SYS_NAME"].ToString(); string horizontalDatumCode = reader["DATUM_CODE"].ToString(); string geographicCRSCode = reader["SOURCE_GEOGCRS_CODE"].ToString(); string projectionCode = reader["PROJECTION_CONV_CODE"].ToString(); string coordRefKind = reader["COORD_REF_SYS_KIND"].ToString(); string remarks = reader["REMARKS"].ToString(); string datasource = reader["DATA_SOURCE"].ToString(); // should always be EPSG?? Database.CheckOneRow(reader, code, "Geographic CRC code"); if (coordRefKind.ToLower() != "projected") { throw new ArgumentException(String.Format(System.Globalization.CultureInfo.InvariantCulture, "CRS code {0} is not a projected coordinate system but a {1}.", code, coordRefKind)); } string primeMeridianCode = ""; IPrimeMeridian primeMeridian = null; IHorizontalDatum horizontalDatum = null; if (horizontalDatumCode != "") { horizontalDatum = HorizontalDatum.WGS84; //this.CreateHorizontalDatum( horizontalDatumCode ); primeMeridianCode = this.CreatePrimeMeridianCodeFromDatum(horizontalDatumCode); primeMeridian = this.CreatePrimeMeridian(primeMeridianCode); } // we get the information for the axis IAxisInfo[] axisInfos = GetAxisInfo(coordSysCode); ICoordinateTransformationAuthorityFactory factory = new CoordinateTransformationEPSGFactory(_databaseConnection); ICoordinateTransformation mathtransform = factory.CreateFromCoordinateSystemCodes(geographicCRSCode, ""); string methodOperation = this.GetMethodOperationCodeFromProjectionCode(projectionCode); IProjection projection = this.CreateProjection(methodOperation, projectionCode); IGeographicCoordinateSystem geographicCoordSystem = this.CreateGeographicCoordinateSystem(geographicCRSCode); ILinearUnit linearUnit = LinearUnit.Meters; IProjectedCoordinateSystem projectedCoordSys = new ProjectedCoordinateSystem(horizontalDatum, axisInfos, geographicCoordSystem, linearUnit, projection, remarks, datasource, code, coordSysName, "", ""); return(projectedCoordSys); }