Beispiel #1
0
        public void AddCoordinates(List <coordinate> coords)
        {
            // Reset Coords
            Coords.Clear();

            // Add each Site
            foreach (var coord in coords)
            {
                _coord c = new _coord();
                c.id      = coord.ID;
                c.placeId = coord.idPlaceInMap;
                double.TryParse(coord.longitude, out c._x);
                double.TryParse(coord.latitude, out c._y);
                c.x = coord.longitude.ToString();
                c.y = coord.latitude.ToString();
                // add to Coords
                Coords.Add(c);

                // Adjust Site's Coord List
                _site site = getSite(coord.idPlaceInMap);
                // assert site is valid
                //Debug.Assert(site != null);
                site.coords.Add(c);
            }

            // prepare Json String for Coordinations
            prepare_Coord_JsonString();
        }
Beispiel #2
0
        private void checkBoundary(_coord c)
        {
            if (_leftTop == null)
            {
                _leftTop     = new _coord();
                _rightBottom = new _coord();

                _leftTop._x     = c._x;
                _leftTop._y     = c._y;
                _rightBottom._x = c._x;
                _rightBottom._y = c._y;
            }
            else
            {
                _leftTop._x     = c._x < _leftTop._x ? c._x : _leftTop._x;
                _leftTop._y     = c._y < _leftTop._y ? c._y : _leftTop._y;
                _rightBottom._x = c._x > _rightBottom._x ? c._x : _rightBottom._x;
                _rightBottom._y = c._y > _rightBottom._y ? c._y : _rightBottom._y;
            }
        }
Beispiel #3
0
        private void checkBoundary(_coord c)
        {
            if (_leftTop == null)
            {
                _leftTop = new _coord();
                _rightBottom = new _coord();

                _leftTop._x = c._x;
                _leftTop._y = c._y;
                _rightBottom._x = c._x;
                _rightBottom._y = c._y;
            }
            else
            {
                _leftTop._x = c._x < _leftTop._x ? c._x : _leftTop._x;
                _leftTop._y = c._y < _leftTop._y ? c._y : _leftTop._y;
                _rightBottom._x = c._x > _rightBottom._x ? c._x : _rightBottom._x;
                _rightBottom._y = c._y > _rightBottom._y ? c._y : _rightBottom._y;
            }
        }
Beispiel #4
0
        public void AddCoordinates(List<coordinate> coords)
        {
            // Reset Coords
            Coords.Clear();

            // Add each Site
            foreach (var coord in coords)
            {
                _coord c = new _coord();
                c.id = coord.ID;
                c.placeId = coord.idPlaceInMap;
                double.TryParse(coord.longitude, out c._x);
                double.TryParse(coord.latitude, out c._y);
                c.x = coord.longitude.ToString();
                c.y = coord.latitude.ToString();
                // add to Coords
                Coords.Add(c);

                // Adjust Site's Coord List
                _site site = getSite(coord.idPlaceInMap);
                // assert site is valid
                //Debug.Assert(site != null);
                site.coords.Add(c);
            }

            // prepare Json String for Coordinations
            prepare_Coord_JsonString();
        }
Beispiel #5
0
        public void Parse(XDocument xDoc, long eventId)
        {
            // reset data lists
            polys.Reset();

            // get Root Namespace
            string xNs = "{" + xDoc.Root.Name.Namespace.ToString() + "}";

            // style parsing
            var styleList = from s in xDoc.Descendants(xNs + "Style")
                            select s;

            foreach (var i in styleList)
            {
                _style newStyle = new _style();
                newStyle.styleUrl = "#" + i.Attribute("id").Value;
                newStyle.eventId = eventId;
                newStyle.label_color = i.Element(xNs + "LabelStyle").Element(xNs + "color").Value;
                newStyle.line_color = i.Element(xNs + "LineStyle").Element(xNs + "color").Value;
                newStyle.poly_color = i.Element(xNs + "PolyStyle").Element(xNs + "color").Value;

                polys.Styles.Add(newStyle);
            }

            // _site parsing
            var coordsStr = from f in xDoc.Descendants(xNs + "Placemark")
                                // where elementToFind.Contains(f.Parent.Element(xNs + "name").Value + f.Element(xNs + "name").Value)
                                //select f.Element(xNs + "LineString").Element(xNs + "coordinates");
                            select f;
            int siteID = 1;
            foreach (var i in coordsStr)
            {
                var y = i.Element(xNs + "MultiGeometry").Descendants(xNs + "Polygon").Descendants(xNs + "outerBoundaryIs").Descendants(xNs + "LinearRing").Descendants(xNs + "coordinates");
                char[] delemeters = { ',', ' ' };
                // create new site
                _site newSite = new _site();
                newSite.style = polys.GetStyle(i.Element(xNs + "styleUrl").Value);
                newSite.styleUrl = newSite.style.styleUrl;
                newSite.eventId = eventId;
                newSite.id = siteID++;
                newSite.name = i.Element(xNs + "name").Value;
                newSite.tag = i.Attribute("id").Value;
                var tmpCoords = y.ElementAt(0).Value.ToString().TrimStart().Split(delemeters).ToList();
                while (tmpCoords.Remove("0"))
                    ;

                // assert even count 
                Debug.Assert((tmpCoords.Count % 2) == 0);

                for (int j = 0; j < tmpCoords.Count; j += 2)
                {
                    _coord c = new _coord();
                    c._x = double.Parse(tmpCoords[j]);
                    c._y = double.Parse(tmpCoords[j + 1]);
                    c.x = tmpCoords[j];
                    c.y = tmpCoords[j + 1];
                    c.placeId = newSite.id;
                    c.eventId = eventId;
                    c.seqCoordinate = (j / 2) + 1;
                    c.siteTag = newSite.tag;
                    newSite.coords.Add(c);
                    polys.Coords.Add(c);
                }

                polys.Sites.Add(newSite);
                // style site count add
                newSite.style.siteCount++;
            }
            Console.WriteLine(coordsStr.Count());

        }
Beispiel #6
0
        public void Parse(XDocument xDoc, long eventId)
        {
            // reset data lists
            polys.Reset();

            // get Root Namespace
            string xNs = "{" + xDoc.Root.Name.Namespace.ToString() + "}";

            // style parsing
            var styleList = from s in xDoc.Descendants(xNs + "Style")
                            select s;

            foreach (var i in styleList)
            {
                _style newStyle = new _style();
                newStyle.styleUrl    = "#" + i.Attribute("id").Value;
                newStyle.eventId     = eventId;
                newStyle.label_color = i.Element(xNs + "LabelStyle").Element(xNs + "color").Value;
                newStyle.line_color  = i.Element(xNs + "LineStyle").Element(xNs + "color").Value;
                newStyle.poly_color  = i.Element(xNs + "PolyStyle").Element(xNs + "color").Value;

                polys.Styles.Add(newStyle);
            }

            // _site parsing
            var coordsStr = from f in xDoc.Descendants(xNs + "Placemark")
                            // where elementToFind.Contains(f.Parent.Element(xNs + "name").Value + f.Element(xNs + "name").Value)
                            //select f.Element(xNs + "LineString").Element(xNs + "coordinates");
                            select f;
            int siteID = 1;

            foreach (var i in coordsStr)
            {
                var    y          = i.Element(xNs + "MultiGeometry").Descendants(xNs + "Polygon").Descendants(xNs + "outerBoundaryIs").Descendants(xNs + "LinearRing").Descendants(xNs + "coordinates");
                char[] delemeters = { ',', ' ' };
                // create new site
                _site newSite = new _site();
                newSite.style    = polys.GetStyle(i.Element(xNs + "styleUrl").Value);
                newSite.styleUrl = newSite.style.styleUrl;
                newSite.eventId  = eventId;
                newSite.id       = siteID++;
                newSite.name     = i.Element(xNs + "name").Value;
                newSite.tag      = i.Attribute("id").Value;
                var tmpCoords = y.ElementAt(0).Value.ToString().TrimStart().Split(delemeters).ToList();
                while (tmpCoords.Remove("0"))
                {
                    ;
                }

                // assert even count
                Debug.Assert((tmpCoords.Count % 2) == 0);

                for (int j = 0; j < tmpCoords.Count; j += 2)
                {
                    _coord c = new _coord();
                    c._x            = double.Parse(tmpCoords[j]);
                    c._y            = double.Parse(tmpCoords[j + 1]);
                    c.x             = tmpCoords[j];
                    c.y             = tmpCoords[j + 1];
                    c.placeId       = newSite.id;
                    c.eventId       = eventId;
                    c.seqCoordinate = (j / 2) + 1;
                    c.siteTag       = newSite.tag;
                    newSite.coords.Add(c);
                    polys.Coords.Add(c);
                }

                polys.Sites.Add(newSite);
                // style site count add
                newSite.style.siteCount++;
            }
            Console.WriteLine(coordsStr.Count());
        }