public override bool Contains(DbGeometry geometryValue, DbGeometry otherGeometry) { if (geometryValue == null) { throw new ArgumentNullException("geometryValue"); } if (otherGeometry == null) { throw new ArgumentNullException("otherGeometry"); } DbGeometry mysqlValue = DbGeometry.FromText(geometryValue.ProviderValue.ToString()); return(mysqlValue.Contains(otherGeometry)); }
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; }