/// <summary> /// 构建不同的投影变换方法 /// </summary> /// <param name="projection"></param> /// <param name="ellipsoid"></param> /// <param name="unit"></param> /// <returns></returns> private static IMathTransform CreateCoordinateOperation(IProjection projection, IEllipsoid ellipsoid, ILinearUnit unit) { List <ProjectionParameter> parameterList = new List <ProjectionParameter>(projection.NumParameters); for (int i = 0; i < projection.NumParameters; i++) { parameterList.Add(projection.GetParameter(i)); } parameterList.Add(new ProjectionParameter("semi_major", ellipsoid.SemiMajorAxis)); //长轴 parameterList.Add(new ProjectionParameter("semi_minor", ellipsoid.SemiMinorAxis)); //短轴 parameterList.Add(new ProjectionParameter("unit", unit.MetersPerUnit)); //单位弧度 IMathTransform transform = null; switch (projection.ClassName.ToLower(CultureInfo.InvariantCulture).Replace(' ', '_')) { case "mercator": case "mercator_1sp": case "mercator_2sp": //1SP transform = new Mercator(parameterList); break; case "transverse_mercator": transform = new TransverseMercator(parameterList); break; case "gauss_kruger": //高斯克吕格投影 transform = new GaussKrugerProjection(parameterList); break; case "albers": case "albers_conic_equal_area": transform = new AlbersProjection(parameterList); break; case "krovak": transform = new KrovakProjection(parameterList); break; case "lambert_conformal_conic": case "lambert_conformal_conic_2sp": case "lambert_conic_conformal_(2sp)": transform = new LambertConformalConic2SP(parameterList); break; default: throw new NotSupportedException(String.Format("Projection {0} is not supported.", projection.ClassName)); } return(transform); }
public void MapProjectionsWorkingManualClarkeLatitudeTableTest() { var clarke1866 = new SpheroidEquatorialPolar(6378206.4, 6356583.8); var projection = new Mercator(0, 1, Vector2.Zero, new SpheroidEquatorialInvF(1.0, clarke1866.InvF)); // it has a major axis of 1.0 // check all the Y coordinates Assert.AreEqual(3.12454, projection.TransformValue(new GeographicCoordinate(1.48352986, 0)).Y, 0.001); // 85 degrees N Assert.AreEqual(1.50031, projection.TransformValue(new GeographicCoordinate(1.13446401, 0)).Y, 0.001); // 65 degrees N Assert.AreEqual(0.87658, projection.TransformValue(new GeographicCoordinate(0.785398163, 0)).Y, 0.001); // 45 degrees N Assert.AreEqual(0.44801, projection.TransformValue(new GeographicCoordinate(0.436332313, 0)).Y, 0.001); // 25 degrees N Assert.AreEqual(0.26309, projection.TransformValue(new GeographicCoordinate(0.261799388, 0)).Y, 0.001); // 15 degrees N Assert.AreEqual(0.08679, projection.TransformValue(new GeographicCoordinate(0.0872664626, 0)).Y, 0.001); // 5 degrees N Assert.AreEqual(0, projection.TransformValue(new GeographicCoordinate(0, 0)).Y, 0.001); // 0 degrees }
public void EpsgExample_1_3_3_B_InverseTest() { var projection = new Mercator( new GeographicCoordinate(0.73303829, 0.89011792), new Vector2(0, 0), new SpheroidEquatorialInvF(6378245, 298.3) ); var expected = new GeographicCoordinate(0.9250245, 0.9250245); var input = new Point2(165704.29, 5171848.07); var result = projection.GetInverse().TransformValue(input); Assert.AreEqual(expected.Latitude, result.Latitude, 0.000000006); Assert.AreEqual(expected.Longitude, result.Longitude, 0.000000005); }
public void EpsgExample_1_3_3_C_Test() { var projection = Mercator.ConstructVariantC( new GeographicCoordinate(0.73303829, 0.89011792), new Vector2(0, 0), new SpheroidEquatorialInvF(6378245, 298.3)); var input = new GeographicCoordinate(0.9250245, 0.9250245); var expected = new Point2(165704.29, 1351950.22); var result = projection.TransformValue(input); Assert.AreEqual(expected.X, result.X, 0.04); Assert.AreEqual(expected.Y, result.Y, 0.06); }
public void EpsgExample_1_3_3_B_Test() { var projection = new Mercator( new GeographicCoordinate(0.73303829, 0.89011792), new Vector2(0, 0), new SpheroidEquatorialInvF(6378245, 298.3) ); var input = new GeographicCoordinate(0.9250245, 0.9250245); var expected = new Point2(165704.29, 5171848.07); var result = projection.TransformValue(input); Assert.AreEqual(expected.X, result.X, 0.03); Assert.AreEqual(expected.Y, result.Y, 0.05); }
public void Test(string geoResourceName, string mercResourceName, double projectDelta, double unprojectDelta) { var latLonData = GoldData.GetReadyReader(geoResourceName); var lccData = GoldData.GetReadyReader(mercResourceName); var latTrueScale = lccData["LATITUDE OF TRUE SCALE"]; Mercator projection; if (null == latTrueScale) { projection = new Mercator( Double.Parse(lccData["CENTRAL MERIDIAN"]) / 180 * Math.PI, Double.Parse(lccData["SCALE FACTOR"]), new Vector2( Double.Parse(lccData["FALSE EASTING"]), Double.Parse(lccData["FALSE NORTHING"]) ), GoldData.GenerateSpheroid(lccData["DATUM"]) ); } else { projection = new Mercator( new GeographicCoordinate( Double.Parse(latTrueScale) / 180 * Math.PI, Double.Parse(lccData["CENTRAL MERIDIAN"]) / 180 * Math.PI ), new Vector2( Double.Parse(lccData["FALSE EASTING"]), Double.Parse(lccData["FALSE NORTHING"]) ), GoldData.GenerateSpheroid(lccData["DATUM"]) ); } var inverse = projection.GetInverse(); while (latLonData.Read() && lccData.Read()) { var coord = latLonData.CurrentLatLon(); var coordRads = latLonData.CurrentLatLonRadians(); var expected = lccData.CurrentPoint2D(); var projected = projection.TransformValue(coordRads); Assert.AreEqual(expected.X, projected.X, projectDelta); Assert.AreEqual(expected.Y, projected.Y, projectDelta); var unProjected = inverse.TransformValue(expected); unProjected = new GeographicCoordinate(unProjected.Latitude * 180.0 / Math.PI, unProjected.Longitude * 180.0 / Math.PI); Assert.AreEqual(coord.Latitude, unProjected.Latitude, unprojectDelta); Assert.AreEqual(coord.Longitude, unProjected.Longitude, unprojectDelta); } }
public void EpsgExample_1_3_3_A_InverseTest() { var projection = new Mercator( 1.91986218, 0.997, new Vector2(3900000, 900000), new SpheroidEquatorialInvF(6377397.155, 299.15281) ); var expected = new GeographicCoordinate(-0.05235988, 2.09439510); var input = new Point2(5009726.58, 569150.82); var result = projection.GetInverse().TransformValue(input); Assert.AreEqual(expected.Latitude, result.Latitude, 0.000000003); Assert.AreEqual(expected.Longitude, result.Longitude, 0.000000005); }
public void EpsgExample_1_3_3_A_Test() { var projection = new Mercator( 1.91986218, 0.997, new Vector2(3900000, 900000), new SpheroidEquatorialInvF(6377397.155, 299.15281) ); var input = new GeographicCoordinate(-0.05235988, 2.09439510); var expected = new Point2(5009726.58, 569150.82); var result = projection.TransformValue(input); Assert.AreEqual(expected.X, result.X, 0.03); Assert.AreEqual(expected.Y, result.Y, 0.02); }
public BuildingPart BuildPart(XElement way, bool volume = true) { var tags = way.Descendants("tag") .ToDictionary( tag => tag.Attribute("k").Value, // add key tag => tag.Attribute("v").Value); // add value // Building creation var buildingPart = new BuildingPart( tags.ContainsKey("name") ? tags["name"] : "", Convert.ToInt64(way.Attribute("id").Value)); // Outline construction // TODO check if closed? foreach (var elt in way.Descendants("nd")) { // find node that matches ways' node ref var query = (from node in Xdoc.Descendants("node") where (string)node.Attribute("id") == (string)elt.Attribute("ref") select node).First(); var pos = Mercator.ToMeters(Convert.ToDouble(query.Attribute("lat").Value), Convert.ToDouble(query.Attribute("lon").Value)); var x = pos.X - Tile.Center.X; var y = pos.Y - Tile.Center.Y; buildingPart.Outline.Add(new Vector2(x, y)); } // Part data PartData part; part.volume = volume; part.height = float.Parse(tags.ContainsKey("height") ? Regex.Match(tags["height"], @"\d+").Value : "-1", CultureInfo.InvariantCulture); part.min_height = float.Parse(tags.ContainsKey("min_height") ? Regex.Match(tags["min_height"], @"\d+").Value : "-1", CultureInfo.InvariantCulture); part.levels = Convert.ToInt16(tags.ContainsKey("building:levels") ? tags["building:levels"] : "-1"); part.min_level = Convert.ToInt16(tags.ContainsKey("building:min_level") ? tags["building:min_level"] : "-1"); buildingPart.Data = part; Surface surf; surf.colour = tags.ContainsKey("building:colour") ? tags["building:colour"] : ""; surf.material = tags.ContainsKey("building:material") ? tags["building:material"] : ""; buildingPart.PartSurface = surf; return(buildingPart); }
private static IMathTransform CreateCoordinateOperation(IProjection projection, IEllipsoid ellipsoid) { List <ProjectionParameter> parameterList = new List <ProjectionParameter>(projection.NumParameters); for (int i = 0; i < projection.NumParameters; i++) { parameterList.Add(projection.GetParameter(i)); } parameterList.Add(new ProjectionParameter("semi_major", ellipsoid.SemiMajorAxis)); parameterList.Add(new ProjectionParameter("semi_minor", ellipsoid.SemiMinorAxis)); IMathTransform transform = null; switch (projection.ClassName.ToLower()) { case "mercator_1sp": case "mercator_2sp": //1SP transform = new Mercator(parameterList); break; case "transverse_mercator": transform = new TransverseMercator(parameterList); break; case "albers": transform = new AlbersProjection(parameterList); break; case "lambert_conformal_conic": case "lambert_conformal_conic_2sp": transform = new LambertConformalConic2SP(parameterList); break; default: throw new NotSupportedException(String.Format("Projection {0} is not supported.", projection.ClassName)); } return(transform); }
void Start() { Mercator mProj = new Mercator(); // obtaining the maximum and minimum latitiude and longitude from the graph if (_viz == null) { _viz = this.gameObject.GetComponent <Visualisation>(); mySourceData = (CSVDataSource)_viz.dataSource; } string x_data_dim = _viz.xDimension.Attribute; string z_data_dim = _viz.zDimension.Attribute; float maxlongitute = float.Parse(_viz.dataSource.getOriginalValue(mySourceData[x_data_dim].Data.Max(), x_data_dim) + ""); float maxlatitude = float.Parse(_viz.dataSource.getOriginalValue(mySourceData[z_data_dim].Data.Max(), z_data_dim) + ""); float minlongitute = float.Parse(_viz.dataSource.getOriginalValue(mySourceData[x_data_dim].Data.Min(), x_data_dim) + ""); float minlatitude = float.Parse(_viz.dataSource.getOriginalValue(mySourceData[z_data_dim].Data.Min(), z_data_dim) + ""); //GeoCoordinate float[] topLeft = mProj.latLonToMeters(minlatitude, minlongitute); float[] topright = mProj.latLonToMeters(minlatitude, maxlongitute); float[] bottomLeft = mProj.latLonToMeters(maxlatitude, minlongitute); float[] bottomRight = mProj.latLonToMeters(maxlatitude, maxlongitute); Vector2d centerMap = new Vector2d(minlatitude + (maxlatitude - minlatitude) / 2.0, minlongitute + (maxlongitute - minlongitute) / 2.0); float leftRightDistance = this.distance(topLeft[0], topLeft[1], topright[0], topright[1]); float topBottomDistance = this.distance(topLeft[0], topLeft[1], bottomLeft[0], bottomLeft[1]); float maxdist = Mathf.Max(leftRightDistance, topBottomDistance); float pixelDist = 3 * 256; int lastgoodZoom = 0; for (int i = 0; i < 17; i++) { float realSize = 256 * (maxdist / 40000000) * Mathf.Pow(2, i); if (realSize < pixelDist) { lastgoodZoom = i; } } Debug.Log("Appropriate Zoom level: " + lastgoodZoom); //_map.ResetMap(); GameObject mapGo = new GameObject("Map_GO"); mapGo.transform.parent = this.transform; mapGo.transform.localScale = new Vector3(0.1f, 0.1f, 0.1f); _map = mapGo.AddComponent <AbstractMap>(); _map.Initialize(centerMap, lastgoodZoom); // calculating the coordinates for the x-axis end point, z-axis end point and the center xExtremeAxis = maxlatitude + "," + minlongitute; zExtremeAxis = minlatitude + "," + maxlongitute; center = minlatitude + "," + minlongitute; Debug.Log("ExtremeValue: " + center + " - " + xExtremeAxis + " - " + zExtremeAxis); // coverting the coordinates into geolocation Vector3 xExtremeAxisGeo = _map.GeoToWorldPosition(Conversions.StringToLatLon(xExtremeAxis), true); Vector3 zExtremeAxisGeo = _map.GeoToWorldPosition(Conversions.StringToLatLon(zExtremeAxis), true); Vector3 centerGeo = _map.GeoToWorldPosition(Conversions.StringToLatLon(center), true); // Assigning the position to the visulization by making center of the visulization fixed Vector3 mapPos = _map.transform.position; _viz.transform.position = centerGeo; _map.transform.position = mapPos; // calculating the length of x and z axis for width and depth of the graph respectively var width = (centerGeo - zExtremeAxisGeo).magnitude; var Depth = (centerGeo - xExtremeAxisGeo).magnitude; _viz.width = width; _viz.depth = Depth; //_map. // height of the graph // when z-axis is not defined if (_viz.zDimension.Attribute == "Undefined") { _viz.height = _map.Options.locationOptions.zoom / 5; } else // when z-axis is defined { _viz.height = _viz.zDimension.maxScale; } _viz.gameObject.GetComponent <ScatterplotVisualisation>().UpdateVisualisationAxes(AbstractVisualisation.PropertyType.Scaling); // function for map update _map.OnUpdated += delegate { UpdateMap(); }; }
private static IMathTransform CreateCoordinateOperation(IProjection projection, IEllipsoid ellipsoid, ILinearUnit unit) { List<ProjectionParameter> parameterList = new List<ProjectionParameter>(projection.NumParameters); for (int i = 0; i < projection.NumParameters; i++) parameterList.Add(projection.GetParameter(i)); parameterList.Add(new ProjectionParameter("semi_major", ellipsoid.SemiMajorAxis)); parameterList.Add(new ProjectionParameter("semi_minor", ellipsoid.SemiMinorAxis)); parameterList.Add(new ProjectionParameter("unit", unit.MetersPerUnit)); IMathTransform transform = null; switch (projection.ClassName.ToLower(CultureInfo.InvariantCulture).Replace(' ', '_')) { case "mercator": case "mercator_1sp": case "mercator_2sp": transform = new Mercator(parameterList); break; case "transverse_mercator": transform = new TransverseMercator(parameterList); break; case "albers": case "albers_conic_equal_area": transform = new AlbersProjection(parameterList); break; case "lambert_conformal_conic": case "lambert_conformal_conic_2sp": case "lambert_conic_conformal_(2sp)": transform = new LambertConformalConic2SP(parameterList); break; default: throw new NotSupportedException(String.Format("Projection {0} is not supported.", projection.ClassName)); } return transform; }
public Vector2 PixelPosition(GlobalPosition pos) { return((1 << GoogleMapsDriver.main.zoom) * Mercator.CoordToPoint(pos)); }