static void Main(string[] args) { Point p = new Point(3, 4); var p2 = new Point(5, 7); // Revient à faire Point p2 = new Point(5, 7); car cela permet de racoussir var p3 = new Point(10, 4); var p4 = new Point(3, 6); Cercle c = new Cercle(p, 4); var poly = new Polygone(p, p2, p3, p4); System.Console.WriteLine(poly.CalculerPerimetre()); foreach (var item in poly) { System.Console.WriteLine(item); } for (int i = 0; i < poly.Count; i++) { System.Console.WriteLine(poly[i].ToString()); } }
private void Polygone_Button_Click(object sender, RoutedEventArgs e)//APRES AVOIR SELECTIONNER LES ELEMENTS SUR LA LISTE, ON CLICK SUR POLYGONE ET LE POLYGONE EST CONSTRUIT { Polygone gone = new Polygone(LineP, BackP); if (listBox.SelectedItems.Count <= 1) { return; } var selectedElems = listBox.SelectedItems; List <int> ListIdDelete = new List <int>(); for (int i = 0; i < listBox.SelectedItems.Count; i++) { ListIdDelete.Add((selectedElems[i] as Coordonnees).Id); gone.coord.Add(listBox.SelectedItems[i] as Coordonnees); } DrawGone(gone.coord, gone.Id, gone.Contour, gone.Remplissage); foreach (var selid in ListIdDelete) { _myMapData.ObservableCollection.Remove(_myMapData.ObservableCollection.Cast <CartoObj>().First(a => a.Id == selid)); } _myMapData.ObservableCollection.Add(gone); listBox.Items.Refresh(); }
/// <summary> /// Permet de créer un triangle. /// </summary> /// <param name="positionX"></param> /// <param name="positionY"></param> /// <param name="taille"></param> /// <returns></returns> public virtual Forme CreerTriangle(int positionX, int positionY, int taille) { Polygone f = new Polygone(new Point(positionX, positionY)); f.SetTriangle(taille); this.Canvas.Formes.Add(f); IMode.instance.Logger(f.Type + " " + f.ID + " : Création effectuée.", ConsoleColor.Green); return(f); }
/// <summary> /// Permet de créer une étoile. /// </summary> /// <param name="positionX"></param> /// <param name="positionY"></param> /// <param name="rayonInterieur"></param> /// <param name="rayonExterieur"></param> /// <param name="nbSommet"></param> /// <returns></returns> public virtual Forme CreerEtoile(int positionX, int positionY, int rayonInterieur, int rayonExterieur, int nbSommet) { Polygone f = new Polygone(new Point(positionX, positionY)); f.SetEtoile(rayonInterieur / 2, rayonExterieur / 2, nbSommet); this.Canvas.Formes.Add(f); IMode.instance.Logger(f.Type + " " + f.ID + " : Création effectuée.", ConsoleColor.Green); return(f); }
/// <summary> /// Permet de créer un rectangle. /// </summary> /// <param name="positionX"></param> /// <param name="positionY"></param> /// <param name="largeur"></param> /// <param name="hauteur"></param> /// <returns></returns> public virtual Forme CreerRectangle(int positionX, int positionY, int largeur, int hauteur) { Polygone f = new Polygone(new Point(positionX, positionY)); f.SetRectangle(largeur, hauteur); this.Canvas.Formes.Add(f); IMode.instance.Logger(f.Type + " " + f.ID + " : Création effectuée.", ConsoleColor.Green); return(f); }
private void Connexion_Click(object sender, RoutedEventArgs e) { MyPersonalMapData utilisateur = new MyPersonalMapData(NomTB.Text, PrenomTB.Text, emailTB.Text); WindowPrincipal w = new WindowPrincipal(utilisateur); Coordonnees A = new Coordonnees(40.25, 48.25); MyCartographyObjects.Polyline Poly1 = new MyCartographyObjects.Polyline(new List <Coordonnees>() { A }, 10, Color.FromArgb(255, 201, 200, 152), 1); ObservableCollection <ICartoObj> ListeTest = new ObservableCollection <ICartoObj>(); ListeTest.Add(Poly1); utilisateur.ObservableCollection = ListeTest; Coordonnees B = new Coordonnees(40.25, 48.25); Coordonnees D = new Coordonnees(3.25, 10.45); Coordonnees E = new Coordonnees(4.254, 5.2545); Polygone Polygone = new Polygone(new List <Coordonnees>() { B, D, E }, Color.FromArgb(165, 187, 195, 0), Color.FromArgb(165, 200, 140, 165), 1, 1); ListeTest.Add(Polygone); utilisateur.ObservableCollection = ListeTest; string filename = utilisateur.Nom + utilisateur.Prenom + ".dat"; if (NomTB.Text.Length < 1 || PrenomTB.Text.Length < 1 || emailTB.Text.Length < 1) { ApresConnexion.Text = "Erreur : Veuillez remplir tous les champs"; MessageBox.Show("Erreur : Veuillez remplir tous les champs"); } else { // ApresConnexion.Text = filename; if (!(File.Exists(@"C:\Users\gaetan\source\repos\CartoProject\Test\bin\Debug\" + filename))) { ApresConnexion.Text = "Utilisateur n'existe pas"; MessageBox.Show("Utilisateur n'existe pas"); utilisateur.Save(); w.Show(); this.Close(); } else { ApresConnexion.Text = "Utilisateur existe deja"; MessageBox.Show("Utilisateur existe deja"); // utilisateur.Load(); w.Show(); this.Close(); } } }
// Update is called once per frame void Update() { if (client == null) { return; } this.stream.Write(this.dataSend, 0, this.dataSend.Length); String responseData = String.Empty; int bytes = this.stream.Read(this.data, 0, this.data.Length); responseData = System.Text.Encoding.ASCII.GetString(this.data, 0, bytes); if (responseData == String.Empty) { return; } if (responseData == "ok") { stream.Close(); client.Close(); stream = null; client = null; return; } Debug.Log(responseData); robot = JsonUtility.FromJson <Robot>(responseData); //recuperer infos sur polygone surface de TC Polygone p = repTC.polygoneSurface; Debug.Log(p.liste_vecteur[1].x); Debug.Log(p.liste_vecteur[1].y); Debug.Log(p.liste_vecteur[2]); //on cree le robot represente par un carre Transform robotSimu = Instantiate(this.r, new Vector3(robot.x, 1, robot.y), transform.rotation); Renderer rend = robotSimu.GetComponent <Renderer>(); rend.material = Resources.Load <Material>("blue"); Transform TerrainCsimu = Instantiate(this.tc, transform.position, transform.rotation); float TCx = Convert.ToSingle(p.liste_vecteur[1].y); float TCz = Convert.ToSingle(p.liste_vecteur[0].x); tailleTC = new Vector3(TCx, 0, TCz); TerrainCsimu.transform.localScale = tailleTC; }
public static bool IsPointInPolygone(Point3D point, Polygone polygone) { int pointsCount = polygone.Points.Count; bool c = false; for (int i = 0, j = pointsCount - 1; i < pointsCount; j = i++) { if (((polygone.Points[i].Latitude > point.Latitude) != (polygone.Points[j].Latitude > point.Latitude)) && (point.Longitude < (polygone.Points[j].Longitude - polygone.Points[i].Longitude) * (point.Latitude - polygone.Points[i].Latitude) / (polygone.Points[j].Latitude - polygone.Points[i].Latitude) + polygone.Points[i].Longitude)) { c = !c; } } return(c); }
private void LoadCoordoonees() //CHARGE LE CONTENU DU FICHIER S'IL EXISTE { foreach (var co in _myMapData.ObservableCollection) { if ((co as Coordonnees) is var point && point != null) { Location loc = new Location(point.Latitude, point.Longitude); Pushpin pin = new Pushpin(); pin.Location = loc; pin.Tag = point.Id; MyMap.Children.Add(pin); } if (co is MyCartographyObjects.Polyline) { List <Coordonnees> c = new List <Coordonnees>(); var ac = co as MyCartographyObjects.Polyline; MyCartographyObjects.Polyline line = new MyCartographyObjects.Polyline(ac.coord, LineP); foreach (var pt in line.coord) { AddPushPin(pt); } DrawLine(line.coord, line.Id, line.Colrs); } if (co is Polygone) { List <Coordonnees> c = new List <Coordonnees>(); var ac = co as Polygone; Polygone gone = new Polygone(ac.coord, LineP, BackP); foreach (var pt in gone.coord) { AddPushPin(pt); } DrawGone(gone.coord, gone.Id, gone.Contour, gone.Remplissage); } } }
public List <Polygone> DecryptLine(string strline) { var elems = strline.Split(' '); //What is the action? int action = GetFirstDigit(strline); switch (action) { case 1: //there must be a file name at the end as it just can't be 1 point alone if (elems.Length != 15) { break; } var poly = new List <Polygone>(); //check if element is existing var ret = Loader.DatObj.Where(x => x.Name.ToLower() == elems.Last().ToLower()); if (!ret.Any()) { Console.WriteLine($"Cloning {elems.Last()}"); DatLoader ld = new DatLoader(RootPath, elems.Last(), HiQuality); poly = ld.LoadFromFile(); } else { //Clone the existing part poly = ret.First().Polygones.DeepClone <List <Polygone> >(); } Point t = new Point(float.Parse(elems[2], System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture), float.Parse(elems[3], System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture), float.Parse(elems[4], System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture)); Point m1 = new Point(float.Parse(elems[5], System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture), float.Parse(elems[6], System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture), float.Parse(elems[7], System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture)); Point m2 = new Point(float.Parse(elems[8], System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture), float.Parse(elems[9], System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture), float.Parse(elems[10], System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture)); Point m3 = new Point(float.Parse(elems[11], System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture), float.Parse(elems[12], System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture), float.Parse(elems[13], System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture)); var col = int.Parse(elems[1]); for (int i = 0; i < poly.Count; i++) { poly[i].Matrix(m1, m2, m3, t); if (poly[i].Color == 16) { poly[i].Color = col; } } return(poly); //break; case 2: //We don't need the specific lines break; case 3: //it's the standard triangle if (elems.Length != 11) { break; } Point ptc1 = new Point(float.Parse(elems[2], System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture), float.Parse(elems[3], System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture), float.Parse(elems[4], System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture)); Point ptc2 = new Point(float.Parse(elems[5], System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture), float.Parse(elems[6], System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture), float.Parse(elems[7], System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture)); Point ptc3 = new Point(float.Parse(elems[8], System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture), float.Parse(elems[9], System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture), float.Parse(elems[10], System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture)); Polygone plc = new Polygone(ptc1, ptc2, ptc3); plc.Color = int.Parse(elems[1]); return(new List <Polygone> { plc }); //break; case 4: //it's a rectangle, will need to transform into 2 triuangles if (elems.Length != 14) { break; } float a1 = float.Parse(elems[2], System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture); float a2 = float.Parse(elems[3], System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture); float a3 = float.Parse(elems[4], System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture); float b1 = float.Parse(elems[5], System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture); float b2 = float.Parse(elems[6], System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture); float b3 = float.Parse(elems[7], System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture); float c1 = float.Parse(elems[8], System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture); float c2 = float.Parse(elems[9], System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture); float c3 = float.Parse(elems[10], System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture); float d1 = float.Parse(elems[11], System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture); float d2 = float.Parse(elems[12], System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture); float d3 = float.Parse(elems[13], System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture); Polygone qq1; Polygone qq2; qq1 = new Polygone(new Point(a1, a2, a3), new Point(b1, b2, b3), new Point(c1, c2, c3)); qq2 = new Polygone(new Point(c1, c2, c3), new Point(d1, d2, d3), new Point(a1, a2, a3)); qq1.Color = int.Parse(elems[1]); qq2.Color = int.Parse(elems[1]); return(new List <Polygone> { qq1, qq2 }); //break; case 5: //As for case 2, there is no need of converting hidden lines break; case 0: //check if it is a part as we'll save it at the end if (elems.Length > 3) { if (elems[1] == @"!LDRAW_ORG") { if (elems[2].ToLower() == @"part") { IsPart = true; } } } break; default: break; } return(new List <Polygone>()); }
public override void LoadFromFile(string filename) { System.IO.StreamReader FileText = new System.IO.StreamReader(filename); string TempLine; List <string> DataStrings = new List <string>(); bool DataBegin = false; Name = Path.GetFileNameWithoutExtension(filename); while ((TempLine = FileText.ReadLine()) != null) { TempLine = TempLine.ToLower(); if ((DataBegin == true) && (TempLine != "")) { DataStrings.Add(TempLine); } if (TempLine == "data") { DataBegin = true; } } List <string> SeparatorArray; char[] SeparatorSymbols = new char[] { ',', ' ', '(', ')' }; char[] SeparatorSymbolsCoord = new char[] { ' ', '(', ')' }; for (int i = 0; i < DataStrings.Count; i++) { SeparatorArray = (DataStrings[i].Split(SeparatorSymbolsCoord)).ToList(); Split(SeparatorArray); double x, y, z; if (SeparatorArray.Count > 0) { switch (SeparatorArray[0]) { case "point": ConvertPointInCorrectFormat(SeparatorArray); x = double.Parse(SeparatorArray[1].Replace('.', ',')); y = double.Parse(SeparatorArray[2].Replace('.', ',')); z = double.Parse(SeparatorArray[3].Replace('.', ',')); Point point = new Point(x, y, z); CountHeightAndConvert(point); AddObject(point); break; case "line": double x1, y1; x = double.Parse(SeparatorArray[1].Replace('.', ',')); y = double.Parse(SeparatorArray[2].Replace('.', ',')); x1 = double.Parse(SeparatorArray[3].Replace('.', ',')); y1 = double.Parse(SeparatorArray[4].Replace('.', ',')); Line line = new Line(new GeoPoint(x, y), new GeoPoint(x1, y1)); if ((i + 1) < DataStrings.Count) { SeparatorArray = (DataStrings[i + 1].Split(SeparatorSymbols)).ToList(); Split(SeparatorArray); if (SeparatorArray[0] == "pen") { i++; line.Style.Fatness = int.Parse(SeparatorArray[1]); line.Style.Type = int.Parse(SeparatorArray[2]); int Colour = int.Parse(SeparatorArray[3]); line.Style.LColour = System.Drawing.Color.FromArgb((Colour & 0xFF0000) / 65536, (Colour & 0xFF00) / 256, (Colour & 0xFF)); } } AddObject(line); break; case "pline": i++; SeparatorArray = (DataStrings[i].Split(SeparatorSymbols)).ToList(); Split(SeparatorArray); int count = int.Parse(SeparatorArray[0]); PolyLine ponyline = new PolyLine(); for (int k = 0; k < count; k++) { i++; SeparatorArray = (DataStrings[i].Split(SeparatorSymbolsCoord)).ToList(); Split(SeparatorArray); x = double.Parse(SeparatorArray[0].Replace('.', ',')); y = double.Parse(SeparatorArray[1].Replace('.', ',')); ponyline.AddNode(new GeoPoint(x, y)); if ((i + 1) < DataStrings.Count && (k == count - 1)) { SeparatorArray = (DataStrings[i + 1].Split(SeparatorSymbols)).ToList(); Split(SeparatorArray); if (SeparatorArray[0] == "pen") { i++; ponyline.Style.Fatness = int.Parse(SeparatorArray[1]); ponyline.Style.Type = int.Parse(SeparatorArray[2]); int Colour = int.Parse(SeparatorArray[3]); ponyline.Style.LColour = System.Drawing.Color.FromArgb((Colour & 0xFF0000) / 65536, (Colour & 0xFF00) / 256, (Colour & 0xFF)); } } AddObject(ponyline); } break; case "region": i++; SeparatorArray = (DataStrings[i].Split(SeparatorSymbols)).ToList(); Split(SeparatorArray); count = int.Parse(SeparatorArray[0]); Polygone ponygnya = new Polygone(); for (int k = 0; k < count; k++) { i++; SeparatorArray = (DataStrings[i].Split(SeparatorSymbolsCoord)).ToList(); Split(SeparatorArray); x = double.Parse(SeparatorArray[0].Replace('.', ',')); y = double.Parse(SeparatorArray[1].Replace('.', ',')); ponygnya.AddNode(new GeoPoint(x, y)); if ((i + 1) < DataStrings.Count && (k == count - 1)) { SeparatorArray = (DataStrings[i + 1].Split(SeparatorSymbols)).ToList(); Split(SeparatorArray); if (SeparatorArray[0] == "pen") { i++; ponygnya.Style.Fatness = int.Parse(SeparatorArray[1]); ponygnya.Style.Type = int.Parse(SeparatorArray[2]); int Colour = int.Parse(SeparatorArray[3]); ponygnya.Style.LColour = System.Drawing.Color.FromArgb((Colour & 0xFF0000) / 65536, (Colour & 0xFF00) / 256, (Colour & 0xFF)); } } if ((i + 1) < DataStrings.Count && (k == count - 1)) { SeparatorArray = (DataStrings[i + 1].Split(SeparatorSymbols)).ToList(); Split(SeparatorArray); if (SeparatorArray.Count > 0) { if (SeparatorArray[0] == "brush") { i++; int Colour = int.Parse(SeparatorArray[2]); ponygnya.Brush.Color = System.Drawing.Color.FromArgb((Colour & 0xFF0000) / 65536, (Colour & 0xFF00) / 256, (Colour & 0xFF)); } } } } AddObject(ponygnya); break; default: break; } } } }
private void InsertGolfStore(MallBuddyApi.Models.ApplicationDbContext context) { try { var golf = new Store { Name = "GOLF", Type = POI.POIType.STORE, Anchor = new Point3D(), Schedule = new List <Models.existing.OpeningHoursSpan>(), Enabled = true, WebsiteLink = "http://www.dizengof-center.co.il/GOLF.aspx", ImageUrl = "http://www.dizengof-center.co.il/manage-pages/uploaded-files/a_03-07-2011-15-37-5.jpg", Location = new Polygone(), ContactDetails = new ContactDetails { PoiName = "GOLF", Phone1 = "03-5283163", Address = "www.golf.co.il" }, //Category = "Fashion", }; var schedule1 = new List <OpeningHoursSpan>(); var weekday = new OpeningHoursSpan { day = DayOfWeek.Sunday, from = 10, to = 2130 }; var friday = new OpeningHoursSpan { day = DayOfWeek.Friday, from = 0930, to = 1530 }; var saturday = new OpeningHoursSpan { day = DayOfWeek.Saturday, from = 20, to = 2230 }; schedule1.Add(weekday); schedule1.Add(friday); schedule1.Add(saturday); golf.Schedule = schedule1; Polygone poly = new Polygone { Accessible = true, Areas = new List <Area> { new Area { AreaID = "0401" }, new Area { AreaID = "0401A" } }, Wkt = "POLYGON ((34.775053932498516 32.07540339193275,34.77499915806167 32.07548404017222,34.77497984348338 32.07549149508553, 34.774953825764996 32.07549049106811,34.774935077805786 32.07547970303128,34.77491144862596 32.07545506831342,34.77490455271353 32.07544820193738, 34.77489280495869 32.075426482513976, 34.774889877466975 32.07541821355505,34.774886213457535 32.07540786423455,34.77488379926684 32.075401045136886,34.774871958289275 32.07534718017001,34.77487191400818 32.0752896316811,34.77492920795574 32.075324825765655,34.775053932498516 32.07540339193275,34.775053932498516 32.07540339193275))", LocationG = DbGeometry.PolygonFromText("POLYGON ((34.775053932498516 32.07540339193275,34.77499915806167 32.07548404017222,34.77497984348338 32.07549149508553, 34.774953825764996 32.07549049106811,34.774935077805786 32.07547970303128,34.77491144862596 32.07545506831342,34.77490455271353 32.07544820193738, 34.77489280495869 32.075426482513976, 34.774889877466975 32.07541821355505,34.774886213457535 32.07540786423455,34.77488379926684 32.075401045136886,34.774871958289275 32.07534718017001,34.77487191400818 32.0752896316811,34.77492920795574 32.075324825765655,34.775053932498516 32.07540339193275,34.775053932498516 32.07540339193275))", 4326), Points = new List <Point3D>() }; var Point3D1 = new Point3D { Level = 2, Longitude = 34.775053932498516m, Latitude = 32.07540339193275m, Wkt = "POINT(34.775053932498516 32.07540339193275)", LocationG = DbGeometry.PointFromText("POINT(34.775053932498516 32.07540339193275)", 4326) }; var Point3D2 = new Point3D { Level = 2, Longitude = 34.77499915806167m, Latitude = 32.07548404017222m, Wkt = "POINT(34.77499915806167 32.07548404017222)", LocationG = DbGeometry.PointFromText("POINT(34.77499915806167 32.07548404017222)", 4326) }; var Point3D3 = new Point3D { Level = 2, Longitude = 34.77497984348338m, Latitude = 32.07549149508553m, Wkt = "POINT(34.77497984348338 32.07549149508553)", LocationG = DbGeometry.PointFromText("POINT(34.77497984348338 32.07549149508553)", 4326) }; var Point3D4 = new Point3D { Level = 2, Longitude = 34.774953825764996m, Latitude = 32.07549049106811m, Wkt = "POINT(34.774953825764996 32.07549049106811)", LocationG = DbGeometry.PointFromText("POINT(34.774953825764996 32.07549049106811)", 4326) }; poly.Points.Add(Point3D1); poly.Points.Add(Point3D2); poly.Points.Add(Point3D3); poly.Points.Add(Point3D4); golf.Location = poly; context.Stores.AddOrUpdate(golf); //context. SaveChanges(context); } catch (DbEntityValidationException e) { foreach (var eve in e.EntityValidationErrors) { Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State); foreach (var ve in eve.ValidationErrors) { Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage); } } throw; } }
private static void extractPolygon(JObject feature, Dictionary <string, Point3D> labeledPoints, ApplicationDbContext context , List <Point3D> badPolygonsPoints, List <POI> poisToSave) { POI poi = new POI(); poi.Type = null; Polygone toReturn = new Polygone(); toReturn.Points = new List <Point3D>(); int level = int.Parse(feature["properties"]["level"].ToString()); //bool isAccessible = Boolean.Parse(feature["properties"]["accessible"].ToString()); toReturn.Level = level; StringBuilder wktsb = new StringBuilder("POLYGON (("); List <Point3D> labeledPointsFound = new List <Point3D>(); foreach (JArray j in feature["geometry"]["coordinates"][0]) { StringBuilder pointWkt = new StringBuilder("POINT ("); string lon = Regex.Match(j.ToString(), "34\\.\\d+").Value; string lat = Regex.Match(j.ToString(), "32\\.\\d+").Value; wktsb.Append(lon + " " + lat + ","); pointWkt.Append(lon + " " + lat + ")"); if (!toReturn.Points.Exists(Point3D => Point3D.Wkt == pointWkt.ToString())) { if (labeledPoints.ContainsKey(pointWkt.ToString())) { labeledPointsFound.Add(labeledPoints[pointWkt.ToString()]); toReturn.Points.Add(labeledPoints[pointWkt.ToString()]); //break; } else { DbGeometry pointG = DbGeometry.PointFromText(pointWkt.ToString(), 4326); Point3D point = new Point3D { Longitude = Decimal.Parse(lon), Latitude = Decimal.Parse(lat), Wkt = pointWkt.ToString(), LocationG = pointG, Level = level }; toReturn.Points.Add(point); } } } wktsb.Remove(wktsb.Length - 1, 1); wktsb.Append("))"); toReturn.Wkt = wktsb.ToString(); try { DbGeometry polygone = DbGeometry.PolygonFromText(wktsb.ToString(), 4326); if (!polygone.IsValid) { polygone = DbGeometry.FromText(SqlGeometry.STGeomFromText(new SqlChars(polygone.AsText()), 4326).MakeValid().STAsText().ToSqlString().ToString(), 4326); } foreach (Point3D point in badPolygonsPoints) { if (polygone.Contains(point.LocationG)) { return; } } toReturn.LocationG = polygone; } catch (Exception ex) { ex = ex; } // polygon with no info if (labeledPointsFound.Count == 0) { return; } // polygon with more than one anchor point - check if it is 2 entrances if (labeledPointsFound.Count > 1) { if (labeledPointsFound[0].Areas.Count != labeledPointsFound[1].Areas.Count) { return; } else { for (int i = 0; i < labeledPointsFound[0].Areas.Count; i++) { if (!labeledPointsFound[0].Areas[i].AreaID.Equals(labeledPointsFound[1].Areas[i].AreaID)) { return; } } } } Point3D labeledPoint = labeledPointsFound[0]; if (labeledPoint != null) { toReturn.Areas = labeledPoint.Areas; if (labeledPoint.Areas != null && labeledPoint.Areas.Count > 0 && !labeledPoint.Areas[0].AreaID.StartsWith("9")) { poi.Type = POI.POIType.STORE; } if (labeledPoint.Name.ToLower().Contains("atm")) { poi.Type = POI.POIType.ATM; } if (labeledPoint.Name.ToLower().Contains("entrance")) { poi.Type = POI.POIType.ENTRANCE; } if (labeledPoint.Name.ToLower().Contains("toilet") | labeledPoint.Name.ToLower().Contains("wc")) { poi.Type = POI.POIType.WC; } if (labeledPoint.Name.ToLower().Contains("zone")) { poi.Type = POI.POIType.ZONE; } } if (poi.Type != null) { switch (poi.Type) { case POI.POIType.STORE: { poi = new Store { Type = poi.Type, Anchor = labeledPoint, Enabled = true , Floor = level, IsAccessible = labeledPoint.IsAccessible, Name = labeledPoint.Name, Name2 = labeledPoint.Name2, Location = toReturn, Entrances = new List <Point3D>() }; foreach (Point3D entrancePoint in labeledPointsFound) { ((Store)poi).Entrances.Add(entrancePoint); } //context.Stores.AddOrUpdate(new Store[] { (Store)poi }); break; } default: { poi = new POI { Type = poi.Type, Anchor = labeledPoint, Enabled = true, Name = labeledPoint.Name, Location = toReturn }; //poisToSave.Add(poi); break; } } poisToSave.Add(poi); } //return poi; }
private void ListBox1_SelectionChange(object sender, SelectionChangedEventArgs e) { /* if(ListBox1.SelectedItem is Polyline) * { * Polyline P = new Polyline(); * P = (Polyline)ListBox1.SelectedItem; * CouleurContour.Content = P.Couleur; * Epaisseur.Content = P.Epaisseur; * * MapPolyline polyline = new MapPolyline(); * * * polyline.Stroke = new SolidColorBrush(P.Couleur); * polyline.StrokeThickness = 5; * polyline.Opacity = 0.7; * polyline.Locations = new LocationCollection() { * new Location(50.611182, 5.509222), new Location(50.609452, 5.509943),new Location(50.609866, 5.507116) }; * * MyMap.Children.Add(polyline); * * }*/ if (ListBox1.SelectedItem is Polyline) { MyMap.Children.Clear(); Polyline P = new Polyline(); P = (Polyline)ListBox1.SelectedItem; CouleurContour.Content = P.Couleur; Epaisseur.Content = P.Epaisseur; CouleurRemplissage.Content = ""; Opacite.Content = ""; Description.Content = ""; MapPolyline polyline = new MapPolyline(); polyline.Stroke = new SolidColorBrush(P.Couleur); polyline.StrokeThickness = 5; polyline.Opacity = 0.7; polyline.Locations = new LocationCollection() { new Location(50.611182, 5.509222), new Location(50.609452, 5.509943), new Location(50.609866, 5.507116) }; MyMap.Children.Add(polyline); } if (ListBox1.SelectedItem is POI) { MyMap.Children.Clear(); POI Point = new POI(); Point = (POI)ListBox1.SelectedItem; // MyMap.TryViewportPointToLocation() Location l = new Location { Latitude = Point.latitude, Longitude = Point.longitude }; Description.Content = Point.Description; CouleurContour.Content = ""; CouleurRemplissage.Content = ""; Opacite.Content = ""; Epaisseur.Content = ""; Pushpin Pushin = new Pushpin(); Pushin.SetValue(MapLayer.PositionProperty, l); this.MyMap.Children.Add(Pushin); } if (ListBox1.SelectedItem is MyCartographyObjects.Polygone) { CouleurContour.BorderThickness = new Thickness(0.8); Epaisseur.BorderThickness = new Thickness(0); CouleurRemplissage.BorderThickness = new Thickness(0.8); Opacite.BorderThickness = new Thickness(0.8); MyMap.Children.Clear(); Polygone P = new Polygone(); P = (Polygone)ListBox1.SelectedItem; CouleurContour.Content = P.CouleurContourString; CouleurRemplissage.Content = P.CouleurRemplissageString; Opacite.Content = P.Opacite; Epaisseur.Content = ""; Description.Content = ""; MapPolygon polygon = new MapPolygon(); polygon.Fill = new SolidColorBrush(P.Contour); polygon.Stroke = new SolidColorBrush(P.Remplissage); polygon.StrokeThickness = 5; polygon.Opacity = P.Opacite; polygon.Locations = new LocationCollection(); foreach (Coordonnees item in P.Liste) { polygon.Locations.Add(new Location(item.latitude, item.longitude)); } MyMap.Children.Add(polygon); } }
public HttpResponseMessage PostPOI([FromBody] string content) //(POI poi) { JsonSerializerSettings settings = new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.All }; POI poi = null; try { poi = JsonConvert.DeserializeObject <Store>(content, settings); poi.Type = POI.POIType.STORE; if (((Store)poi).ContactDetails != null && ((Store)poi).ContactDetails.PoiName == null) { ((Store)poi).ContactDetails.PoiName = poi.Name; } } catch (Exception) { try { poi = JsonConvert.DeserializeObject <POI>(content, settings); } catch (Exception) { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } } if (!ModelState.IsValid) { return(Request.CreateResponse(HttpStatusCode.BadRequest, ModelState)); } poi.Modified = DateTime.Now; if (poi.Location != null) { if (poi.Location.Id > 0) { Polygone foundP = db.Polygones.Find(poi.Location.Id); if (foundP == null) { foundP = db.Polygones.First(x => x.Wkt == poi.Location.Wkt && x.Level == poi.Location.Level); if (foundP != null) { db.Entry <Polygone>(foundP).State = EntityState.Modified; } } } } POI found = db.POIs.FirstOrDefault(x => x.Name == poi.Name && x.Location.Level == poi.Location.Level && x.Location.Wkt == poi.Location.Wkt); if (found == null) { switch (poi.Type) { case POI.POIType.STORE: { db.Stores.Add(new Store(poi)); break; } default: { db.POIs.Add(poi); break; } } //if (db.Entry<POI>(poi).State == EntityState.Detached) //{ // //EFSet.Attach(updatedEntity); // db.POIs.Attach(poi); //} //else //{ // //EFContext.Entry<TEntity>(updatedEntity).CurrentValues.SetValues(entity); // db.Entry(poi).CurrentValues.SetValues(poi); //} //db.Entry<POI>(poi).State = EntityState.Modified; } else { if (db.Entry <POI>(poi).State == EntityState.Detached) { //EFSet.Attach(updatedEntity); db.POIs.Attach(poi); } else { //EFContext.Entry<TEntity>(updatedEntity).CurrentValues.SetValues(entity); db.Entry(poi).CurrentValues.SetValues(poi); } db.Entry <POI>(poi).State = EntityState.Modified; } //POI existing = db.POIs.SingleOrDefault(x => x.DbID == poi.DbID); //db.POIs.Add(poi); try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { var context = ((IObjectContextAdapter)db).ObjectContext; context.Refresh(System.Data.Entity.Core.Objects.RefreshMode.StoreWins, poi); db.SaveChanges(); } //return CreatedAtRoute("GetPOIById", new { id = poi.DbID }, poi); return(Request.CreateResponse(HttpStatusCode.Created, poi)); //var response = Request.CreateResponse<POI>(HttpStatusCode.Created, poi); ////Request.Properties.controller.Request.Properties.Add(HttpPropertyKeys.HttpRouteDataKey, routeData); //string uri = Url.Link("GetPOIById", new { id = poi.DbID }); ////string uri = Url.Link("DefaultApi", new { id = poi.DbID }); //response.Headers.Location = new Uri(uri); //return response; }
public static void Main(string[] args) { Console.WriteLine("************COORDONNEES************\n"); Coordonnees A = new Coordonnees(40.25, 48.25); Coordonnees B = new Coordonnees(2.25, 12.25); Coordonnees C = new Coordonnees(3.45, 50.45); Coordonnees D = new Coordonnees(3.25, 10.45); Coordonnees Z = new Coordonnees(5.2, 11); A.latitude = 41.2; Console.WriteLine(A.ToString()); Console.WriteLine(C.ToString()); Console.WriteLine("\n**************POI**************\n"); POI E = new POI(); POI F = new POI("ici", 25.2, 1.25); POI Y = new POI("ok", 14, 2); Console.WriteLine(E.ToString()); Console.WriteLine(F.ToString()); Console.WriteLine("\n**************** Polyline******************\n"); Polyline Poly1 = new Polyline(new List <Coordonnees>() { A, D, Y }, 10, Color.FromArgb(255, 255, 255, 255), 1); Polyline Poly2 = new Polyline(new List <Coordonnees>() { E, F }, 15, Color.FromArgb(0, 0, 0, 0), 1); Polyline Poly3 = new Polyline(new List <Coordonnees>() { Z, A }, 11, Color.FromArgb(254, 0, 211, 0), 0); Polyline Poly4 = new Polyline(new List <Coordonnees>() { Z, B }, 11, Color.FromArgb(254, 158, 251, 0), 0); Console.WriteLine(Poly1.ToString()); Console.WriteLine(Poly2.ToString()); Console.WriteLine("\n**************Polygone**********************\n"); Polygone Polygone = new Polygone(new List <Coordonnees>() { A, D, E }, Color.FromArgb(165, 187, 195, 0), Color.FromArgb(165, 200, 140, 165), 1, 1); Polygone P5 = new Polygone(); Console.WriteLine(Polygone.ToString()); Console.WriteLine(P5.ToString()); Console.WriteLine("\n******************Liste CartObj********************\n"); List <CartoObj> ListeCart = new List <CartoObj>(); ListeCart.Add(A); ListeCart.Add(E); ListeCart.Add(F); ListeCart.Add(Poly1); ListeCart.Add(Poly2); //Afficher la liste ListeCart.ForEach(item => Console.WriteLine(item)); //Afficher ceux qui utilise ipointy Console.Write("\n****************On affiche ceux qui utilise IPOINTY*************\n"); foreach (CartoObj item in ListeCart) { if (!(item is IPointy)) { item.Draw(); } } Console.Write("\n****************On affiche ceux qui n'utilise pas IPOINTY*************\n"); foreach (CartoObj item in ListeCart) { if (item is IPointy) { item.Draw(); } } Console.WriteLine("\n****************Cree une liste de 5 polyline***********************\n"); List <Polyline> Polyliste = new List <Polyline>(); Polyliste.Add(Poly1); Polyliste.Add(Poly2); Polyliste.Add(Poly3); Polyliste.Add(Poly4); foreach (Polyline item in Polyliste) { Console.WriteLine(item.ToString()); } Polyliste.Sort(); Console.WriteLine("\n*************************** On Affiche la liste polyline triee -> longueur********************"); foreach (Polyline item in Polyliste) { Console.WriteLine(item.ToString()); } Console.WriteLine("\n*************************** On Affiche la liste polyline triee -> AIR Box********************"); MyPolylineBoundingBoxComparer Compare = new MyPolylineBoundingBoxComparer(); Polyliste.Sort(Compare); foreach (Polyline item in Polyliste) { Console.WriteLine(item.ToString()); } Console.WriteLine("\n******************Nombre de point Different Dans poly 1 : **************************"); int point = Poly1.NbPoints; Console.WriteLine("il y a : " + point + "point(s) différent"); Console.WriteLine("\n**************** Utilisation de IPointCLose*************"); Polyline P = Polyliste.Find(i => i.IsPointClose(25.2, 71, 1) == 1); //recherche dans la liste un element qui correspont if (P == null) // il ne sera pas proche { Console.WriteLine("Le point n'est pas proche."); } else { Console.WriteLine("Le point est proche ===>"); P.Draw(); } Polyline P2 = Polyliste.Find(i => i.IsPointClose(41.2, 48, 1) == 1); //recherche dans la liste un element qui correspont if (P2 == null) // il sera proche de la coordonnee A { Console.WriteLine("Le point n'est pas proche."); } else { Console.WriteLine("Le point est proche ===>"); P2.Draw(); } Console.WriteLine("\n*********************Test Longueur*******************\n"); double longueur = Poly1.LongueurPoly(); Console.WriteLine("Voici la longueur: " + longueur); Polyline PP = Polyliste.Find(i => i.LongueurPoly() == longueur); if (PP == null) { Console.WriteLine("Aucun point ne correspond a cette longueur"); } else { PP.Draw(); } Console.WriteLine("TestLoad et Save"); ObservableCollection <ICartoObj> ListeTest = new ObservableCollection <ICartoObj>(); ListeTest.Add(Poly1); MyPersonalMapData user = new MyPersonalMapData("Dresse", "Amarige", "email1"); user.ObservableCollection = ListeTest; user.Save(); Console.ReadKey(); }
/// <summary> /// liest die Daten in <see cref="polygone"/> ein /// </summary> /// <param name="br"></param> /// <param name="bRelaxed"></param> void Decode_PolygoneData(BinaryReaderWriter br, bool bRelaxed) { if (PolygoneTableBlock.Count > 0) { StringBuilder sb = new StringBuilder(); // Tabelle für Typen und Offsets zu den eigentlichen Daten einlesen PolygonTableItems = new List <TableItem>(); br.Seek(PolygoneTableBlock.Offset); for (int i = 0; i < PolygoneTableBlock.Count; i++) { PolygonTableItems.Add(new TableItem(br, PolygoneTableBlock.Recordsize)); } // Draworder-Tabelle einlesen PolygonDraworderTableItems = new List <PolygonDraworderTableItem>(); uint iLevel = 1; br.Seek(PolygoneDraworderTableBlock.Offset); int blocklen = (int)PolygoneDraworderTableBlock.Length; if (blocklen > 0) { while (blocklen >= PolygoneDraworderTableBlock.Recordsize) { PolygonDraworderTableItem dro = new PolygonDraworderTableItem(br, PolygoneDraworderTableBlock.Recordsize, iLevel); blocklen -= PolygoneDraworderTableBlock.Recordsize; PolygonDraworderTableItems.Add(dro); if (dro.Type == 0) // nächster Level { iLevel++; } } } // Tabelle der Polygondaten einlesen polygone.Clear(); for (int i = 0; i < PolygonTableItems.Count; i++) { br.Seek(PolygonTableItems[i].Offset + PolygoneDatablock.Offset); int datalen = i < PolygonTableItems.Count - 1 ? PolygonTableItems[i + 1].Offset - PolygonTableItems[i].Offset : (int)PolygoneTableBlock.Offset - (PolygonTableItems[i].Offset + (int)PolygoneDatablock.Offset); try { long startpos = br.Position; Polygone p = new Polygone(PolygonTableItems[i].Type, PolygonTableItems[i].Subtype); p.Read(br); Debug.WriteLineIf(startpos + datalen != br.Position, string.Format("Diff. {0} der Datenlänge beim Lesen des Objektes 0x{1:x} 0x{2:x} (größer 0 bedeutet: zuviel gelesen)", br.Position - (startpos + datalen), PolygonTableItems[i].Type, PolygonTableItems[i].Subtype)); // zugehörige Draworder suchen for (int j = 0; j < PolygonDraworderTableItems.Count; j++) { if (p.Type == PolygonDraworderTableItems[j].Type) // Haupttyp gefunden { for (int k = 0; k < PolygonDraworderTableItems[j].Subtypes.Count; k++) { if (p.Subtype == PolygonDraworderTableItems[j].Subtypes[k]) // auch Subtyp gefunden { p.Draworder = PolygonDraworderTableItems[j].Level; j = PolygonDraworderTableItems.Count; // 2. Schleifenabbruch break; } } } } polygone.Add(p, 0); } catch (Exception ex) { if (bRelaxed) { sb.AppendFormat("Fehler beim Einlesen von Polygon 0x{0:x2}, 0x{1:x2}: {2}", PolygonTableItems[i].Type, PolygonTableItems[i].Subtype, ex.Message); sb.AppendLine(); } else { throw new Exception(ex.Message); } } } if (bRelaxed) { RelaxedModeErrors += sb.ToString(); } } }
/// <summary> /// Transforme une détection de balise en triangle /// </summary> /// <returns>Triangle correspondant à la détection</returns> public Polygone ToPolygone() { List<PointReel> listePoints = new List<PointReel>(); // Point de la balise double xPoint1 = Balise.Position.Coordonnees.X; double yPoint1 = Balise.Position.Coordonnees.Y; PointReel point = new PointReel(xPoint1, yPoint1); listePoints.Add(point); // Point du côté du début de l'angle // 5000 valeur arbitraire, assez grande pour dépasser de la table xPoint1 = Balise.Position.Coordonnees.X + Math.Cos(Maths.DegreeToRadian(AngleDebut)) * 5000; yPoint1 = Balise.Position.Coordonnees.Y + Math.Sin(Maths.DegreeToRadian(AngleDebut)) * 5000; point = new PointReel(xPoint1, yPoint1); listePoints.Add(point); // Point du côté du début de l'angle xPoint1 = Balise.Position.Coordonnees.X + Math.Cos(Maths.DegreeToRadian(AngleFin)) * 5000; yPoint1 = Balise.Position.Coordonnees.Y + Math.Sin(Maths.DegreeToRadian(AngleFin)) * 5000; point = new PointReel(xPoint1, yPoint1); listePoints.Add(point); Polygone polygone = new Polygone(listePoints); return polygone; }
private static void DessinerForme(Graphics graphics, Color color, int epaisseur, Polygone polygone, bool plein = false, bool realToScreen = true) { if (polygone.Cotes.Count == 0) return; Point[] listePoints = new Point[polygone.Cotes.Count + 1]; listePoints[0] = realToScreen ? RealToScreenPosition(polygone.Cotes[0].Debut) : (Point)polygone.Cotes[0].Debut; for (int i = 0; i < polygone.Cotes.Count; i++) { Segment s = polygone.Cotes[i]; listePoints[i] = realToScreen ? RealToScreenPosition(s.Fin) : (Point)s.Fin; } listePoints[listePoints.Length - 1] = listePoints[0]; if (!plein) using (Pen pen = new Pen(color, epaisseur)) graphics.DrawPolygon(pen, listePoints); else using (SolidBrush brush = new SolidBrush(color)) graphics.FillPolygon(brush, listePoints, System.Drawing.Drawing2D.FillMode.Winding); }