예제 #1
0
파일: Mesh.cs 프로젝트: BHoM/XML_Toolkit
        public static List <KML.Polygon> ToKML(this BHG.Mesh mesh, GeoReference geoReference)
        {
            mesh = mesh.Rotate(geoReference.Reference, BHG.Vector.ZAxis, geoReference.NorthVector.SignedAngle(BHG.Vector.YAxis, BHG.Vector.ZAxis));
            List <KML.Polygon> polygons = new List <KML.Polygon>();

            foreach (BHG.Face face in mesh.Faces)
            {
                List <double>    coords = new List <double>();
                List <BHG.Point> points = new List <BHG.Point> {
                    mesh.Vertices[face.A].DeepClone(),
                    mesh.Vertices[face.B].DeepClone(),
                    mesh.Vertices[face.C].DeepClone(),
                    mesh.Vertices[face.A].DeepClone()
                };

                if (face.D > -1)
                {
                    points.Insert(3, mesh.Vertices[face.D].DeepClone());
                }

                foreach (BHG.Point p in points)
                {
                    BHG.Point kmlpoint = p.ToLatLon(geoReference);
                    coords.Add(kmlpoint.X);
                    coords.Add(kmlpoint.Y);
                    coords.Add(kmlpoint.Z);
                }

                KML.Polygon polygon = new KML.Polygon();
                polygon.AltitudeMode = geoReference.AltitudeMode.ToKML();
                polygon.OuterBoundaryIs.LinearRing.Coordinates = coords.ToArray();
                polygons.Add(polygon);
            }
            return(polygons);
        }
예제 #2
0
        public static KML.Point ToKML(this BHG.Point point, GeoReference geoReference)
        {
            BHG.Point     latlon = point.ToLatLon(geoReference);
            List <double> coords = new List <double>()
            {
                latlon.X,
                latlon.Y,
                latlon.Z
            };

            KML.Point kmlPoint = new KML.Point();
            kmlPoint.AltitudeMode = geoReference.AltitudeMode.ToKML();
            kmlPoint.Coordinates  = coords.ToArray();
            return(kmlPoint);
        }
예제 #3
0
        public static BHG.Point ToLatLon(this BHG.Point point, GeoReference geoReference)
        {
            BHG.Vector vector = point - geoReference.Reference;
            //vector in plane
            vector.Z = 0;
            double degLatInM  = 10000000.0 / 90;
            double bearing    = vector.SignedAngle(BHG.Vector.YAxis, BHG.Vector.ZAxis);
            double DeltaNorth = vector.Length() * Math.Cos(bearing) / degLatInM;
            double DeltaEast  = vector.Length() * Math.Sin(bearing) / Math.Cos(geoReference.ReferenceLatitude * Math.PI / 180) / degLatInM;

            if (geoReference.AltitudeMode == AltitudeMode.Absolute)
            {
                point.Z += geoReference.ReferenceAltitude;
            }

            return(new BHG.Point()
            {
                X = geoReference.ReferenceLongitude + DeltaEast,
                Y = geoReference.ReferenceLatitude + DeltaNorth,
                Z = point.Z
            });
            //https://gis.stackexchange.com/questions/5821/calculating-latitude-longitude-x-miles-from-point
        }