private void connectAllFloors(List <Point3D> pointsToConnect, List <LineStringDTO> lineStrings, List <Point3D> pathPoints, Dictionary <string, Point3D> pillarPoints) { for (int i = 0; i < pointsToConnect.Count; i++) { //JObject jobjectSource = pointsToConnect[i]; Point3D source = pointsToConnect[i]; //source = extractPoint(0, jobjectSource, null, Point3D.PointType.PATH_POINT); if (!pathPoints.Contains(source)) { pathPoints.Add(source); } for (int j = i + 1; j < pointsToConnect.Count; j++) { LineStringDTO toAdd = new LineStringDTO(); //JObject jobjectTarget = pointsToConnect[j]; Point3D target = pointsToConnect[j]; //target = extractPoint(0, jobjectTarget, null, Point3D.PointType.PATH_POINT); if (!pathPoints.Contains(target)) { pathPoints.Add(target); } toAdd.Source = source; toAdd.Target = target; toAdd.Wkt = "LINESTRING(" + source.Longitude + " " + source.Latitude + "," + target.Longitude + " " + target.Latitude + ")"; toAdd.LocationG = DbGeometry.LineFromText(toAdd.Wkt, 4326); toAdd.BiDirectional = true; toAdd.Distance = GeoUtils.GetHaversineDistance(source, target); toAdd.Level = source.Level; toAdd.setConnectorType(); lineStrings.Add(toAdd); } pillarPoints.Remove(source.Name); } }
private void connectPOIsToPaths(Dictionary <string, Point3D> labeledPoints, List <LineStringDTO> paths, List <Point3D> pathPoints) { foreach (var item in labeledPoints.Values) { if (item.Name.ToLower().Contains("level")) { continue; } double minToSource = double.MaxValue; Point3D closestSource = null; foreach (Point3D pointFromAll in pathPoints) { if (item.Equals(pointFromAll) | item.Level != pointFromAll.Level) { continue; } double toSource = GeoUtils.GetHaversineDistance(pointFromAll, item); if (toSource < minToSource) { minToSource = toSource; closestSource = pointFromAll; } } LineStringDTO pointToNearestPath = new LineStringDTO { Level = item.Level, Source = closestSource, Target = item, Distance = minToSource, Name = "Edge To " + item.Name, }; pointToNearestPath.setWktAndLocationG(); paths.Add(pointToNearestPath); } }
private RoutingPath getRoutingPathFromDataGraphItems(ApplicationDbContext db, Point3D source, Point3D target, IEnumerable <GraphDataItem> result, bool isAllEdges) { RoutingPath toReturn = new RoutingPath { Routingsteps = new List <RoutingStep>(), Source = source, Destination = target }; foreach (var step in result) { Point3D from = null; LineStringDTO ls = db.LineStrings.ToList().Where(x => x.Id == step.EdgeID).FirstOrDefault(); RoutingStep next = new RoutingStep(); if (ls != null) { // if (ls.connectorType != ConnectorType.PATH) // System.Diagnostics.Debugger.Break(); next = ls.toGeneric().toRoutingStep(); } if (step.SourceVertexID == source.Id | step.SourceVertexID == target.Id) { //step.EdgeID == sourceToNearestPath.Id ? lineDTO = sourceToNearestPath.toDTO() : lineDTO = targetToNearestPath.toDTO(); from = step.SourceVertexID == source.Id ? source : target; } else { from = db.Points.Find(step.SourceVertexID); } Point3D to = null; if (step.TargetVertexID == source.Id | step.TargetVertexID == target.Id) { //step.EdgeID == sourceToNearestPath.Id ? lineDTO = sourceToNearestPath.toDTO() : lineDTO = targetToNearestPath.toDTO(); to = step.TargetVertexID == source.Id ? source : target; } else { to = db.Points.Find(step.TargetVertexID); } //Point3D to = db.Points.Find(step.TargetVertexID); //Point3D from = pathPoints.Where(x => x.Id == step.TargetVertexID).FirstOrDefault(); //Point3D to = pathPoints.Where(x=>x.Id == step.TargetVertexID).FirstOrDefault(); if (from == null | to == null) { System.Diagnostics.Debugger.Break(); } //LineStringDTO lineDTO = null; //if (step.EdgeID == sourceToNearestPath.Id | step.EdgeID == targetToNearestPath.Id) //{ // //step.EdgeID == sourceToNearestPath.Id ? lineDTO = sourceToNearestPath.toDTO() : lineDTO = targetToNearestPath.toDTO(); // lineDTO = step.EdgeID == sourceToNearestPath.Id ? sourceToNearestPath.toDTO() : targetToNearestPath.toDTO(); //} //else // lineDTO = db.LineStrings.Find(step.EdgeID); //totalPath2.Routingsteps.Add(lineDTO.toGeneric().toRoutingStep()); //RoutingStep next = null; if (toReturn.Routingsteps.Count == 0) { if (step.SourceVertexID == source.Id) { next.setSourceTargetDistance(from, to, step.Cost); } else if (step.TargetVertexID == source.Id) { next.setSourceTargetDistance(to, from, step.Cost); } else if (isAllEdges) { next.setSourceTargetDistance(from, to, step.Cost); } } else { if (step.SourceVertexID == toReturn.Routingsteps[toReturn.Routingsteps.Count - 1].Destination.Id) { next.setSourceTargetDistance(from, to, step.Cost); } else if (step.TargetVertexID == toReturn.Routingsteps[toReturn.Routingsteps.Count - 1].Destination.Id) { next.setSourceTargetDistance(to, from, step.Cost); } else if (isAllEdges) { next.setSourceTargetDistance(from, to, step.Cost); } } toReturn.Routingsteps.Add(next); toReturn.Distance += step.Cost; } return(toReturn); }
private void extractLineString(JObject feature, List <LineStringDTO> lineStrings, List <Point3D> pathPoints, Dictionary <string, Point3D> labeledPoints) { LineStringDTO toAdd = new LineStringDTO(); int level = int.Parse(feature["properties"]["level"].ToString()); //bool isAccessible = Boolean.Parse(feature["properties"]["accessible"].ToString()); toAdd.Level = level; if (feature["properties"]["attrs"]["name"] != null) { toAdd.Name = feature["properties"]["attrs"]["name"].ToString(); } StringBuilder wktsb = new StringBuilder("LINESTRING ("); //List<Point3D> labeledPointsFound = new List<Point3D>(); //Point3D source = new Point3D(); //Point3D target = new Point3D(); int i = 0; foreach (JArray j in feature["geometry"]["coordinates"]) { 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 + ")"); Point3D current = null; if (labeledPoints.ContainsKey(pointWkt.ToString())) { current = labeledPoints[pointWkt.ToString()]; current.Type = Point3D.PointType.PATH_POINT; if (!pathPoints.Contains(current)) { pathPoints.Add(current); } } if (current == null) { current = pathPoints.Find(x => x.Wkt == pointWkt.ToString() && x.Level == level); } else { current = current; } if (current == null) { current = new Point3D(); //current = i == 0 ? source : target; current.Latitude = Decimal.Parse(lat); current.Longitude = Decimal.Parse(lon); current.Wkt = pointWkt.ToString(); current.LocationG = DbGeometry.PointFromText(current.Wkt, 4326); current.Level = level; current.Type = Point3D.PointType.PATH_POINT; pathPoints.Add(current); } else { i = i; } if (i == 0) { toAdd.Source = current; } if (i == 1) { toAdd.Target = current; } i++; } wktsb.Remove(wktsb.Length - 1, 1); wktsb.Append(")"); toAdd.Wkt = wktsb.ToString(); toAdd.LocationG = DbGeometry.LineFromText(toAdd.Wkt, 4326); toAdd.Distance = GeoUtils.GetHaversineDistance(toAdd.Source, toAdd.Target); toAdd.BiDirectional = true; //if (toAdd.Target.Longitude == 34.7745353108864M) // Debugger.Break(); toAdd.setConnectorType(); lineStrings.Add(toAdd); }
private void getAdjacentLevelsConnectors(Dictionary <string, Point3D> pillarPoints, List <LineStringDTO> lineStrings, List <Point3D> pathPoints) { HashSet <string> pillarPOintsUsed = new HashSet <string>(); List <string> pillarsList = pillarPoints.Keys.ToList(); foreach (string name in pillarsList) { //if (name == "2-3BRamp") // Debugger.Break(); if (!pillarPoints.ContainsKey(name)) { continue; } //JObject j = pillarPoints[name]; Point3D source = pillarPoints[name]; //source = extractPoint(0, j, null, Point3D.PointType.PATH_POINT); if (source.Name.Length < 3) { continue; } if (pathPoints.Contains(source)) { source = pathPoints.Find(x => x == source); source.Name = name; } else { pathPoints.Add(source); } char startlevel = source.Name[0]; char endlevel = source.Name[2]; string destname = source.Name.Remove(0, 1).Insert(0, endlevel.ToString()).Remove(2, 1).Insert(2, startlevel.ToString()); if (!pillarPoints.ContainsKey(destname)) { continue; } LineStringDTO toAdd = new LineStringDTO(); //j = pillarPoints[destname]; Point3D target = pillarPoints[destname]; //target = extractPoint(0, j, null, Point3D.PointType.PATH_POINT); if (pathPoints.Contains(target)) { target = pathPoints.Find(x => x == target); target.Name = destname; target.Type = Point3D.PointType.LEVEL_CONNECTION; } else { pathPoints.Add(target); } toAdd.Source = source; toAdd.Target = target; toAdd.Wkt = "LINESTRING(" + source.Longitude + " " + source.Latitude + "," + target.Longitude + " " + target.Latitude + ")"; toAdd.LocationG = DbGeometry.LineFromText(toAdd.Wkt, 4326); toAdd.Distance = GeoUtils.GetHaversineDistance(source, target); toAdd.Level = source.Level; if (source.Name.Contains("Esc")) { if (source.Name.Contains("EscBi")) { toAdd.BiDirectional = true; } else { toAdd.BiDirectional = false; } } toAdd.setConnectorType(); lineStrings.Add(toAdd); pillarPoints.Remove(name); pillarPoints.Remove(destname); } }