예제 #1
0
        private static List <FieldCordinates> SortFieldData(List <FieldCordinates> fieldCoordRes)
        {
            var sortField      = fieldCoordRes.Where(x => (x.FieldName.ToLower()).StartsWith("field")).OrderBy(x => x.FieldName).ToList();
            var sortVenueField = fieldCoordRes.Where(x => (x.FieldName.ToLower()).StartsWith("venue")).OrderBy(x => x.FieldName).ToList();

            List <FieldCordinates> SortedFieldCoord = new List <FieldCordinates>();
            FieldCordinates        fcObj            = new FieldCordinates();

            for (int i = 1; i <= sortField.Count(); i++)
            {
                var sortedFieldData = fieldCoordRes.Where(x => x.FieldName.ToLower() == "field " + i.ToString()).OrderBy(x => x.FieldName).FirstOrDefault();
                sortedFieldData.FieldName = i.ToString();
                SortedFieldCoord.Add(sortedFieldData);
            }

            foreach (var venue in sortVenueField)
            {
                string[] fieldName;
                fieldName = venue.FieldName.Split(' ');
                string fieldNameInitial = fieldName[0].Substring(0, 1) + fieldName[1] + fieldName[3];
                venue.FieldName = fieldNameInitial;
                SortedFieldCoord.Add(venue);
            }
            return(SortedFieldCoord);
        }
예제 #2
0
        public static List <GeoCoordinateMap> MapFieldWithCoordinates(FieldCordinates fc)
        {
            string[]                lines, coords;
            GeoCoordinateMap        geoCoord     = new GeoCoordinateMap();
            List <GeoCoordinateMap> geoCoordList = new List <GeoCoordinateMap>();

            try
            {
                lines = fc.Coordinates.Split('\n');
                for (int i = 0; i < lines.Length; i++)
                {
                    geoCoord           = new GeoCoordinateMap();
                    coords             = lines[i].Split(',');
                    geoCoord.Latitude  = Convert.ToDouble(coords[1].Trim());
                    geoCoord.Longitude = Convert.ToDouble(coords[0].Trim());
                    geoCoordList.Add(geoCoord);
                }
            }
            catch (Exception ex) { }
            return(geoCoordList);
        }
예제 #3
0
        public static void GetFieldMatrix()
        {
            GetIBITestMapData();
            var    ibiMapFile = System.IO.Path.GetFullPath("IBIMapData.kml").ToString();
            string sheetName  = "Field Matrix";

            var service = CreateGoogleSheets(sheetName);

            FileStream fs = new FileStream(ibiMapFile, FileMode.Open, FileAccess.Read);

            List <FieldCordinates> fc            = new List <FieldCordinates>();
            List <FieldCordinates> fieldCoordRes = new List <FieldCordinates>();
            FieldCordinates        fcObj         = new FieldCordinates();

            try
            {
                // new xdoc instance
                XmlDocument xDoc = new XmlDocument();

                //load up the xml from the location
                xDoc.Load(fs);

                // cycle through each child noed
                XmlNodeList xmlnode;
                xmlnode = xDoc.GetElementsByTagName("Folder");
                foreach (XmlNode node in xmlnode)
                {
                    // first node is the url ... have to go to nexted loc node
                    foreach (XmlNode locNode in node)
                    {
                        // thereare a couple child nodes here so only take data from node named loc
                        if (locNode.Name == "Placemark")
                        {
                            fcObj           = new FieldCordinates();
                            fcObj.FieldName = locNode.FirstChild.InnerText.Trim();
                            // get the content of the loc node

                            if ((locNode.FirstChild.InnerText.Trim().ToLower()).IndexOf("field") != -1)
                            {
                                foreach (XmlNode childNode in locNode)
                                {
                                    //var name = childNode.GetElementsByTagName("name").ToString();
                                    //var cordinates = coordinates

                                    if (childNode.Name == "Polygon")
                                    {
                                        foreach (XmlNode cn in childNode)
                                        {
                                            foreach (XmlNode ob in cn)
                                            {
                                                foreach (XmlNode lr in ob)
                                                {
                                                    if (lr.LocalName == "coordinates")
                                                    {
                                                        fcObj.Coordinates = lr.InnerText.Trim();
                                                        fc.Add(fcObj);
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                foreach (var fieldObj in fc)
                {
                    fieldObj.latLong = MapFieldWithCoordinates(fieldObj);
                    fieldCoordRes.Add(fieldObj);
                }

                //Method to show header accordition to the dynamic data
                //FieldMatrixHeaderData(service, sheetName, fieldCoordRes);

                //The belowe method calculate distance between two fields using its coordinates
                CalculateDistanceBetweenTwoFields(SortFieldData(fieldCoordRes), service);
            }
            catch (Exception ex) { }
        }