/// <summary> /// Convert Vector3 World Space location to Position taking account of zoom, scale and mapscale /// </summary> /// <param name="position">Vector3 World Space coordinates</param> /// <returns>Position</returns> static public IPosition ToPosition(this Vector3 position, ICRSObject crs = null) { Geometry geom = position.ToGeometry(); SpatialReference sr = new SpatialReference(null); if (crs == null) { sr.SetWellKnownGeogCS("EPSG:4326"); } else { switch (crs.Type) { case CRSType.Name: string name = (crs as NamedCRS).Properties["name"] as string; sr.SetProjCS(name); break; case CRSType.Link: string url = (crs as LinkedCRS).Properties["href"] as string; sr.ImportFromUrl(url); break; case CRSType.Unspecified: sr.SetWellKnownGeogCS("EPSG:4326"); break; } } geom.TransformTo(sr); double[] argout = new double[3]; geom.GetPoint(0, argout); return(new Position(argout[0], argout[1], argout[2])); }
static public Geometry ToGeometry(this LineString line) { Geometry geom = new Geometry(wkbGeometryType.wkbLineString); SpatialReference sr = new SpatialReference(null); ICRSObject crs = line.CRS; if (crs == null) { crs = new NamedCRS("EPSG:4326"); } switch (crs.Type) { case CRSType.Name: string name = (crs as NamedCRS).Properties["name"] as string; if (name.Contains("urn")) { sr.ImportFromUrl(name); } else if (name.Contains("EPSG")) { string[] args = name.Split(':'); sr.ImportFromEPSG(int.Parse(args[1])); } else { sr.SetWellKnownGeogCS(name); } break; case CRSType.Link: string url = (crs as LinkedCRS).Properties["href"] as string; sr.ImportFromUrl(url); break; case CRSType.Unspecified: sr.SetWellKnownGeogCS("EPSG:4326"); break; } geom.AssignSpatialReference(sr); Position[] vertexes = line.Points(); foreach (Position vertex in vertexes) { Nullable <double> alt = vertex.Altitude; geom.AddPoint(vertex.Latitude, vertex.Longitude, alt ?? 0.0); } return(geom); }