Example #1
0
 /// <summary>
 /// Draws the line string.
 /// </summary>
 /// <param name="ge">The ge.</param>
 /// <param name="p1">The p1.</param>
 /// <param name="p2">The p2.</param>
 /// <returns></returns>
 public static IKmlPlacemark DrawLineString(IGEPlugin ge, IKmlPoint p1, IKmlPoint p2)
 {
     IKmlPlacemark lineStringPlacemark = ge.createPlacemark(String.Empty);
     IKmlLineString lineString = ge.createLineString(String.Empty);
     lineStringPlacemark.setGeometry(lineString);
     lineString.setTessellate(1);
     lineString.getCoordinates().pushLatLngAlt(p1.getLatitude(), p1.getLongitude(), 0);
     lineString.getCoordinates().pushLatLngAlt(p2.getLatitude(), p2.getLongitude(), 0);
     return lineStringPlacemark;
 }
Example #2
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="point1"></param>
        /// <param name="point2"></param>
        /// <returns></returns>
        public static double AngularDistance(IKmlPoint point1, IKmlPoint point2)
        {
            double phi1 = point1.getLatitude().DegreesToRadians();
            double phi2 = point2.getLatitude().DegreesToRadians();
            double d_phi = (point2.getLatitude() - point1.getLatitude()).DegreesToRadians();
            double d_lmd = (point2.getLongitude() - point1.getLongitude()).DegreesToRadians();
            double A = Math.Pow(Math.Sin(d_phi / 2), 2) +
                Math.Cos(phi1) * Math.Cos(phi2) *
                Math.Pow(Math.Sin(d_lmd / 2), 2);

            return 2 * Math.Atan2(Math.Sqrt(A), Math.Sqrt(1 - A));
        }
Example #3
0
        /// <summary>
        /// Icon을 생성하여 GEPlugin 에 Append
        /// </summary>
        /// <param name="placemarkID"></param>
        /// <param name="iconName"></param>
        /// <param name="iconURL"></param>
        /// <param name="latitude"></param>
        /// <param name="longitude"></param>
        public void CreateSystemIcon(string placemarkID, string iconName, string iconUrl, double latitude, double longitude)
        {
            try
            {
                if (this.ge == null)
                {
                    FileLogManager.GetInstance().WriteLog("[GEController] CreateSystemIcon( GEPlugin is null. )");

                    throw new Exception("External Exception : GEPlugin is null.");
                }

                //아이콘 생성---------------------------------------시작
                IKmlPlacemark placemark = ge.createPlacemark("icon" + placemarkID);
                placemark.setDescription(iconName);
                if (!string.IsNullOrEmpty(iconUrl))
                {
                    //아이콘 스타일 변경----------------------------시작
                    IKmlIcon icon = ge.createIcon("");
                    icon.setHref(iconUrl);
                    IKmlStyle style = ge.createStyle("");
                    style.getIconStyle().setIcon(icon);
                    placemark.setStyleSelector(style);
                    //아이콘 스타일 변경------------------------------끝
                }
                else
                {
                    //아이콘 스타일 변경----------------------------시작
                    IKmlIcon icon = ge.createIcon("");
                    icon.setHref("http://maps.google.com/mapfiles/kml/paddle/red-circle.png");
                    IKmlStyle style = ge.createStyle("");
                    style.getIconStyle().setIcon(icon);
                    placemark.setStyleSelector(style);
                    //아이콘 스타일 변경------------------------------끝
                }
                IKmlPoint point = ge.createPoint("");
                point.setLatitude(latitude);
                point.setLongitude(longitude);
                placemark.setGeometry(point);
                ge.getFeatures().appendChild(placemark);
                //아이콘 생성-----------------------------------------끝
            }
            catch (Exception ex)
            {
                System.Console.WriteLine("CreateSystemIcon Exception : " + ex.ToString());
                FileLogManager.GetInstance().WriteLog("[GEController] CreateSystemIcon( " + ex.ToString() + " )");
            }
        }
Example #4
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="origin">The first point</param>
        /// <param name="heading"></param>
        /// <param name="distance"></param>
        /// <returns></returns>
        public static IKmlPoint Destination(IKmlPoint origin, double heading, double distance)
        {
            double phi1 = origin.getLatitude().DegreesToRadians();
            double lmd1 = origin.getLongitude().DegreesToRadians();

            double sin_phi1 = Math.Sin(phi1);
            double angularDistance = distance / EARTH_RADIUS;
            double heading_rad = heading.DegreesToRadians();
            double sin_angularDistance = Math.Sin(angularDistance);
            double cos_angularDistance = Math.Cos(angularDistance);

            double phi2 =
                Math.Asin(sin_phi1 * cos_angularDistance + Math.Cos(phi1) *
                sin_angularDistance * Math.Cos(heading_rad));

            IKmlPoint result = origin;
            result.set(0, 0, 0, 0, 0, 0);
            result.setLatLng(phi2.RadiansToDegrees(),
                Math.Atan2(Math.Sin(heading_rad) * sin_angularDistance * Math.Cos(phi2),
                cos_angularDistance - sin_phi1 * Math.Sin(phi2)).RadiansToDegrees() + origin.getLongitude());

            return result;
        }
Example #5
0
        /// <summary>
        /// Calculates an intermediate point on the geodesic between the two given points 
        /// See: http://williams.best.vwh.net/avform.htm#Intermediate
        /// </summary>
        /// <param name="origin">The first point</param>
        /// <param name="destination">The second point</param>
        /// <param name="fraction">Intermediate location as a decimal fraction (T value)</param>
        /// <returns></returns>
        public static IKmlPoint IntermediatePoint(IKmlPoint origin, IKmlPoint destination, double fraction)
        {
            if (fraction > 1 || fraction < 0)
            {
                throw new ArgumentOutOfRangeException("fraction must be between 0 and 1");
            }

            // TODO: check for antipodality and fail w/ exception in that case
            double phi1 = origin.getLatitude().DegreesToRadians();
            double phi2 = destination.getLatitude().DegreesToRadians();
            double lmd1 = origin.getLongitude().DegreesToRadians();
            double lmd2 = destination.getLongitude().DegreesToRadians();

            double cos_phi1 = Math.Cos(phi1);
            double cos_phi2 = Math.Cos(phi2);
            double angularDistance = AngularDistance(origin, destination);
            double sin_angularDistance = Math.Sin(angularDistance);

            double A = Math.Sin((1 - fraction) * angularDistance) / sin_angularDistance;
            double B = Math.Sin(fraction * angularDistance) / sin_angularDistance;
            double x = A * cos_phi1 * Math.Cos(lmd1) + B * cos_phi2 * Math.Cos(lmd2);
            double y = A * cos_phi1 * Math.Sin(lmd1) + B * cos_phi2 * Math.Sin(lmd2);
            double z = A * Math.Sin(phi1) + B * Math.Sin(phi2);

            IKmlPoint result = origin;
            result.set(0, 0, 0, 0, 0, 0);
            result.setLatLng(Math.Atan2(z, Math.Sqrt(Math.Pow(x, 2) + Math.Pow(y, 2))).RadiansToDegrees(),
                Math.Atan2(y, x).RadiansToDegrees());

            return result;
        }
Example #6
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="origin"></param>
        /// <param name="destination"></param>
        /// <returns></returns>
        public static double Heading(IKmlPoint origin, IKmlPoint destination)
        {
            double phi1 = origin.getLatitude().DegreesToRadians();
            double phi2 = destination.getLatitude().DegreesToRadians();
            double cos_phi2 = Math.Cos(phi2);
            double d_lmd = (destination.getLongitude() - origin.getLongitude()).DegreesToRadians();

            return NormaliseAngle(
                Math.Atan2(Math.Sin(d_lmd) * cos_phi2,
                Math.Cos(phi1) * Math.Sin(phi2) - Math.Sin(phi1) *
                cos_phi2 * Math.Cos(d_lmd))).RadiansToDegrees();
        }
Example #7
0
        /// <summary>
        /// This function is based on the geodesy-library code by Mike Gavaghan 
        /// See http://www.gavaghan.org/blog/2007/08/06/c-gps-receivers-and-geocaching-vincentys-formula/
        /// </summary>
        /// <param name="origin">The first point</param>
        /// <param name="destination">The second point</param>
        /// <returns>The distance between the given points in metres</returns>
        public static double DistanceVincenty(IKmlPoint origin, IKmlPoint destination)
        {
            //
            // All equation numbers refer back to Vincenty's publication:
            // See http://www.ngs.noaa.gov/PUBS_LIB/inverse.pdf
            //

            // WGS84 Ellipsoid
            double a = 6378137;
            double b = 6356752.3142;
            double f = 1 / 298.257223563;

            // get parameters as radians
            double phi1 = origin.getLatitude().DegreesToRadians();
            double phi2 = destination.getLatitude().DegreesToRadians();
            double lambda1 = origin.getLongitude().DegreesToRadians();
            double lambda2 = destination.getLongitude().DegreesToRadians();

            // calculations
            double a2 = a * a;
            double b2 = b * b;
            double a2b2b2 = (a2 - b2) / b2;

            double omega = lambda2 - lambda1;

            double tanphi1 = Math.Tan(phi1);
            double tanU1 = (1.0 - f) * tanphi1;
            double U1 = Math.Atan(tanU1);
            double sinU1 = Math.Sin(U1);
            double cosU1 = Math.Cos(U1);

            double tanphi2 = Math.Tan(phi2);
            double tanU2 = (1.0 - f) * tanphi2;
            double U2 = Math.Atan(tanU2);
            double sinU2 = Math.Sin(U2);
            double cosU2 = Math.Cos(U2);

            double sinU1sinU2 = sinU1 * sinU2;
            double cosU1sinU2 = cosU1 * sinU2;
            double sinU1cosU2 = sinU1 * cosU2;
            double cosU1cosU2 = cosU1 * cosU2;

            // eq. 13
            double lambda = omega;

            // intermediates we'll need to compute 's'
            double A = 0.0;
            double B = 0.0;
            double sigma = 0.0;
            double deltasigma = 0.0;
            double lambda0;

            for (int i = 0; i < 20; i++)
            {
                lambda0 = lambda;

                double sinlambda = Math.Sin(lambda);
                double coslambda = Math.Cos(lambda);

                // eq. 14
                double sin2sigma = (cosU2 * sinlambda * cosU2 * sinlambda) + Math.Pow(cosU1sinU2 - sinU1cosU2 * coslambda, 2.0);
                double sinsigma = Math.Sqrt(sin2sigma);

                // eq. 15
                double cossigma = sinU1sinU2 + (cosU1cosU2 * coslambda);

                // eq. 16
                sigma = Math.Atan2(sinsigma, cossigma);

                // eq. 17    Careful!  sin2sigma might be almost 0!
                double sinalpha = (sin2sigma == 0) ? 0.0 : cosU1cosU2 * sinlambda / sinsigma;
                double alpha = Math.Asin(sinalpha);
                double cosalpha = Math.Cos(alpha);
                double cos2alpha = cosalpha * cosalpha;

                // eq. 18    Careful!  cos2alpha might be almost 0!
                double cos2sigmam = cos2alpha == 0.0 ? 0.0 : cossigma - 2 * sinU1sinU2 / cos2alpha;
                double u2 = cos2alpha * a2b2b2;

                double cos2sigmam2 = cos2sigmam * cos2sigmam;

                // eq. 3
                A = 1.0 + u2 / 16384 * (4096 + u2 * (-768 + u2 * (320 - 175 * u2)));

                // eq. 4
                B = u2 / 1024 * (256 + u2 * (-128 + u2 * (74 - 47 * u2)));

                // eq. 6
                deltasigma = B * sinsigma * (cos2sigmam + B / 4 * (cossigma * (-1 + 2 * cos2sigmam2) - B / 6 * cos2sigmam * (-3 + 4 * sin2sigma) * (-3 + 4 * cos2sigmam2)));

                // eq. 10
                double C = f / 16 * cos2alpha * (4 + f * (4 - 3 * cos2alpha));

                // eq. 11 (modified)
                lambda = omega + (1 - C) * f * sinalpha * (sigma + C * sinsigma * (cos2sigmam + C * cossigma * (-1 + 2 * cos2sigmam2)));

                // see how much improvement we got
                double change = Math.Abs((lambda - lambda0) / lambda);

                if ((i > 1) && (change < EPSILON))
                {
                    break;
                }
            }

            // eq. 19
            double s = b * A * (sigma - deltasigma);

            return s;
        }
Example #8
0
 /// <summary>
 /// Computes the distance between two points using the Haversine formula
 /// </summary>
 /// <param name="origin">The first point</param>
 /// <param name="destination">The second point</param>
 /// <returns>The distance between the given points in metres</returns>
 public static double DistanceHaversine(IKmlPoint origin, IKmlPoint destination)
 {
     return EARTH_RADIUS * AngularDistance(origin, destination);
 }
Example #9
0
 /// <summary>
 /// Look at the given point
 /// </summary>
 /// <param name="ge">the plugin</param>
 /// <param name="point">the point to look at</param>
 public static void LookAt(IGEPlugin ge, IKmlPoint point)
 {
     LookAt(ge, point.getLatitude(), point.getLongitude());
 }
Example #10
0
 /*This is called by the Javascript function that will show the ruler point on the map and will do the calculation of distance */
 public void createRulerPoint(IKmlPlacemark rulerPoint, IKmlPoint point)
 {
     IKmlIcon rulerPointIcon = ge.createIcon("");
     rulerPointIcon.setHref("http://maps.google.com/mapfiles/kml/shapes/placemark_square.png");
     IKmlStyle rulerPointStyle = ge.createStyle("");
     rulerPointStyle.getIconStyle().setIcon(rulerPointIcon);
     rulerPoint.setStyleSelector(rulerPointStyle);
     ruler.getFeatures().appendChild(rulerPoint);  // Add the point to the map.
     /*We will then implement the feature that will calculate the distance between the points*/
     linePoints.getCoordinates().pushLatLngAlt(point.getLatitude(), point.getLongitude(), 0);
     line.setGeometry(linePoints);
     if (pointsMeasured != 0)
     {
         //This means this is not the first point we're measuring. Hence we should find out the distance
         //The distance will be the distance measured so far, plus the distance between the last point and the current point
         rulerDistance += Math.Round(DistanceAlgorithm.DistanceBetweenPlaces(lastPoint.getLatitude(), lastPoint.getLongitude(), point.getLatitude(), point.getLongitude()), 2);
         rulerDistanceText.Text = rulerDistance.ToString() + " km";
         ++pointsMeasured;
     }
     else
     {
         ++pointsMeasured;
     }
     lastPoint = point;
 }
Example #11
0
        public Boolean insert(String tp1, String tp2)
        {
            try
            {
                // Get the end placemark of the 1st trip  and the start placemark of the second trip
                IKmlPlacemark tp1fn = t_pool.getFinish(t_pool.getByName(tp1));
                IKmlPlacemark tp2st = t_pool.getStart(t_pool.getByName(tp2));

                //create a place mark to store the new place mark

                IKmlPlacemark start  = ge.createPlacemark("");
                IKmlPlacemark finish = ge.createPlacemark("");

                start.setName(tp1fn.getName());
                finish.setName(tp2st.getName());

                IKmlPoint sp = ge.createPoint("");
                IKmlPoint fp = ge.createPoint("");

                IKmlPlacemark _temp = ge.createPlacemark("");

                IKmlLineString temp = ge.createLineString("");

                // Retrieve the coordinates of the two trips
                Hashtable cds1 = Module.getCoordinates(tp1fn);
                Hashtable cds2 = Module.getCoordinates(tp2st);

                sp.setLatLng((double)cds1["lat"], (double)cds1["lon"]);
                start.setGeometry(sp);
                fp.setLatLng((double)cds2["lat"], (double)cds2["lon"]);
                finish.setGeometry(fp);

                String color = randomCol();

                IKmlStyleMap sm        = ge.createStyleMap("");
                IKmlStyle    normal    = mkStyle(color, @"http://maps.google.com/mapfiles/kml/paddle/wht-blank.png", (float)0.3);
                IKmlStyle    highlight = mkStyle(color, @"http://maps.google.com/mapfiles/kml/paddle/wht-blank.png", (float)0.4);
                sm.setNormalStyle(normal);
                sm.setHighlightStyle(highlight);
                start.setStyleSelector(sm);
                finish.setStyleSelector(sm);

                temp.getCoordinates().pushLatLngAlt((double)cds1["lat"], (double)cds1["lon"], 0);
                temp.getCoordinates().pushLatLngAlt((double)cds2["lat"], (double)cds2["lon"], 0);
                _temp.setGeometry(temp);

                IKmlStyle sty = ge.createStyle("");
                sty.getLineStyle().setWidth((float)4);
                sty.getLineStyle().getColor().set(color);

                _temp.setStyleSelector(sty);

                //create a new KML folder for the new trip  and append the tmp features of the previous trip
                IKmlFolder temp1 = ge.createFolder("");

                temp1.getFeatures().appendChild(start);
                temp1.getFeatures().appendChild(_temp);
                temp1.getFeatures().appendChild(finish);

                String[] attributes = new String[14];

                //Add the new trip to the trip pools
                t_pool.add(tp2, temp1, attributes);
                ge.getFeatures().appendChild(temp1);

                // record the insert action for undo action
                record.ins_trip(tp2);


                return(true);
            }
            catch
            {
                return(false);
            }
        }
Example #12
0
        /// <summary>
        /// Icon을 생성하여 GEPlugin 에 Append
        /// </summary>
        /// <param name="iconInfo"></param>
        public IKmlObject CreateSystemIcon(IconInfo iconInfo)
        {
            try
            {
                if (this.ge == null)
                {
                    FileLogManager.GetInstance().WriteLog("[GEController] CreateSystemIcon2( GEPlugin is null. )");

                    throw new Exception("External Exception : GEPlugin is null.");
                }

                StringBuilder builder = new StringBuilder();
                builder.Append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
                builder.Append("<kml xmlns=\"http://www.opengis.net/kml/2.2\" xmlns:gx=\"http://www.google.com/kml/ext/2.2\"");
                builder.Append(" xmlns:kml=\"http://www.opengis.net/kml/2.2\" xmlns:atom=\"http://www.w3.org/2005/Atom\">");
                builder.Append("<Placemark id=\"");
                builder.Append("icon" + iconInfo.IconName);
                builder.Append("\">");
                builder.Append("<name></name>");
                if (iconInfo.LstExtendedData.Count > 0)
                {
                    builder.Append("<ExtendedData>");
                    foreach (KmlExtendedData extendData in iconInfo.LstExtendedData)
                    {
                        builder.Append("<Data name=\"");
                        builder.Append(extendData.DataName);
                        builder.Append("\">");
                        builder.Append("<value>");
                        builder.Append(extendData.Data);
                        builder.Append("</value>");
                        builder.Append("</Data>");
                    }
                    builder.Append("</ExtendedData>");
                }

                builder.Append("</Placemark>");
                builder.Append("</kml>");
                IKmlObject obj = ge.parseKml(builder.ToString());
                //아이콘 생성---------------------------------------시작
                IKmlPlacemark placemark = obj as IKmlPlacemark;
                placemark.setDescription(iconInfo.IconName);
                if (!string.IsNullOrEmpty(iconInfo.IconURL))
                {
                    //아이콘 스타일 변경----------------------------시작
                    IKmlIcon icon = ge.createIcon("");
                    icon.setHref(iconInfo.IconURL);
                    IKmlStyle style = ge.createStyle("");
                    style.getIconStyle().setIcon(icon);
                    placemark.setStyleSelector(style);
                    //아이콘 스타일 변경------------------------------끝
                }
                else
                {
                    //아이콘 스타일 변경----------------------------시작
                    IKmlIcon icon = ge.createIcon("");
                    icon.setHref("http://maps.google.com/mapfiles/kml/paddle/red-circle.png");
                    IKmlStyle style = ge.createStyle("");
                    style.getIconStyle().setIcon(icon);
                    placemark.setStyleSelector(style);
                    //아이콘 스타일 변경------------------------------끝
                }
                IKmlPoint point = ge.createPoint("");
                point.setLatitude(iconInfo.Latitude);
                point.setLongitude(iconInfo.Longitude);
                placemark.setGeometry(point);

                return(ge.getFeatures().appendChild(placemark));
                //아이콘 생성-----------------------------------------끝
            }
            catch (Exception ex)
            {
                System.Console.WriteLine("CreateSystemIcon2 Exception : " + ex.ToString());
                FileLogManager.GetInstance().WriteLog("[GEController] CreateSystemIcon2( GEPlugin is null. )");

                return(null);
            }
        }