private void TestMercator_1SP() { CoordinateSystemFactory cFac = new SharpMap.CoordinateSystems.CoordinateSystemFactory(); IEllipsoid ellipsoid = cFac.CreateFlattenedSphere("Bessel 1840", 6377397.155, 299.15281, LinearUnit.Metre); IHorizontalDatum datum = cFac.CreateHorizontalDatum("Bessel 1840", DatumType.HD_Geocentric, ellipsoid, null); IGeographicCoordinateSystem gcs = cFac.CreateGeographicCoordinateSystem("Bessel 1840", AngularUnit.Degrees, datum, PrimeMeridian.Greenwich, new AxisInfo("Lon", AxisOrientationEnum.East), new AxisInfo("Lat", AxisOrientationEnum.North)); List <ProjectionParameter> parameters = new List <ProjectionParameter>(); parameters.Add(new ProjectionParameter("latitude_of_origin", 0)); parameters.Add(new ProjectionParameter("central_meridian", 110)); parameters.Add(new ProjectionParameter("scale_factor", 0.997)); parameters.Add(new ProjectionParameter("false_easting", 3900000)); parameters.Add(new ProjectionParameter("false_northing", 900000)); IProjection projection = cFac.CreateProjection("Mercator_1SP", "Mercator_1SP", parameters); IProjectedCoordinateSystem coordsys = cFac.CreateProjectedCoordinateSystem("Makassar / NEIEZ", gcs, projection, LinearUnit.Metre, new AxisInfo("East", AxisOrientationEnum.East), new AxisInfo("North", AxisOrientationEnum.North)); ICoordinateTransformation trans = new CoordinateTransformationFactory().CreateFromCoordinateSystems(gcs, coordsys); SharpMap.Geometries.Point pGeo = new SharpMap.Geometries.Point(120, -3); SharpMap.Geometries.Point pUtm = new Point(trans.MathTransform.Transform(pGeo.ToDoubleArray())); SharpMap.Geometries.Point pGeo2 = new Point(trans.MathTransform.Inverse().Transform(pUtm.ToDoubleArray())); result.Text += PrintResultTable(gcs, coordsys, pGeo, pUtm, new Point(5009726.58, 569150.82), pGeo2, "Mercator_1SP test"); }
static public double CalculateDistanceBetween84TwoPoints(IPoint pt1, IPoint pt2) { ESRI.ArcGIS.Geometry.ISpatialReferenceFactory spatialReferenceFactory = new ESRI.ArcGIS.Geometry.SpatialReferenceEnvironmentClass(); //wgs 84 IGeographicCoordinateSystem wgs84 = spatialReferenceFactory.CreateGeographicCoordinateSystem(4326) as IGeographicCoordinateSystem; IUnit meterUnit = spatialReferenceFactory.CreateUnit((int)ESRI.ArcGIS.Geometry.esriSRUnitType.esriSRUnit_Meter); ISpatialReference pSR = wgs84 as ISpatialReference; IGeometryServer2 pGS = new GeometryServerClass(); double dis = pGS.GetDistanceGeodesic(wgs84, pt1, pt2, (ILinearUnit)meterUnit); IZAware z1 = pt1 as IZAware; IZAware z2 = pt2 as IZAware; if (double.IsNaN(pt1.Z) == false && double.IsNaN(pt2.Z) == false) { double deltaZ = Math.Abs(pt1.Z - pt2.Z); System.Runtime.InteropServices.Marshal.ReleaseComObject(pGS); System.Runtime.InteropServices.Marshal.ReleaseComObject(spatialReferenceFactory); return(Math.Sqrt(dis * dis + deltaZ * deltaZ)); } else { System.Runtime.InteropServices.Marshal.ReleaseComObject(pGS); System.Runtime.InteropServices.Marshal.ReleaseComObject(spatialReferenceFactory); return(dis); } }
/// <summary> /// Gets the geographic spatial reference. /// </summary> /// <param name="projection">The spatial reference geographic coordinate system type; i.e. factory code. Use an element <b>value</b> from the /// <see cref="ESRI.ArcGIS.Geometry.esriSRGeoCSType "/>, <see cref="ESRI.ArcGIS.Geometry.esriSRGeoCS2Type "/>, /// or <see cref="ESRI.ArcGIS.Geometry.esriSRGeoCS3Type "/> enumerations as the geographicCoordinateSystemType to create a particular /// predefined geographic coordinate system. /// <para>This is the <b>value</b> for a given geographic coordinate system constant.</para> /// </param> /// <returns></returns> public static ISpatialReference GetGeographicSpatialReference(int geographicCoordinateSystemType) { ISpatialReferenceFactory spatialReferenceFactory = new SpatialReferenceEnvironmentClass(); IGeographicCoordinateSystem geographicCoordinateSystem = spatialReferenceFactory.CreateGeographicCoordinateSystem(geographicCoordinateSystemType); return(geographicCoordinateSystem); }
private static ICoordinateSystem ReadCoordinateSystem(string coordinateSystem, WktStreamTokenizer tokenizer) { ICoordinateSystem returnCS = null; switch (coordinateSystem) { case "VERT_CS": IVerticalCoordinateSystem verticalCS = ReadVerticalCoordinateSystem(tokenizer); returnCS = verticalCS; break; case "GEOGCS": IGeographicCoordinateSystem geographicCS = ReadGeographicCoordinateSystem(tokenizer); returnCS = geographicCS; break; case "PROJCS": IProjectedCoordinateSystem projectedCS = ReadProjectedCoordinateSystem(tokenizer); returnCS = projectedCS; break; case "COMPD_CS": ICompoundCoordinateSystem compoundCS = ReadCompoundCoordinateSystem(tokenizer); returnCS = compoundCS; break; case "GEOCCS": case "FITTED_CS": case "LOCAL_CS": throw new InvalidOperationException(String.Format("{0} coordinate system is not recongized.", coordinateSystem)); } return(returnCS); }
/// <summary> /// Geographic to geographic transformation /// </summary> /// <remarks>Adds a datum shift if nessesary</remarks> /// <param name="source"></param> /// <param name="target"></param> /// <returns></returns> private ICoordinateTransformation CreateGeog2Geog(IGeographicCoordinateSystem source, IGeographicCoordinateSystem target) { if (source.HorizontalDatum.EqualParams(target.HorizontalDatum)) { //No datum shift needed return(new CoordinateTransformation(source, target, TransformType.Conversion, new GeographicTransform(source, target), String.Empty, String.Empty, -1, String.Empty, String.Empty)); } else { //Create datum shift //Convert to geocentric, perform shift and return to geographic CoordinateTransformationFactory ctFac = new CoordinateTransformationFactory(); CoordinateSystemFactory cFac = new CoordinateSystemFactory(); IGeocentricCoordinateSystem sourceCentric = cFac.CreateGeocentricCoordinateSystem(source.HorizontalDatum.Name + " Geocentric", source.HorizontalDatum, LinearUnit.Metre, source.PrimeMeridian); IGeocentricCoordinateSystem targetCentric = cFac.CreateGeocentricCoordinateSystem(target.HorizontalDatum.Name + " Geocentric", target.HorizontalDatum, LinearUnit.Metre, source.PrimeMeridian); ConcatenatedTransform ct = new ConcatenatedTransform(); ct.CoordinateTransformationList.Add(ctFac.CreateFromCoordinateSystems(source, sourceCentric)); ct.CoordinateTransformationList.Add(ctFac.CreateFromCoordinateSystems(sourceCentric, targetCentric)); ct.CoordinateTransformationList.Add(ctFac.CreateFromCoordinateSystems(targetCentric, target)); return(new CoordinateTransformation(source, target, TransformType.Transformation, ct, String.Empty, String.Empty, -1, String.Empty, String.Empty)); } }
private void TestAlbers() { CoordinateSystemFactory cFac = new SharpMap.CoordinateSystems.CoordinateSystemFactory(); IEllipsoid ellipsoid = cFac.CreateFlattenedSphere("Clarke 1866", 6378206.4, 294.9786982138982, LinearUnit.USSurveyFoot); IHorizontalDatum datum = cFac.CreateHorizontalDatum("Clarke 1866", DatumType.HD_Geocentric, ellipsoid, null); IGeographicCoordinateSystem gcs = cFac.CreateGeographicCoordinateSystem("Clarke 1866", AngularUnit.Degrees, datum, PrimeMeridian.Greenwich, new AxisInfo("Lon", AxisOrientationEnum.East), new AxisInfo("Lat", AxisOrientationEnum.North)); List <ProjectionParameter> parameters = new List <ProjectionParameter>(); parameters.Add(new ProjectionParameter("central_meridian", -96)); parameters.Add(new ProjectionParameter("latitude_of_origin", 23)); parameters.Add(new ProjectionParameter("standard_parallel_1", 29.5)); parameters.Add(new ProjectionParameter("standard_parallel_2", 45.5)); parameters.Add(new ProjectionParameter("false_easting", 0)); parameters.Add(new ProjectionParameter("false_northing", 0)); IProjection projection = cFac.CreateProjection("Albers Conical Equal Area", "albers", parameters); IProjectedCoordinateSystem coordsys = cFac.CreateProjectedCoordinateSystem("Albers Conical Equal Area", gcs, projection, LinearUnit.Metre, new AxisInfo("East", AxisOrientationEnum.East), new AxisInfo("North", AxisOrientationEnum.North)); ICoordinateTransformation trans = new CoordinateTransformationFactory().CreateFromCoordinateSystems(gcs, coordsys); SharpMap.Geometries.Point pGeo = new SharpMap.Geometries.Point(-75, 35); SharpMap.Geometries.Point pUtm = new Point(trans.MathTransform.Transform(pGeo.ToDoubleArray())); SharpMap.Geometries.Point pGeo2 = new Point(trans.MathTransform.Inverse().Transform(pUtm.ToDoubleArray())); result.Text += PrintResultTable(gcs, coordsys, pGeo, pUtm, new Point(1885472.7, 1535925), pGeo2, "Albers Conical Equal Area test"); }
/// <summary> /// Initializes a new instance of the ProjectedCoordinateSystem class. /// </summary> /// <param name="horizontalDatum">The horizontal datum to use.</param> /// <param name="axisInfoArray">An array of IAxisInfo representing the axis information.</param> /// <param name="geographicCoordSystem">The geographic coordinate system.</param> /// <param name="linearUnit">The linear units to use.</param> /// <param name="projection">The projection to use.</param> /// <param name="remarks">Remarks about this object.</param> /// <param name="authority">The name of the authority.</param> /// <param name="authorityCode">The code the authority uses to identidy this object.</param> /// <param name="name">The name of the object.</param> /// <param name="alias">The alias of the object.</param> /// <param name="abbreviation">The abbreviated name of this object.</param> internal ProjectedCoordinateSystem( IHorizontalDatum horizontalDatum, IAxisInfo[] axisInfoArray, IGeographicCoordinateSystem geographicCoordSystem, ILinearUnit linearUnit, IProjection projection, string remarks, string authority, string authorityCode, string name, string alias, string abbreviation) : base(remarks, authority, authorityCode, name, alias, abbreviation) { if (axisInfoArray==null) { throw new ArgumentNullException("axisInfoArray"); } if (geographicCoordSystem==null) { throw new ArgumentNullException("geographicCoordSystem"); } if (projection==null) { throw new ArgumentNullException("projection"); } if (linearUnit==null) { throw new ArgumentNullException("linearUnit"); } _horizontalDatum=horizontalDatum; _axisInfoArray= axisInfoArray; _geographicCoordSystem = geographicCoordSystem; _projection= projection; _linearUnit = linearUnit; }
private static IProjectedCoordinateSystem ReadProjectedCoordinateSystem(XmlTextReader reader) { if (!(reader.NodeType == XmlNodeType.Element && reader.Name == "CS_ProjectedCoordinateSystem")) { throw new ParseException(String.Format("Expected a IProjectedCoordinateSystem 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); 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)); IGeographicCoordinateSystem geographicCoordinateSystem = ReadGeographicCoordinateSystem(reader); ILinearUnit linearUnit = ReadLinearUnit(reader); IProjection projection = ReadProjection(reader); reader.Read(); //IPrimeMeridian primeMeridian = null; IHorizontalDatum horizontalDatum = null; ProjectedCoordinateSystem projectedCS = new ProjectedCoordinateSystem(horizontalDatum, axisInfos, geographicCoordinateSystem, linearUnit, projection, "", authority, authorityCode, name, "", abbreviation); return(projectedCS); }
/// <summary> /// 创建地理坐标系 /// </summary> /// <param name="gcsType"></param> /// <returns></returns> static public ISpatialReference CreateGeographicCoordinateSystem(int gcsType) { SpatialReferenceEnvironmentClass sfe = new SpatialReferenceEnvironmentClass(); IGeographicCoordinateSystem gcs = sfe.CreateGeographicCoordinateSystem(gcsType); return(gcs); }
public void TestLambertConicConformal2SP_Projection() { CoordinateSystemFactory cFac = new CoordinateSystemFactory(); IEllipsoid ellipsoid = cFac.CreateFlattenedSphere("Clarke 1866", 20925832.16, 294.97470, LinearUnit.USSurveyFoot); IHorizontalDatum datum = cFac.CreateHorizontalDatum("Clarke 1866", DatumType.HD_Geocentric, ellipsoid, null); IGeographicCoordinateSystem gcs = cFac.CreateGeographicCoordinateSystem("Clarke 1866", AngularUnit.Degrees, datum, PrimeMeridian.Greenwich, new AxisInfo("Lon", AxisOrientationEnum.East), new AxisInfo("Lat", AxisOrientationEnum.North)); List <ProjectionParameter> parameters = new List <ProjectionParameter>(5); parameters.Add(new ProjectionParameter("latitude_of_origin", 27.833333333)); parameters.Add(new ProjectionParameter("central_meridian", -99)); parameters.Add(new ProjectionParameter("standard_parallel_1", 28.3833333333)); parameters.Add(new ProjectionParameter("standard_parallel_2", 30.2833333333)); parameters.Add(new ProjectionParameter("false_easting", 2000000 / LinearUnit.USSurveyFoot.MetersPerUnit)); parameters.Add(new ProjectionParameter("false_northing", 0)); IProjection projection = cFac.CreateProjection("Lambert Conic Conformal (2SP)", "lambert_conformal_conic_2sp", parameters); IProjectedCoordinateSystem coordsys = cFac.CreateProjectedCoordinateSystem("NAD27 / Texas South Central", gcs, projection, LinearUnit.USSurveyFoot, new AxisInfo("East", AxisOrientationEnum.East), new AxisInfo("North", AxisOrientationEnum.North)); ICoordinateTransformation trans = new CoordinateTransformationFactory().CreateFromCoordinateSystems(gcs, coordsys); double[] pGeo = new double[] { -96, 28.5 }; double[] pUtm = trans.MathTransform.Transform(pGeo); double[] pGeo2 = trans.MathTransform.Inverse().Transform(pUtm); double[] expected = new double[] { 2963503.91 / LinearUnit.USSurveyFoot.MetersPerUnit, 254759.80 / LinearUnit.USSurveyFoot.MetersPerUnit }; Assert.IsTrue(ToleranceLessThan(pUtm, expected, 0.05), String.Format("LambertConicConformal2SP forward transformation outside tolerance, Expected [{0},{1}], got [{2},{3}]", expected[0], expected[1], pUtm[0], pUtm[1])); Assert.IsTrue(ToleranceLessThan(pGeo, pGeo2, 0.0000001), String.Format("LambertConicConformal2SP reverse transformation outside tolerance, Expected [{0},{1}], got [{2},{3}]", pGeo[0], pGeo[1], pGeo2[0], pGeo2[1])); }
public void TestTransverseMercator_Projection() { CoordinateSystemFactory cFac = new CoordinateSystemFactory(); IEllipsoid ellipsoid = cFac.CreateFlattenedSphere("Airy 1830", 6377563.396, 299.32496, LinearUnit.Metre); IHorizontalDatum datum = cFac.CreateHorizontalDatum("Airy 1830", DatumType.HD_Geocentric, ellipsoid, null); IGeographicCoordinateSystem gcs = cFac.CreateGeographicCoordinateSystem("Airy 1830", AngularUnit.Degrees, datum, PrimeMeridian.Greenwich, new AxisInfo("Lon", AxisOrientationEnum.East), new AxisInfo("Lat", AxisOrientationEnum.North)); List <ProjectionParameter> parameters = new List <ProjectionParameter>(5); parameters.Add(new ProjectionParameter("latitude_of_origin", 49)); parameters.Add(new ProjectionParameter("central_meridian", -2)); parameters.Add(new ProjectionParameter("scale_factor", 0.9996012717)); parameters.Add(new ProjectionParameter("false_easting", 400000)); parameters.Add(new ProjectionParameter("false_northing", -100000)); IProjection projection = cFac.CreateProjection("Transverse Mercator", "Transverse_Mercator", parameters); IProjectedCoordinateSystem coordsys = cFac.CreateProjectedCoordinateSystem("OSGB 1936 / British National Grid", gcs, projection, LinearUnit.Metre, new AxisInfo("East", AxisOrientationEnum.East), new AxisInfo("North", AxisOrientationEnum.North)); ICoordinateTransformation trans = new CoordinateTransformationFactory().CreateFromCoordinateSystems(gcs, coordsys); double[] pGeo = new double[] { 0.5, 50.5 }; double[] pUtm = trans.MathTransform.Transform(pGeo); double[] pGeo2 = trans.MathTransform.Inverse().Transform(pUtm); double[] expected = new double[] { 577274.99, 69740.50 }; Assert.IsTrue(ToleranceLessThan(pUtm, expected, 0.02), String.Format("TransverseMercator forward transformation outside tolerance, Expected {0}, got {1}", expected.ToString(), pUtm.ToString())); Assert.IsTrue(ToleranceLessThan(pGeo, pGeo2, 0.0000001), String.Format("TransverseMercator reverse transformation outside tolerance, Expected {0}, got {1}", pGeo.ToString(), pGeo2.ToString())); }
public void TestAlbersProjectionFeet() { CoordinateSystemFactory cFac = new CoordinateSystemFactory(); IEllipsoid ellipsoid = cFac.CreateFlattenedSphere("Clarke 1866", 6378206.4, 294.9786982138982, LinearUnit.USSurveyFoot); IHorizontalDatum datum = cFac.CreateHorizontalDatum("Clarke 1866", DatumType.HD_Geocentric, ellipsoid, null); IGeographicCoordinateSystem gcs = cFac.CreateGeographicCoordinateSystem("Clarke 1866", AngularUnit.Degrees, datum, PrimeMeridian.Greenwich, new AxisInfo("Lon", AxisOrientationEnum.East), new AxisInfo("Lat", AxisOrientationEnum.North)); List <ProjectionParameter> parameters = new List <ProjectionParameter>(5); parameters.Add(new ProjectionParameter("central_meridian", -96)); parameters.Add(new ProjectionParameter("latitude_of_center", 23)); parameters.Add(new ProjectionParameter("standard_parallel_1", 29.5)); parameters.Add(new ProjectionParameter("standard_parallel_2", 45.5)); parameters.Add(new ProjectionParameter("false_easting", 0)); parameters.Add(new ProjectionParameter("false_northing", 0)); IProjection projection = cFac.CreateProjection("Albers Conical Equal Area", "albers", parameters); IProjectedCoordinateSystem coordsys = cFac.CreateProjectedCoordinateSystem("Albers Conical Equal Area", gcs, projection, LinearUnit.Foot, new AxisInfo("East", AxisOrientationEnum.East), new AxisInfo("North", AxisOrientationEnum.North)); ICoordinateTransformation trans = new CoordinateTransformationFactory().CreateFromCoordinateSystems(gcs, coordsys); double[] pGeo = new double[] { -75, 35 }; double[] pUtm = trans.MathTransform.Transform(pGeo); double[] pGeo2 = trans.MathTransform.Inverse().Transform(pUtm); double[] expected = new double[] { 1885472.7 / LinearUnit.Foot.MetersPerUnit, 1535925 / LinearUnit.Foot.MetersPerUnit }; Assert.IsTrue(ToleranceLessThan(pUtm, expected, 0.1), String.Format("Albers forward transformation outside tolerance, Expected [{0},{1}], got [{2},{3}]", expected[0], expected[1], pUtm[0], pUtm[1])); Assert.IsTrue(ToleranceLessThan(pGeo, pGeo2, 0.0000001), String.Format("Albers reverse transformation outside tolerance, Expected [{0},{1}], got [{2},{3}]", pGeo[0], pGeo[1], pGeo2[0], pGeo2[1])); }
public static ICoordinateTransformation LatLonToGoogle() { CoordinateSystemFactory csFac = new CoordinateSystemFactory(); CoordinateTransformationFactory ctFac = new CoordinateTransformationFactory(); IGeographicCoordinateSystem sourceCs = csFac.CreateGeographicCoordinateSystem( "WGS 84", AngularUnit.Degrees, HorizontalDatum.WGS84, PrimeMeridian.Greenwich, new AxisInfo("north", AxisOrientationEnum.North), new AxisInfo("east", AxisOrientationEnum.East)); List <ProjectionParameter> parameters = new List <ProjectionParameter>(); parameters.Add(new ProjectionParameter("semi_major", 6378137.0)); parameters.Add(new ProjectionParameter("semi_minor", 6378137.0)); parameters.Add(new ProjectionParameter("latitude_of_origin", 0.0)); parameters.Add(new ProjectionParameter("central_meridian", 0.0)); parameters.Add(new ProjectionParameter("scale_factor", 1.0)); parameters.Add(new ProjectionParameter("false_easting", 0.0)); parameters.Add(new ProjectionParameter("false_northing", 0.0)); IProjection projection = csFac.CreateProjection("Google Mercator", "mercator_1sp", parameters); IProjectedCoordinateSystem targetCs = csFac.CreateProjectedCoordinateSystem( "Google Mercator", sourceCs, projection, LinearUnit.Metre, new AxisInfo("East", AxisOrientationEnum.East), new AxisInfo("North", AxisOrientationEnum.North)); return(ctFac.CreateFromCoordinateSystems(sourceCs, targetCs)); }
private void createProjectedCoordinateSystem() { ISpatialReferenceFactory2 spatialReferenceFactory = new SpatialReferenceEnvironmentClass(); IProjectionGEN projection = spatialReferenceFactory.CreateProjection((int)esriSRProjectionType.esriSRProjection_Sinusoidal) as IProjectionGEN; IGeographicCoordinateSystem geographicCoordinateSystem = spatialReferenceFactory.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_WGS1984); ILinearUnit unit = spatialReferenceFactory.CreateUnit((int)esriSRUnitType.esriSRUnit_Meter) as ILinearUnit; IParameter[] parameters = projection.GetDefaultParameters(); IProjectedCoordinateSystemEdit projectedCoordinateSystemEdit = new ProjectedCoordinateSystemClass(); object name = "Newfoundland"; object alias = "NF_LAB"; object abbreviation = "NF"; object remarks = "Most Eastern Province in Canada"; object usage = "When making maps of Newfoundland"; object geographicCoordinateSystemObject = geographicCoordinateSystem as object; object unitObject = unit as object; object projectionObject = projection as object; object parametersObject = parameters as object; projectedCoordinateSystemEdit.Define(ref name, ref alias, ref abbreviation, ref remarks, ref usage, ref geographicCoordinateSystemObject, ref unitObject, ref projectionObject, ref parametersObject); IProjectedCoordinateSystem userDefinedProjectedCoordinateSystem = projectedCoordinateSystemEdit as IProjectedCoordinateSystem; m_map.SpatialReference = userDefinedProjectedCoordinateSystem; m_activeView.Refresh(); MessageBox.Show("自定义ProjectedCoordinateSystem完成!"); }
public void TestMercator_1SP_Projection() { CoordinateSystemFactory cFac = new CoordinateSystemFactory(); IEllipsoid ellipsoid = cFac.CreateFlattenedSphere("Bessel 1840", 6377397.155, 299.15281, LinearUnit.Metre); IHorizontalDatum datum = cFac.CreateHorizontalDatum("Bessel 1840", DatumType.HD_Geocentric, ellipsoid, null); IGeographicCoordinateSystem gcs = cFac.CreateGeographicCoordinateSystem("Bessel 1840", AngularUnit.Degrees, datum, PrimeMeridian.Greenwich, new AxisInfo("Lon", AxisOrientationEnum.East), new AxisInfo("Lat", AxisOrientationEnum.North)); List <ProjectionParameter> parameters = new List <ProjectionParameter>(5); parameters.Add(new ProjectionParameter("latitude_of_origin", 0)); parameters.Add(new ProjectionParameter("central_meridian", 110)); parameters.Add(new ProjectionParameter("scale_factor", 0.997)); parameters.Add(new ProjectionParameter("false_easting", 3900000)); parameters.Add(new ProjectionParameter("false_northing", 900000)); IProjection projection = cFac.CreateProjection("Mercator_1SP", "Mercator_1SP", parameters); IProjectedCoordinateSystem coordsys = cFac.CreateProjectedCoordinateSystem("Makassar / NEIEZ", gcs, projection, LinearUnit.Metre, new AxisInfo("East", AxisOrientationEnum.East), new AxisInfo("North", AxisOrientationEnum.North)); ICoordinateTransformation trans = new CoordinateTransformationFactory().CreateFromCoordinateSystems(gcs, coordsys); double[] pGeo = new double[] { 120, -3 }; double[] pUtm = trans.MathTransform.Transform(pGeo); double[] pGeo2 = trans.MathTransform.Inverse().Transform(pUtm); double[] expected = new double[] { 5009726.58, 569150.82 }; Assert.IsTrue(ToleranceLessThan(pUtm, expected, 0.02), String.Format("Mercator_1SP forward transformation outside tolerance, Expected [{0},{1}], got [{2},{3}]", expected[0], expected[1], pUtm[0], pUtm[1])); Assert.IsTrue(ToleranceLessThan(pGeo, pGeo2, 0.0000001), String.Format("Mercator_1SP reverse transformation outside tolerance, Expected [{0},{1}], got [{2},{3}]", pGeo[0], pGeo[1], pGeo2[0], pGeo2[1])); }
private void projectCoords(out double lat, out double lon, IPoint pPoint) { ISpatialReference pSR; SpatialReferenceEnvironment pSREnv = new SpatialReferenceEnvironmentClass(); // using the WKID 2270 == Oregon State Plane South // =-====================================================== IProjectedCoordinateSystem pPCS = pSREnv.CreateProjectedCoordinateSystem(2270); pSR = pPCS; IPoint pLocalPoint = new PointClass(); pLocalPoint.SpatialReference = pSR; pLocalPoint.PutCoords(pPoint.X, pPoint.Y); ISpatialReference pWGSSR; SpatialReferenceEnvironment pSREnv2 = new SpatialReferenceEnvironmentClass(); // this uses the esri enum instead of the 4326 wkid // again, either is fine IGeographicCoordinateSystem pGCS = pSREnv2.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_WGS1984); pWGSSR = pGCS; pWGSSR.SetFalseOriginAndUnits(-180, -90, 1000000); pLocalPoint.Project(pWGSSR); lat = pLocalPoint.Y; lon = pLocalPoint.X; }
public static enumSpatialRelType GetSpatialRelType(ISpatialReference spatialReference) { enumSpatialRelType spatialRelType = enumSpatialRelType.Unknown; if (spatialReference == null) { return(spatialRelType); } //地理坐标系统 IGeographicCoordinateSystem geographicCoordinateSystem = spatialReference as IGeographicCoordinateSystem; if (geographicCoordinateSystem != null) { spatialRelType = enumSpatialRelType.GCS; return(spatialRelType); } //投影坐标系统 IProjectedCoordinateSystem projectedCoordinateSystem = spatialReference as IProjectedCoordinateSystem; if (projectedCoordinateSystem != null) { spatialRelType = enumSpatialRelType.PCS; return(spatialRelType); } return(spatialRelType); }
/// <summary> /// Factory's constructor /// </summary> public ItmWgs84MathTransfromFactory() { var coordinateSystemFactory = new CoordinateSystemFactory(); var itmParameters = new List <ProjectionParameter> { new ProjectionParameter("latitude_of_origin", 31.734393611111109123611111111111), new ProjectionParameter("central_meridian", 35.204516944444442572222222222222), new ProjectionParameter("false_northing", 626907.390), new ProjectionParameter("false_easting", 219529.584), new ProjectionParameter("scale_factor", 1.0000067) }; var itmDatum = coordinateSystemFactory.CreateHorizontalDatum("Isreal 1993", DatumType.HD_Geocentric, Ellipsoid.GRS80, new Wgs84ConversionInfo(-24.0024, -17.1032, -17.8444, -0.33077, -1.85269, 1.66969, 5.4248)); var itmGeo = coordinateSystemFactory.CreateGeographicCoordinateSystem("ITM", AngularUnit.Degrees, itmDatum, PrimeMeridian.Greenwich, new AxisInfo("East", AxisOrientationEnum.East), new AxisInfo("North", AxisOrientationEnum.North)); var itmProjection = coordinateSystemFactory.CreateProjection("Transverse_Mercator", "Transverse_Mercator", itmParameters); _itm = coordinateSystemFactory.CreateProjectedCoordinateSystem("ITM", itmGeo, itmProjection, LinearUnit.Metre, new AxisInfo("East", AxisOrientationEnum.East), new AxisInfo("North", AxisOrientationEnum.North)); _wgs84 = ProjectedCoordinateSystem.WGS84_UTM(36, true).GeographicCoordinateSystem; }
/// <summary> /// Creates a transformation between two coordinate systems. (not implemented) /// </summary> /// <remarks> /// This method will examine the coordinate systems in order to construct a transformation between them. This method may fail if no path between the coordinate systems is found, using the normal failing behavior of the DCP (e.g. throwing an exception). /// </remarks> /// <param name="sourceCoordinateSystem">The source coordinate system.</param> /// <param name="targetCoordinateSystem">The target coordinate system.</param> /// <returns></returns> public ICoordinateTransformation CreateFromCoordinateSystems(ICoordinateSystem sourceCoordinateSystem, ICoordinateSystem targetCoordinateSystem) { IProjectedCoordinateSystem projectedCS = null; IGeographicCoordinateSystem geographicCS = null; if (sourceCoordinateSystem is IProjectedCoordinateSystem && targetCoordinateSystem is IGeographicCoordinateSystem) { projectedCS = (IProjectedCoordinateSystem)sourceCoordinateSystem; geographicCS = (IGeographicCoordinateSystem)targetCoordinateSystem; } else if (targetCoordinateSystem is IProjectedCoordinateSystem && sourceCoordinateSystem is IGeographicCoordinateSystem) { projectedCS = (IProjectedCoordinateSystem)targetCoordinateSystem; geographicCS = (IGeographicCoordinateSystem)sourceCoordinateSystem; } if (projectedCS == null || geographicCS == null) { throw new InvalidOperationException("Need a geographic and a projetced coordinate reference system to make a transform."); } IMathTransform mathTransform = CreateCoordinateOperation(projectedCS.Projection, projectedCS.GeographicCoordinateSystem.HorizontalDatum.Ellipsoid); ICoordinateTransformation coordinateTransformation = new CoordinateTransformation( TransformType.Transformation, geographicCS, projectedCS, mathTransform, "", "", "", "", "", ""); return(coordinateTransformation); }
/// <summary> /// Creates a UTM projection for the northern/// hemisphere based on the WGS84 datum /// </summary> /// <param name="utmZone">Utm Zone</param> /// <returns>Projection</returns> private IProjectedCoordinateSystem CreateUtmProjection(int utmZone) { CoordinateSystemFactory cFac = new ProjNet.CoordinateSystems.CoordinateSystemFactory(); //CoordinateSystemFactory cFac = new SharpMap.CoordinateSystems.CoordinateSystemFactory(); //Create geographic coordinate system based on the WGS84 datum IEllipsoid ellipsoid = cFac.CreateFlattenedSphere("WGS 84", 6378137, 298.257223563, LinearUnit.Metre); IHorizontalDatum datum = cFac.CreateHorizontalDatum("WGS_1984", DatumType.HD_Geocentric, ellipsoid, null); IGeographicCoordinateSystem gcs = cFac.CreateGeographicCoordinateSystem("WGS 84", AngularUnit.Degrees, datum, PrimeMeridian.Greenwich, new AxisInfo("Lon", AxisOrientationEnum.East), new AxisInfo("Lat", AxisOrientationEnum.North)); //Create UTM projection List <ProjectionParameter> parameters = new List <ProjectionParameter>(); parameters.Add(new ProjectionParameter("latitude_of_origin", 0)); parameters.Add(new ProjectionParameter("central_meridian", -183 + 6 * utmZone)); parameters.Add(new ProjectionParameter("scale_factor", 0.9996)); parameters.Add(new ProjectionParameter("false_easting", 500000)); parameters.Add(new ProjectionParameter("false_northing", 0.0)); IProjection projection = cFac.CreateProjection("Transverse Mercator", "Transverse Mercator", parameters); return(cFac.CreateProjectedCoordinateSystem("WGS 84 / UTM zone " + utmZone.ToString() + "N", gcs, projection, LinearUnit.Metre, new AxisInfo("East", AxisOrientationEnum.East), new AxisInfo("North", AxisOrientationEnum.North))); }
private void btnOK_Click(object sender, EventArgs e) { try { if (this.txtConvertMethod.Tag != null) { esriTransformDirection direction; IGeoTransformation transformation; IGeoTransformationOperationSet geographicTransformations = (this.ibasicMap_0 as IMapGeographicTransformations).GeographicTransformations; IGeographicCoordinateSystem pFromGCS = (this.listBox1.SelectedItem as ObjectWrap).Object as IGeographicCoordinateSystem; IGeographicCoordinateSystem pToGCS = (this.cboTarget.SelectedItem as ObjectWrap).Object as IGeographicCoordinateSystem; geographicTransformations.Get(pFromGCS, pToGCS, out direction, out transformation); if (transformation != null) { geographicTransformations.Remove(direction, transformation); } geographicTransformations.Set(esriTransformDirection.esriTransformForward, this.txtConvertMethod.Tag as IGeoTransformation); geographicTransformations.Set(esriTransformDirection.esriTransformReverse, this.txtConvertMethod.Tag as IGeoTransformation); } } catch (Exception exception) { exception.ToString(); } base.DialogResult = DialogResult.OK; }
private void TestGeocentric() { CoordinateSystemFactory cFac = new CoordinateSystemFactory(); IGeographicCoordinateSystem gcs = cFac.CreateGeographicCoordinateSystem("WGS84", AngularUnit.Degrees, HorizontalDatum.WGS84, PrimeMeridian.Greenwich, new AxisInfo("Lon", AxisOrientationEnum.East), new AxisInfo("Lat", AxisOrientationEnum.North)); IGeocentricCoordinateSystem geoccs = cFac.CreateGeocentricCoordinateSystem("WGS84 geocentric", gcs.HorizontalDatum, LinearUnit.Metre, PrimeMeridian.Greenwich); ICoordinateTransformation trans = new CoordinateTransformationFactory().CreateFromCoordinateSystems(gcs, geoccs); var pGeo = new Coordinate(2.12955, 53.80939444, 73); var pGc = Transform(trans.MathTransform, pGeo); trans.MathTransform.Invert(); var pGeo2 = Transform(trans.MathTransform, pGc); trans.MathTransform.Invert(); result.Text += PrintResultTable(gcs, geoccs, pGeo, pGc, new Coordinate(3771793.97, 140253.34, 5124304.35), pGeo2, "Geocentric test"); return; }
private void TestLambertConicConformal_2SP() { CoordinateSystemFactory cFac = new SharpMap.CoordinateSystems.CoordinateSystemFactory(); IEllipsoid ellipsoid = cFac.CreateFlattenedSphere("Clarke 1866", 20925832.16, 294.97470, LinearUnit.USSurveyFoot); IHorizontalDatum datum = cFac.CreateHorizontalDatum("Clarke 1866", DatumType.HD_Geocentric, ellipsoid, null); IGeographicCoordinateSystem gcs = cFac.CreateGeographicCoordinateSystem("Clarke 1866", AngularUnit.Degrees, datum, PrimeMeridian.Greenwich, new AxisInfo("Lon", AxisOrientationEnum.East), new AxisInfo("Lat", AxisOrientationEnum.North)); List <ProjectionParameter> parameters = new List <ProjectionParameter>(); parameters.Add(new ProjectionParameter("latitude_of_origin", 27.833333333)); parameters.Add(new ProjectionParameter("central_meridian", -99)); parameters.Add(new ProjectionParameter("standard_parallel_1", 28.3833333333)); parameters.Add(new ProjectionParameter("standard_parallel_2", 30.2833333333)); parameters.Add(new ProjectionParameter("false_easting", 2000000)); parameters.Add(new ProjectionParameter("false_northing", 0)); IProjection projection = cFac.CreateProjection("Lambert Conic Conformal (2SP)", "lambert_conformal_conic_2sp", parameters); IProjectedCoordinateSystem coordsys = cFac.CreateProjectedCoordinateSystem("NAD27 / Texas South Central", gcs, projection, LinearUnit.USSurveyFoot, new AxisInfo("East", AxisOrientationEnum.East), new AxisInfo("North", AxisOrientationEnum.North)); ICoordinateTransformation trans = new CoordinateTransformationFactory().CreateFromCoordinateSystems(gcs, coordsys); SharpMap.Geometries.Point pGeo = new SharpMap.Geometries.Point(-96, 28.5); SharpMap.Geometries.Point pUtm = new Point(trans.MathTransform.Transform(pGeo.ToDoubleArray())); SharpMap.Geometries.Point pGeo2 = new Point(trans.MathTransform.Inverse().Transform(pUtm.ToDoubleArray())); result.Text += PrintResultTable(gcs, coordsys, pGeo, pUtm, new Point(2963503.91, 254759.80), pGeo2, "Lambert Conic Conformal 2SP test"); }
public void TestNtsIssue191() { List <ProjectionParameter> parameters = new List <ProjectionParameter>(); parameters.Add(new ProjectionParameter("latitude_of_center", 45.30916666666666)); parameters.Add(new ProjectionParameter("longitude_of_center", -86)); parameters.Add(new ProjectionParameter("azimuth", 337.25556)); parameters.Add(new ProjectionParameter("rectified_grid_angle", 337.25556)); parameters.Add(new ProjectionParameter("scale_factor", 0.9996)); parameters.Add(new ProjectionParameter("false_easting", 2546731.496)); parameters.Add(new ProjectionParameter("false_northing", -4354009.816)); CoordinateSystemFactory factory = new CoordinateSystemFactory(); IProjection projection = factory.CreateProjection("Test Oblique", "oblique_mercator", parameters); Assert.That(projection, Is.Not.Null); IGeographicCoordinateSystem wgs84 = GeographicCoordinateSystem.WGS84; IProjectedCoordinateSystem dummy = factory.CreateProjectedCoordinateSystem("dummy pcs", wgs84, projection, LinearUnit.Metre, new AxisInfo("X", AxisOrientationEnum.East), new AxisInfo("Y", AxisOrientationEnum.North)); Assert.That(dummy, Is.Not.Null); CoordinateTransformationFactory transformationFactory = new CoordinateTransformationFactory(); ICoordinateTransformation transform = transformationFactory.CreateFromCoordinateSystems(wgs84, dummy); Assert.That(transform, Is.Not.Null); IMathTransform mathTransform = transform.MathTransform; IMathTransform inverse = mathTransform.Inverse(); Assert.That(inverse, Is.Not.Null); }
public static ISpatialReference GetSR(int type) { Type t = Type.GetTypeFromProgID("esriGeometry.SpatialReferenceEnvironment"); System.Object obj = Activator.CreateInstance(t); ISpatialReferenceFactory srFact = obj as ISpatialReferenceFactory; // Use the enumeration to create an instance of the predefined object. try { IGeographicCoordinateSystem geographicCS = srFact.CreateGeographicCoordinateSystem(type); return(geographicCS as ISpatialReference); } catch (Exception ex) { // do nothing } try { IProjectedCoordinateSystem projectCS = srFact.CreateProjectedCoordinateSystem(type); return(projectCS as ISpatialReference); } catch (Exception ex) { // do nothing } return(null); }
public void TestMercator_2SP_Projection() { CoordinateSystemFactory cFac = new CoordinateSystemFactory(); IEllipsoid ellipsoid = cFac.CreateFlattenedSphere("Krassowski 1940", 6378245.0, 298.3, LinearUnit.Metre); IHorizontalDatum datum = cFac.CreateHorizontalDatum("Krassowski 1940", DatumType.HD_Geocentric, ellipsoid, null); IGeographicCoordinateSystem gcs = cFac.CreateGeographicCoordinateSystem("Krassowski 1940", AngularUnit.Degrees, datum, PrimeMeridian.Greenwich, new AxisInfo("Lon", AxisOrientationEnum.East), new AxisInfo("Lat", AxisOrientationEnum.North)); List <ProjectionParameter> parameters = new List <ProjectionParameter>(5); parameters.Add(new ProjectionParameter("latitude_of_origin", 42)); parameters.Add(new ProjectionParameter("central_meridian", 51)); parameters.Add(new ProjectionParameter("false_easting", 0)); parameters.Add(new ProjectionParameter("false_northing", 0)); IProjection projection = cFac.CreateProjection("Mercator_2SP", "Mercator_2SP", parameters); IProjectedCoordinateSystem coordsys = cFac.CreateProjectedCoordinateSystem("Pulkovo 1942 / Mercator Caspian Sea", gcs, projection, LinearUnit.Metre, new AxisInfo("East", AxisOrientationEnum.East), new AxisInfo("North", AxisOrientationEnum.North)); ICoordinateTransformation trans = new CoordinateTransformationFactory().CreateFromCoordinateSystems(gcs, coordsys); double[] pGeo = new double[] { 53, 53 }; double[] pUtm = trans.MathTransform.Transform(pGeo); double[] pGeo2 = trans.MathTransform.Inverse().Transform(pUtm); double[] expected = new double[] { 165704.29, 5171848.07 }; Assert.IsTrue(ToleranceLessThan(pUtm, expected, 0.02), String.Format("Mercator_2SP forward transformation outside tolerance, Expected {0}, got {1}", expected.ToString(), pUtm.ToString())); Assert.IsTrue(ToleranceLessThan(pGeo, pGeo2, 0.0000001), String.Format("Mercator_2SP reverse transformation outside tolerance, Expected {0}, got {1}", pGeo.ToString(), pGeo2.ToString())); }
private void TestTransverseMercator() { CoordinateSystemFactory cFac = new SharpMap.CoordinateSystems.CoordinateSystemFactory(); IEllipsoid ellipsoid = cFac.CreateFlattenedSphere("Airy 1830", 6377563.396, 299.32496, LinearUnit.Metre); IHorizontalDatum datum = cFac.CreateHorizontalDatum("Airy 1830", DatumType.HD_Geocentric, ellipsoid, null); IGeographicCoordinateSystem gcs = cFac.CreateGeographicCoordinateSystem("Airy 1830", AngularUnit.Degrees, datum, PrimeMeridian.Greenwich, new AxisInfo("Lon", AxisOrientationEnum.East), new AxisInfo("Lat", AxisOrientationEnum.North)); List <ProjectionParameter> parameters = new List <ProjectionParameter>(); parameters.Add(new ProjectionParameter("latitude_of_origin", 49)); parameters.Add(new ProjectionParameter("central_meridian", -2)); parameters.Add(new ProjectionParameter("scale_factor", 0.9996012717)); parameters.Add(new ProjectionParameter("false_easting", 400000)); parameters.Add(new ProjectionParameter("false_northing", -100000)); IProjection projection = cFac.CreateProjection("Transverse Mercator", "Transverse_Mercator", parameters); IProjectedCoordinateSystem coordsys = cFac.CreateProjectedCoordinateSystem("OSGB 1936 / British National Grid", gcs, projection, LinearUnit.Metre, new AxisInfo("East", AxisOrientationEnum.East), new AxisInfo("North", AxisOrientationEnum.North)); ICoordinateTransformation trans = new CoordinateTransformationFactory().CreateFromCoordinateSystems(gcs, coordsys); SharpMap.Geometries.Point pGeo = new SharpMap.Geometries.Point(0.5, 50.5); SharpMap.Geometries.Point pUtm = new Point(trans.MathTransform.Transform(pGeo.ToDoubleArray())); SharpMap.Geometries.Point pGeo2 = new Point(trans.MathTransform.Inverse().Transform(pUtm.ToDoubleArray())); result.Text += PrintResultTable(gcs, coordsys, pGeo, pUtm, new Point(577274.99, 69740.50), pGeo2, "Transverse Mercator test"); }
private static ICoordinateTransformation Geog2Proj(IGeographicCoordinateSystem source, IProjectedCoordinateSystem target) { IMathTransform mathTransform = CreateCoordinateOperation(target.Projection, target.GeographicCoordinateSystem.HorizontalDatum.Ellipsoid); return(new CoordinateTransformation(source, target, TransformType.Transformation, mathTransform, String.Empty, String.Empty, -1, String.Empty, String.Empty)); }
public Vector3 getOffsetFromLeader(MAVState leader, MAVState mav) { //convert Wgs84ConversionInfo to utm CoordinateTransformationFactory ctfac = new CoordinateTransformationFactory(); IGeographicCoordinateSystem wgs84 = GeographicCoordinateSystem.WGS84; int utmzone = (int)((leader.cs.lng - -186.0) / 6.0); IProjectedCoordinateSystem utm = ProjectedCoordinateSystem.WGS84_UTM(utmzone, leader.cs.lat < 0 ? false : true); ICoordinateTransformation trans = ctfac.CreateFromCoordinateSystems(wgs84, utm); double[] masterpll = { leader.cs.lng, leader.cs.lat }; // get leader utm coords double[] masterutm = trans.MathTransform.Transform(masterpll); double[] mavpll = { mav.cs.lng, mav.cs.lat }; //getLeader follower utm coords double[] mavutm = trans.MathTransform.Transform(mavpll); var heading = -leader.cs.yaw; var norotation = new Vector3(masterutm[1] - mavutm[1], masterutm[0] - mavutm[0], 0); norotation.x *= -1; norotation.y *= -1; return(new Vector3(norotation.x * Math.Cos(heading * MathHelper.deg2rad) - norotation.y * Math.Sin(heading * MathHelper.deg2rad), norotation.x * Math.Sin(heading * MathHelper.deg2rad) + norotation.y * Math.Cos(heading * MathHelper.deg2rad), 0)); }
private void listBox1_SelectedIndexChanged(object sender, EventArgs e) { this.btnNew.Enabled = this.listBox1.SelectedIndex != -1; if ((this.bool_0 && (this.listBox1.SelectedIndex != -1)) && (this.cboTarget.SelectedIndex != -1)) { IGeographicCoordinateSystem pFromGCS = (this.listBox1.SelectedItem as ObjectWrap).Object as IGeographicCoordinateSystem; IGeographicCoordinateSystem pToGCS = (this.cboTarget.SelectedItem as ObjectWrap).Object as IGeographicCoordinateSystem; IGeoTransformationOperationSet geographicTransformations = (this.ibasicMap_0 as IMapGeographicTransformations).GeographicTransformations; if (geographicTransformations != null) { esriTransformDirection direction; IGeoTransformation transformation; geographicTransformations.Get(pFromGCS, pToGCS, out direction, out transformation); if (transformation != null) { this.txtConvertMethod.Text = transformation.Name; this.txtConvertMethod.Tag = transformation; } else { this.txtConvertMethod.Text = ""; this.txtConvertMethod.Tag = transformation; } } } }
private void TestMercator_2SP() { CoordinateSystemFactory cFac = new SharpMap.CoordinateSystems.CoordinateSystemFactory(); IEllipsoid ellipsoid = cFac.CreateFlattenedSphere("Krassowski 1940", 6378245.0, 298.3, LinearUnit.Metre); IHorizontalDatum datum = cFac.CreateHorizontalDatum("Krassowski 1940", DatumType.HD_Geocentric, ellipsoid, null); IGeographicCoordinateSystem gcs = cFac.CreateGeographicCoordinateSystem("Krassowski 1940", AngularUnit.Degrees, datum, PrimeMeridian.Greenwich, new AxisInfo("Lon", AxisOrientationEnum.East), new AxisInfo("Lat", AxisOrientationEnum.North)); List <ProjectionParameter> parameters = new List <ProjectionParameter>(); parameters.Add(new ProjectionParameter("latitude_of_origin", 42)); parameters.Add(new ProjectionParameter("central_meridian", 51)); parameters.Add(new ProjectionParameter("false_easting", 0)); parameters.Add(new ProjectionParameter("false_northing", 0)); IProjection projection = cFac.CreateProjection("Mercator_2SP", "Mercator_2SP", parameters); IProjectedCoordinateSystem coordsys = cFac.CreateProjectedCoordinateSystem("Pulkovo 1942 / Mercator Caspian Sea", gcs, projection, LinearUnit.Metre, new AxisInfo("East", AxisOrientationEnum.East), new AxisInfo("North", AxisOrientationEnum.North)); ICoordinateTransformation trans = new CoordinateTransformationFactory().CreateFromCoordinateSystems(gcs, coordsys); SharpMap.Geometries.Point pGeo = new SharpMap.Geometries.Point(53, 53); SharpMap.Geometries.Point pUtm = new Point(trans.MathTransform.Transform(pGeo.ToDoubleArray())); SharpMap.Geometries.Point pGeo2 = new Point(trans.MathTransform.Inverse().Transform(pUtm.ToDoubleArray())); result.Text += PrintResultTable(gcs, coordsys, pGeo, pUtm, new Point(165704.29, 5171848.07), pGeo2, "Mercator_2SP test"); }
internal GeographicTransform( string name, string authority, long code, string alias, string remarks, string abbreviation, IGeographicCoordinateSystem sourceGCS, IGeographicCoordinateSystem targetGCS) : base(name, authority, code, alias, abbreviation, remarks) { _SourceGCS = sourceGCS; _TargetGCS = targetGCS; }
/// <summary> /// Initializes a new instance of the ProjectedCoordinateSystem class. /// </summary> /// <param name="horizontalDatum">The horizontal datum to use.</param> /// <param name="axisInfoArray">An array of IAxisInfo representing the axis information.</param> /// <param name="geographicCoordSystem">The geographic coordinate system.</param> /// <param name="linearUnit">The linear units to use.</param> /// <param name="projection">The projection to use.</param> internal ProjectedCoordinateSystem( IHorizontalDatum horizontalDatum, IAxisInfo[] axisInfoArray, IGeographicCoordinateSystem geographicCoordSystem, ILinearUnit linearUnit, IProjection projection) : this(horizontalDatum, axisInfoArray, geographicCoordSystem, linearUnit, projection, "", "", "", "", "", "") { }
/// <summary> /// Initializes a new instance of a projected coordinate system /// </summary> /// <param name="datum">Horizontal datum</param> /// <param name="geographicCoordinateSystem">Geographic coordinate system</param> /// <param name="linearUnit">Linear unit</param> /// <param name="projection">Projection</param> /// <param name="axisInfo">Axis info</param> /// <param name="name">Name</param> /// <param name="authority">Authority name</param> /// <param name="code">Authority-specific identification code.</param> /// <param name="alias">Alias</param> /// <param name="abbreviation">Abbreviation</param> /// <param name="remarks">Provider-supplied remarks</param> internal ProjectedCoordinateSystem(IHorizontalDatum datum, IGeographicCoordinateSystem geographicCoordinateSystem, ILinearUnit linearUnit, IProjection projection, List<AxisInfo> axisInfo, string name, string authority, long code, string alias, string remarks, string abbreviation) : base(datum, axisInfo, name, authority, code, alias, abbreviation, remarks) { _GeographicCoordinateSystem = geographicCoordinateSystem; _LinearUnit = linearUnit; _Projection = projection; }
public static void WriteGeographicCoordinateSystem(IGeographicCoordinateSystem geographicCoordinateSystem, IndentedTextWriter writer) { writer.WriteLine("GEOGCS["); writer.Indent=writer.Indent+1; writer.WriteLine(String.Format(System.Globalization.CultureInfo.InvariantCulture, "\"{0}\",", geographicCoordinateSystem.Name)); WriteHorizontalDatum(geographicCoordinateSystem.HorizontalDatum, writer); WritePrimeMeridian(geographicCoordinateSystem.PrimeMeridian, writer); //TODO:WriteAngularUnit(geocentricCoordinateSystem.get_Units for(int dimension=0; dimension<geographicCoordinateSystem.Dimension; dimension++) { WriteAxis( geographicCoordinateSystem.GetAxis(dimension), writer ); } writer.WriteLine(String.Format(System.Globalization.CultureInfo.InvariantCulture, "AUTHORITY[\"{0}\",\"{1}\"]", geographicCoordinateSystem.Authority, geographicCoordinateSystem.AuthorityCode)); writer.Indent=writer.Indent-1; writer.Write("]"); }
private void LoadGeoCoord(bool p, IGeographicCoordinateSystem pGeoCoord) { this.txtName.Text = pGeoCoord.Name; this.rtxDetail.Text = "��������ϵͳ:\n"; this.rtxDetail.Text += "Name :" + pGeoCoord.Name +"\n"; this.rtxDetail.Text += " Datum: " + pGeoCoord.Datum.Name + "\n"; this.rtxDetail.Text += " Spheroid: " + pGeoCoord.Datum.Spheroid.Name + "\n"; this.rtxDetail.Text += " Semimajor Axis: " + pGeoCoord.Datum.Spheroid.SemiMajorAxis.ToString() + "\n"; this.rtxDetail.Text += " Semiminor Axis: " + pGeoCoord.Datum.Spheroid.SemiMinorAxis.ToString() + "\n"; this.rtxDetail.Text += " Inverse Flattening: " + pGeoCoord.Datum.Spheroid.Flattening.ToString() + "\n"; }
internal GeographicTransform(IGeographicCoordinateSystem sourceGCS, IGeographicCoordinateSystem targetGCS) { _sourceGCS = sourceGCS; _targetGCS = targetGCS; }
private static ICoordinateTransformation Proj2Geog(IProjectedCoordinateSystem source, IGeographicCoordinateSystem target) { if (source.GeographicCoordinateSystem.EqualParams(target)) { IMathTransform mathTransform = CreateCoordinateOperation(source.Projection, source.GeographicCoordinateSystem.HorizontalDatum.Ellipsoid, source.LinearUnit).Inverse(); return new CoordinateTransformation(source, target, TransformType.Transformation, mathTransform, String.Empty, String.Empty, -1, String.Empty, String.Empty); } else { // Geographic coordinatesystems differ - Create concatenated transform ConcatenatedTransform ct = new ConcatenatedTransform(); CoordinateTransformationFactory ctFac = new CoordinateTransformationFactory(); ct.CoordinateTransformationList.Add(ctFac.CreateFromCoordinateSystems(source, source.GeographicCoordinateSystem)); ct.CoordinateTransformationList.Add(ctFac.CreateFromCoordinateSystems(source.GeographicCoordinateSystem, target)); return new CoordinateTransformation(source, target, TransformType.Transformation, ct, String.Empty, String.Empty, -1, String.Empty, String.Empty); } }
private void btnSelect_Click(object sender, EventArgs e) { System.Windows.Forms.OpenFileDialog flg = new OpenFileDialog(); flg.Filter = "�����ļ�(*prj)|*.prj"; string coordPath = Application.StartupPath + "\\����ϵͳ"; if (!System.IO.Directory.Exists(coordPath)) System.IO.Directory.CreateDirectory(coordPath); flg.InitialDirectory = coordPath; if (flg.ShowDialog() == DialogResult.OK) { ISpatialReferenceFactory SpRefFac = new SpatialReferenceEnvironmentClass(); ISpatialReference SpRef = SpRefFac.CreateESRISpatialReferenceFromPRJFile(flg.FileName); this.m_SpatialReferenceName = SpRef.Name; if (flg.FileName.Contains("�������ϵ")) { this.m_CurGeoCoord = SpRef as IGeographicCoordinateSystem; this.m_Datum = m_CurGeoCoord.Datum.Name; this.txtName.Text = m_CurGeoCoord.Name; this.LoadGeoCoord(true, this.m_CurGeoCoord); this.LoadFileContent(flg.FileName); } else if (flg.FileName.Contains("ƽ������ϵ")) { this.m_CurProCoord = SpRef as IProjectedCoordinateSystem; this.m_Datum = m_CurProCoord.GeographicCoordinateSystem.Datum.Name; this.txtName.Text = m_CurProCoord.Name; this.LoadProCoord(true, this.m_CurProCoord); this.LoadFileContent(flg.FileName); } } }
private void BindRunTime() { if (ESRI.ArcGIS.RuntimeManager.ActiveRuntime == null) { // Required to prevent Runtime.InteropServices.COMException ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.Desktop); bngSRef = new SpatialReferenceEnvironmentClass().CreateProjectedCoordinateSystem((int)esriSRProjCSType.esriSRProjCS_BritishNationalGrid); wgs84SRef = new SpatialReferenceEnvironmentClass().CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_WGS1984); } }
private static ICoordinateTransformation Proj2Geog(IProjectedCoordinateSystem source, IGeographicCoordinateSystem target) { if (source.GeographicCoordinateSystem.EqualParams(target)) { return new CoordinateTransformation(source, target, TransformType.Transformation, CreateCoordinateOperation(source.Projection, source.GeographicCoordinateSystem.HorizontalDatum.Ellipsoid).Inverse(), string.Empty, string.Empty, -1L, string.Empty, string.Empty); } ConcatenatedTransform mathTransform = new ConcatenatedTransform(); CoordinateTransformationFactory factory = new CoordinateTransformationFactory(); mathTransform.CoordinateTransformationList.Add(factory.CreateFromCoordinateSystems(source, source.GeographicCoordinateSystem)); mathTransform.CoordinateTransformationList.Add(factory.CreateFromCoordinateSystems(source.GeographicCoordinateSystem, target)); return new CoordinateTransformation(source, target, TransformType.Transformation, mathTransform, string.Empty, string.Empty, -1L, string.Empty, string.Empty); }
private static ICoordinateTransformation Proj2Geog(IProjectedCoordinateSystem source, IGeographicCoordinateSystem target) { IMathTransform mathTransform = CreateCoordinateOperation(source.Projection, source.GeographicCoordinateSystem.HorizontalDatum.Ellipsoid).Inverse(); return new CoordinateTransformation(source, target, TransformType.Transformation, mathTransform, String.Empty, String.Empty, -1, String.Empty, String.Empty); }
/// <summary> /// Geographic to geographic transformation /// </summary> /// <remarks>Adds a datum shift if nessesary</remarks> /// <param name="source"></param> /// <param name="target"></param> /// <returns></returns> private ICoordinateTransformation CreateGeog2Geog(IGeographicCoordinateSystem source, IGeographicCoordinateSystem target) { if (source.HorizontalDatum.EqualParams(target.HorizontalDatum)) { //No datum shift needed return new CoordinateTransformation(source, target, TransformType.Conversion, new GeographicTransform(source, target), String.Empty, String.Empty, -1, String.Empty, String.Empty); } else { //Create datum shift //Convert to geocentric, perform shift and return to geographic CoordinateTransformationFactory ctFac = new CoordinateTransformationFactory(); CoordinateSystemFactory cFac = new CoordinateSystemFactory(); IGeocentricCoordinateSystem sourceCentric = cFac.CreateGeocentricCoordinateSystem(source.HorizontalDatum.Name + " Geocentric", source.HorizontalDatum, LinearUnit.Metre, source.PrimeMeridian); IGeocentricCoordinateSystem targetCentric = cFac.CreateGeocentricCoordinateSystem(target.HorizontalDatum.Name + " Geocentric", target.HorizontalDatum, LinearUnit.Metre, source.PrimeMeridian); ConcatenatedTransform ct = new ConcatenatedTransform(); ct.CoordinateTransformationList.Add(ctFac.CreateFromCoordinateSystems(source, sourceCentric)); ct.CoordinateTransformationList.Add(ctFac.CreateFromCoordinateSystems(sourceCentric, targetCentric)); ct.CoordinateTransformationList.Add(ctFac.CreateFromCoordinateSystems(targetCentric, target)); return new CoordinateTransformation(source, target, TransformType.Transformation, ct, String.Empty, String.Empty, -1, String.Empty, String.Empty); } }
private static ICoordinateTransformation Geog2Geoc(IGeographicCoordinateSystem source, IGeocentricCoordinateSystem target) { IMathTransform geocMathTransform = CreateCoordinateOperation(target); return new CoordinateTransformation(source, target, TransformType.Conversion, geocMathTransform, String.Empty, String.Empty, -1, String.Empty, String.Empty); }
private void MakeCoordinateSystems() { //Create a spatial reference environment and get theISpatialReferenceFactory2 interface ISpatialReferenceFactory2 spatRefFact = new SpatialReferenceEnvironmentClass(); //Create a geographic coordinate system and get the IGeographicCoordinateSystem interface m_GeographicCoordinateSystem = spatRefFact.CreateGeographicCoordinateSystem((int) esriSRGeoCSType.esriSRGeoCS_WGS1984); //Create a projected coordinate system and get the IProjectedCoordinateSystem interface m_ProjectedCoordinateSystem = spatRefFact.CreateProjectedCoordinateSystem((int)esriSRProjCSType.esriSRProjCS_World_Mollweide); //Set the map controls spatial reference property m_MapControl.SpatialReference = m_ProjectedCoordinateSystem; }
private static ICoordinateTransformation Geog2Geoc(IGeographicCoordinateSystem source, IGeocentricCoordinateSystem target) { return new CoordinateTransformation(source, target, TransformType.Conversion, CreateCoordinateOperation(target), string.Empty, string.Empty, -1L, string.Empty, string.Empty); }
/// <summary> /// Creates a <see cref="ProjectedCoordinateSystem"/> using a projection object. /// </summary> /// <param name="name">Name of projected coordinate system</param> /// <param name="gcs">Geographic coordinate system</param> /// <param name="projection">Projection</param> /// <param name="linearUnit">Linear unit</param> /// <param name="axis0">Primary axis</param> /// <param name="axis1">Secondary axis</param> /// <returns>Projected coordinate system</returns> public IProjectedCoordinateSystem CreateProjectedCoordinateSystem(string name, IGeographicCoordinateSystem gcs, IProjection projection, ILinearUnit linearUnit, AxisInfo axis0, AxisInfo axis1) { if (string.IsNullOrEmpty(name)) throw new ArgumentException("Invalid name"); if (gcs == null) throw new ArgumentException("Geographic coordinate system was null"); if (projection == null) throw new ArgumentException("Projection was null"); if (linearUnit == null) throw new ArgumentException("Linear unit was null"); List<AxisInfo> info = new List<AxisInfo>(2); info.Add(axis0); info.Add(axis1); return new ProjectedCoordinateSystem(null, gcs, linearUnit, projection, info, name, String.Empty, -1, String.Empty, String.Empty, String.Empty); }
/// <summary> /// Creates a projected coordinate system using a projection object. /// </summary> /// <param name="name">The name of the projected coordinate system.</param> /// <param name="geographicCoordinateSystem">The geographic coordinate system to base this coordinate system on.</param> /// <param name="projection">The projection details.</param> /// <param name="linearUnit">The linear units to use.</param> /// <param name="axis0">The X axis.</param> /// <param name="axis1">The Y aixs.</param> /// <returns>An object the implements the IProjectedCoordinateSystem interface.</returns> public IProjectedCoordinateSystem CreateProjectedCoordinateSystem(string name, IGeographicCoordinateSystem geographicCoordinateSystem, IProjection projection, ILinearUnit linearUnit, IAxisInfo axis0, IAxisInfo axis1) { if (name==null) { throw new ArgumentNullException("name"); } if (geographicCoordinateSystem==null) { throw new ArgumentNullException("geographicCoordinateSystem"); } if (projection==null) { throw new ArgumentNullException("projection"); } if (linearUnit==null) { throw new ArgumentNullException("linearUnit"); } IAxisInfo[] axisInfo = new IAxisInfo[2]; axisInfo[0]=axis0; axisInfo[1]=axis1; ProjectedCoordinateSystem projectedCS = new ProjectedCoordinateSystem(null,axisInfo,geographicCoordinateSystem,linearUnit, projection); return projectedCS; }
public IProjectedCoordinateSystem CreateProjectedCoordinateSystem(string name, IGeographicCoordinateSystem gcs, IProjection projection, ILinearUnit linearUnit, AxisInfo axis0, AxisInfo axis1) { throw new NotImplementedException(); }
/// <summary> /// Geographic to geographic transformation /// </summary> /// <remarks>Adds a datum shift if nessesary</remarks> /// <param name="source"></param> /// <param name="target"></param> /// <returns></returns> private ICoordinateTransformation CreateGeog2Geog(IGeographicCoordinateSystem source, IGeographicCoordinateSystem target) { if (source.HorizontalDatum.EqualParams(target.HorizontalDatum)) { return new CoordinateTransformation(source, target, TransformType.Conversion, new Topology.CoordinateSystems.Transformations.GeographicTransform(source, target), string.Empty, string.Empty, -1L, string.Empty, string.Empty); } CoordinateTransformationFactory factory = new CoordinateTransformationFactory(); CoordinateSystemFactory factory2 = new CoordinateSystemFactory(); IGeocentricCoordinateSystem targetCS = factory2.CreateGeocentricCoordinateSystem(source.HorizontalDatum.Name + " Geocentric", source.HorizontalDatum, LinearUnit.Metre, source.PrimeMeridian); IGeocentricCoordinateSystem system2 = factory2.CreateGeocentricCoordinateSystem(target.HorizontalDatum.Name + " Geocentric", target.HorizontalDatum, LinearUnit.Metre, source.PrimeMeridian); ConcatenatedTransform mathTransform = new ConcatenatedTransform(); mathTransform.CoordinateTransformationList.Add(factory.CreateFromCoordinateSystems(source, targetCS)); mathTransform.CoordinateTransformationList.Add(factory.CreateFromCoordinateSystems(targetCS, system2)); mathTransform.CoordinateTransformationList.Add(factory.CreateFromCoordinateSystems(system2, target)); return new CoordinateTransformation(source, target, TransformType.Transformation, mathTransform, string.Empty, string.Empty, -1L, string.Empty, string.Empty); }
internal GeographicTransform(IGeographicCoordinateSystem sourceGCS, IGeographicCoordinateSystem targetGCS) { this._SourceGCS = sourceGCS; this._TargetGCS = targetGCS; }
private static ICoordinateTransformation Geog2Geoc(IGeographicCoordinateSystem source, IGeocentricCoordinateSystem target) { IMathTransform geocMathTransform = CreateCoordinateOperation(target); if (source.PrimeMeridian.EqualParams(target.PrimeMeridian)) { return new CoordinateTransformation(source, target, TransformType.Conversion, geocMathTransform, String.Empty, String.Empty, -1, String.Empty, String.Empty); } else { var ct = new ConcatenatedTransform(); ct.CoordinateTransformationList.Add(new CoordinateTransformation(source, target, TransformType.Transformation, new PrimeMeridianTransform(source.PrimeMeridian, target.PrimeMeridian), String.Empty, String.Empty, -1, String.Empty, String.Empty)); ct.CoordinateTransformationList.Add(new CoordinateTransformation(source, target, TransformType.Conversion, geocMathTransform, String.Empty, String.Empty, -1, String.Empty, String.Empty)); return new CoordinateTransformation(source, target, TransformType.Conversion, ct, String.Empty, String.Empty, -1, String.Empty, String.Empty); } }