public OSMListWithPaths(GH_Structure <GH_String> tagsTree) { items = new List <OSMTag>(); pathsPerItem = new Dictionary <OSMTag, List <GH_Path> >(); GH_Path tagPath; List <GH_String> itemsInPath; GH_String tagString; OSMTag osmItem; // Convert from tree of strings representing tags to linear list of OSM Items for (int pathIndex = 0; pathIndex < tagsTree.Paths.Count; pathIndex++) { tagPath = tagsTree.Paths[pathIndex]; itemsInPath = tagsTree[tagPath]; for (int tagIndex = 0; tagIndex < itemsInPath.Count; tagIndex++) { // Make new item and track the path it came from tagString = itemsInPath[tagIndex]; osmItem = new OSMTag(tagString.Value); if (osmItem != null) { AddItem(osmItem, ref items, ref pathsPerItem); pathsPerItem[osmItem].Add(tagPath); AddItem(osmItem.Key, ref items, ref pathsPerItem); pathsPerItem[osmItem.Key].Add(tagPath); } } } }
protected static int CountWaysForMetaData(RequestHandler results, OSMTag request) { var allResults = results.FoundData[request]; var nodeResults = allResults.Where(o => o.Kind == OSMGeometryType.Way); return(nodeResults.Count()); }
static void ShowFilterForm() { var mockTags = new TreeGridItemCollection(); var parentA = new OSMTag("website"); var itemA = new OSMTreeGridItem(parentA, 0, 0, false, false); var AChildA = new OSMTreeGridItem(new OSMTag("website=http://www.google.com"), 1, 2, true, false); itemA.Children.Add(AChildA); var AChildB = new OSMTreeGridItem(new OSMTag("website=http://www.test.com"), 1, 2, true, false); itemA.Children.Add(AChildB); mockTags.Add(itemA); var parentB = new OSMTag("height"); var itemB = new OSMTreeGridItem(parentB, 0, 0, false, false); var BChildA = new OSMTreeGridItem(new OSMTag("height=10"), 2, 2, true, false); itemB.Children.Add(BChildA); var BChildB = new OSMTreeGridItem(new OSMTag("height=5"), 1, 1, true, false); itemB.Children.Add(BChildB); var CChildC = new OSMTreeGridItem(new OSMTag("height=11"), 3, 3, true, false); itemB.Children.Add(CChildC); var BChildD = new OSMTreeGridItem(new OSMTag("height=2"), 3, 3, true, false); itemB.Children.Add(BChildD); var CChildE = new OSMTreeGridItem(new OSMTag("height=20"), 3, 3, true, false); itemB.Children.Add(CChildE); mockTags.Add(itemB); new Application(Eto.Platforms.Wpf).Run(new FilterTagsForm(mockTags, HideObscure)); }
public void ParseNodesGivenDoubleKeyViaXMLReader() { var queryA = new OSMTag("addr:street", "Swanston Street"); var test = new ParseRequest(new List <OSMTag>() { queryA }); var results = fetchResultsViaXMLReader(OSMXMLs, test, OSMGeometryType.Node); Assert.AreEqual(2, CountNodesForMetaData(results, queryA)); var queryB = new List <string>() { "addr:street=Swanston Street" }; test = new ParseRequest(queryB); results = fetchResultsViaXMLReader(OSMXMLs, test, OSMGeometryType.Node); Assert.AreEqual(2, CountNodesForMetaData(results, queryA)); var queryC = new List <string>() { "addr:street=swanston street" }; test = new ParseRequest(queryC); results = fetchResultsViaXMLReader(OSMXMLs, test, OSMGeometryType.Node); Assert.AreEqual(2, CountNodesForMetaData(results, queryA)); }
static void GenerateOsmFiles(List <Bucket> buckets, PathReconstructer reconstructor, OSMDB map, List <GPXTrack> gpxTrackList) { foreach (var b in buckets) { if (b.Paths.Any()) { var mapCopy = ObjectCopier.Clone <OSMDB>(map); List <Polyline <IPointGeo> > pathList = new List <Polyline <IPointGeo> >(); OSMNode bucketInfo = new OSMNode(0, 0, 0); OSMTag start = new OSMTag("start", b.Start.ToString()); OSMTag end = new OSMTag("end", b.End.ToString()); bucketInfo.Tags.Add(start); bucketInfo.Tags.Add(end); foreach (var p in b.Paths) { var uniquePath = p.Value.GroupBy(x => new { x.Id }).Select(x => x.First()); foreach (var seg in uniquePath) { if (seg.Id != 0) { var matchingWay = mapCopy.Ways[seg.Id]; var avgSpeed = getAverageSpeed(p.Key, gpxTrackList); if (avgSpeed != null) { if (matchingWay.Tags.ContainsTag("avgSpeed")) { matchingWay.Tags["avgSpeed"].Value = avgSpeed; } else { matchingWay.Tags.Add(new OSMTag("avgSpeed", avgSpeed)); } } if (matchingWay.Tags.ContainsTag("traffic")) { matchingWay.Tags["traffic"].Value += "," + p.Key; } else { matchingWay.Tags.Add(new OSMTag("traffic", p.Key)); } } } pathList.AddRange(uniquePath); } //OSMDB resultMap = reconstructor.SaveToOSM(pathList); //resultMap.Save("map" + b.Name + ".osm"); mapCopy.Nodes.Add(bucketInfo); mapCopy.Save("map" + b.Name + ".osm"); } } }
private void AddItem(OSMTag item, ref List <OSMTag> items, ref Dictionary <OSMTag, List <GH_Path> > pathsPerItem) { if (!pathsPerItem.ContainsKey(item)) { items.Add(item); pathsPerItem[item] = new List <GH_Path>(); } }
public void TestKeyValueParsingA() // E.g. defined subfeatures without a primary feature { var miscA = new OSMTag("capacity=charging"); Assert.AreEqual(miscA.ToString(), "capacity=charging"); Assert.AreEqual(miscA.IsParent(), false); Assert.AreEqual(miscA.Key.ToString(), "capacity=*"); Assert.AreEqual(miscA.Key.IsParent(), true); }
private void AddItems(IEnumerable <string> tags, ref List <OSMTag> itemList) { foreach (string tagName in tags) { var tagData = new OSMTag(tagName); itemList.Add(tagData); if (!itemList.Contains(tagData.Key)) { itemList.Add(tagData.Key); } } }
} // Coming from already-parsed tag lists; not a predefined list public OSMTreeGridItem(OSMTag osmItem, int nodeCount, int wayCount, bool showCounts, bool selected, bool expanded = false) { osmItem.NodeCount = nodeCount; osmItem.WayCount = wayCount; OSMData = osmItem; Expanded = expanded; IsParsed = showCounts; IsObscure = GetObscurity(); // Defined features; Values = this.GetColumnData(selected); }
public override sealed bool Equals(object obj) { if (this == obj) { return(true); } else if (!(obj is OSMTag)) { return(false); } OSMTag other = (OSMTag)obj; return(this.id == other.id); }
public void TestKeyValueParsingC() { var websiteParentA = new OSMTag("website"); var websiteChildA = new OSMTag("website=http://www.google.com"); var websiteChildB = new OSMTag("website", "http://www.google.com"); foreach (var item in new List <OSMTag> { websiteChildA, websiteChildB }) { Assert.AreEqual(item.ToString(), "website=http://www.google.com"); Assert.AreEqual(item.Key, websiteParentA); } }
public void TestPrimaryKeyParsing() // E.g. those defined in OSMDefinedFeatures at Primary lvl { var highwaysParentA = new OSMTag("highway"); var highwaysParentB = new OSMTag("highway=*"); var highwaysParentC = new OSMTag("highway", ""); var highwaysParentD = new OSMTag("highway", "Highway", "Roads", null); foreach (var item in new List <OSMTag> { highwaysParentA, highwaysParentB, highwaysParentC, highwaysParentD }) { Assert.AreEqual(item.ToString(), "highway=*"); Assert.AreEqual(item.IsParent(), true); Assert.AreNotEqual(item.Description, ""); } }
public void TestKeyValueParsingB() { var websiteParentA = new OSMTag("website"); var websiteParentB = new OSMTag("website=*"); var websiteParentC = new OSMTag("website", "*"); foreach (var item in new List <OSMTag> { websiteParentA, websiteParentB, websiteParentC }) { Assert.AreEqual(item.ToString(), "website=*"); Assert.AreEqual(item.Name, "Website"); Assert.AreEqual(item.Key, null); Assert.AreNotEqual(item.Description, ""); } }
/// <param name="tagSet"> /// the tag set </param> /// <returns> the minimum zoom level of all tags in the tag set </returns> public sbyte getZoomAppearPOI(short[] tagSet) { if (tagSet == null || tagSet.Length == 0) { return(sbyte.MaxValue); } TShortHashSet tmp = new TShortHashSet(tagSet); if (this.poiZoomOverrides.Count > 0) { foreach (short s in tagSet) { ISet <OSMTag> overriddenTags = this.poiZoomOverrides[Convert.ToInt16(s)]; if (overriddenTags != null) { foreach (OSMTag osmTag in overriddenTags) { tmp.remove(osmTag.Id); } } } if (tmp.Empty) { StringBuilder sb = new StringBuilder(); foreach (short s in tagSet) { sb.Append(this.idToPoiTag[Convert.ToInt16(s)].tagKey() + "; "); } LOGGER.severe("ERROR: You have a cycle in your zoom-override definitions. Look for these tags: " + sb.ToString()); } } sbyte zoomAppear = sbyte.MaxValue; foreach (short s in tmp.toArray()) { OSMTag tag = this.idToPoiTag[Convert.ToInt16(s)]; if (tag.Renderable) { zoomAppear = (sbyte)Math.Min(zoomAppear, tag.ZoomAppear); } } return(zoomAppear); }
public void TestKeyParsing() // E.g. those defined in MiscFeatures at Primary lvl { var randomA = new OSMTag("rental"); Assert.AreEqual(randomA.ToString(), "rental=*"); var randomB = new OSMTag("passenger"); Assert.AreEqual(randomB.ToString(), "passenger=*"); foreach (var item in new List <OSMTag> { randomA, randomB }) { Assert.AreEqual(item.IsParent(), true); } }
/// <summary> /// Extracts known way tags and returns their ids. /// </summary> /// <param name="entity"> /// the way </param> /// <returns> the ids of the identified tags </returns> public static short[] extractKnownWayTags(Entity entity) { TShortArrayList currentTags = new TShortArrayList(); OSMTagMapping mapping = OSMTagMapping.Instance; if (entity.Tags != null) { foreach (Tag tag in entity.Tags) { OSMTag wayTag = mapping.getWayTag(tag.Key, tag.Value); if (wayTag != null) { currentTags.add(wayTag.Id); } } } return(currentTags.toArray()); }
public void ParseWaysGivenDoubleKeyViaXMLReader() { var query = new OSMTag("addr:street", "Swanston Street"); var test = new ParseRequest(new List <OSMTag>() { query }); var results = fetchResultsViaXMLReader(OSMXMLs, test, OSMGeometryType.Way); Assert.AreEqual(2, CountWaysForMetaData(results, query)); var rawQuery = new List <string>() { "addr:street=Swanston Street" }; test = new ParseRequest(rawQuery); results = fetchResultsViaXMLReader(OSMXMLs, test, OSMGeometryType.Way); Assert.AreEqual(2, CountWaysForMetaData(results, query)); }
/// <param name="histogram"> /// a histogram that represents the frequencies of tags </param> public void optimizeWayOrdering(TShortIntHashMap histogram) { this.optimizedWayIds.Clear(); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final java.util.TreeSet<HistogramEntry> wayOrdering = new java.util.TreeSet<>(); SortedSet <HistogramEntry> wayOrdering = new SortedSet <HistogramEntry>(); histogram.forEachEntry(new TShortIntProcedureAnonymousInnerClassHelper2(this, wayOrdering)); short tmpWayID = 0; OSMTag currentTag = null; foreach (HistogramEntry histogramEntry in wayOrdering.descendingSet()) { currentTag = this.idToWayTag[Convert.ToInt16(histogramEntry.id)]; this.optimizedWayIds[Convert.ToInt16(histogramEntry.id)] = Convert.ToInt16(tmpWayID); LOGGER.finer("adding way tag: " + currentTag.tagKey() + " id:" + tmpWayID + " amount: " + histogramEntry.amount); tmpWayID++; } }
public void TestPrimaryKeyValueParsing() // E.g. defined subfeatures with a primary feature { var highwaysParentA = new OSMTag("highway"); var highwaysChildA = new OSMTag("highway=residential"); Assert.IsTrue(highwaysChildA.WayCount > 0); var highwaysChildB = new OSMTag("highway", "residential"); Assert.IsTrue(highwaysChildB.WayCount > 0); var highwaysChildC = new OSMTag("residential", "Highway", "Roads", highwaysParentA); foreach (var item in new List <OSMTag> { highwaysChildA, highwaysChildB, highwaysChildC }) { Assert.AreEqual(item.ToString(), "highway=residential"); Assert.AreEqual(item.IsParent(), false); Assert.AreNotEqual(item.Description, ""); Assert.AreEqual(item.Key, highwaysParentA); } }
public void TestKeyValueParsingD() { var height = new OSMTag("height"); Assert.AreNotEqual(height.Description, ""); }
protected override void CaribouSolveInstance(IGH_DataAccess da) { logger.Reset(); #region Input Parsing da.GetDataTree(0, out GH_Structure <IGH_Goo> itemsTree); if (itemsTree.Branches[0][0] as IGH_GeometricGoo == null) { this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "It looks like you have provided a non-geometry input to the Items parameter. This input should connect to the Nodes, Ways, or Buildings outputs produced by the Extract components."); return; } ProvidedNodes = itemsTree.Branches[0][0] is GH_Point; da.GetDataTree(1, out GH_Structure <GH_String> tagsTree); if (tagsTree.Branches[0].Count >= 3) { if (tagsTree.Branches[0][2].ToString().Contains(" found")) { this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "It looks like you have provided a Report parameter output as the Tag parameter input. Use a Tag parameter output instead."); return; } } if (itemsTree.PathCount != tagsTree.PathCount) { this.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "The path counts of the Items and Tags do not match - check these are coming from the same component."); } else if (itemsTree.Branches.Count != tagsTree.Branches.Count) { this.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "The branch structure of the Items and Tags do not match - check these are coming from the same component."); } logger.NoteTiming("Input capture"); #endregion #region Form Data Setup // Setup form-presentable items for tags provided and parsed into OSM objects var requests = new OSMListWithPaths(tagsTree); // Parse provided tree into OSM objects and a dictionary of paths per object logger.NoteTiming("Tag parsing"); // If tags have changed we write out current state so we can try to preserve it in the new tags list if (this.PreviousTagsDescription != null) { if (tagsTree.DataDescription(false, false) != this.PreviousTagsDescription) { this.storedSelectionState = GetStateKeys(); } } // If loading from scratch, or if the tags have changed if (this.storedSelectionState != null) { var availableOSMs = GetSelectableTagsFromInputTree(requests); this.selectableOSMs = TreeGridUtilities.SetSelectionsFromStoredState( availableOSMs, this.storedSelectionState); this.storedSelectionState = null; // Reset flag } else { this.selectableOSMs = GetSelectableTagsFromInputTree(requests); } this.PreviousTagsDescription = tagsTree.DataDescription(false, false); // Track tag input identity this.selectionStateSerialized = GetSelectedKeyValuesFromForm(); logger.NoteTiming("State loading/making"); #endregion #region Outputting // Match geometry paths to selected filters var geometryOutput = new GH_Structure <IGH_Goo>(); var tagOutput = new GH_Structure <GH_String>(); // Setup tracking dictionary for the report tree output var foundItemCountsForResult = new Dictionary <OSMTag, int>(); for (int i = 0; i < this.selectionStateSerialized.Count; i++) { string itemKeyValue = this.selectionStateSerialized[i]; OSMTag osmItem = new OSMTag(itemKeyValue); if (!requests.pathsPerItem.ContainsKey(osmItem)) { continue; } foundItemCountsForResult[osmItem] = 0; // Match keyvalues to OSMListwithpaths for (int j = 0; j < requests.pathsPerItem[osmItem].Count; j++) { GH_Path inputPath = requests.pathsPerItem[osmItem][j]; var geometryItemsForPath = itemsTree.get_Branch(inputPath); var tagItemsForPath = tagsTree.get_Branch(inputPath); if (geometryItemsForPath == null) { continue; // No provided geometry path for that OSM item } foundItemCountsForResult[osmItem] += 1; for (int k = 0; k < geometryItemsForPath.Count; k++) { GH_Path outputPathFor = new GH_Path(i, j); geometryOutput.EnsurePath(outputPathFor); // Need to ensure even an empty path exists to enable data matching tagOutput.EnsurePath(outputPathFor); // Need to ensure even an empty path exists to enable data matching geometryOutput.Append(geometryItemsForPath[k] as IGH_Goo, outputPathFor); foreach (GH_String tag in tagItemsForPath) { tagOutput.Append(tag, outputPathFor); } } } } logger.NoteTiming("Geometry matching"); var requestReport = TreeFormatters.MakeReportForRequests(foundItemCountsForResult); logger.NoteTiming("Tree formatting"); this.OutputMessageBelowComponent(); da.SetDataTree(0, geometryOutput); da.SetDataTree(1, tagOutput); da.SetDataTree(2, requestReport); logger.NoteTiming("Data tree setting"); #endregion }
// /** // * @param tags // * the tags // * @return // */ // private static short[] tagIDsFromList(List<OSMTag> tags) { // short[] tagIDs = new short[tags.size()]; // int i = 0; // for (OSMTag tag : tags) { // tagIDs[i++] = tag.getId(); // } // // return tagIDs; // } /// <param name="key"> /// the key </param> /// <param name="value"> /// the value </param> /// <returns> the corresponding <seealso cref="OSMTag"/> </returns> public OSMTag getWayTag(string key, string value) { return(this.stringToWayTag[OSMTag.tagKey(key, value)]); }
private OSMTagMapping(URL tagConf) { try { sbyte defaultZoomAppear; // ---- Parse XML file ---- DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); Document document = builder.parse(tagConf.openStream()); XPath xpath = XPathFactory.newInstance().newXPath(); XPathExpression xe = xpath.compile(XPATH_EXPRESSION_DEFAULT_ZOOM); defaultZoomAppear = sbyte.Parse((string)xe.evaluate(document, XPathConstants.STRING)); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final java.util.HashMap<Nullable<short>, java.util.Set<String>> tmpPoiZoomOverrides = new java.util.HashMap<>(); Dictionary <short?, ISet <string> > tmpPoiZoomOverrides = new Dictionary <short?, ISet <string> >(); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final java.util.HashMap<Nullable<short>, java.util.Set<String>> tmpWayZoomOverrides = new java.util.HashMap<>(); Dictionary <short?, ISet <string> > tmpWayZoomOverrides = new Dictionary <short?, ISet <string> >(); // ---- Get list of poi nodes ---- xe = xpath.compile(XPATH_EXPRESSION_POIS); NodeList pois = (NodeList)xe.evaluate(document, XPathConstants.NODESET); for (int i = 0; i < pois.Length; i++) { NamedNodeMap attributes = pois.item(i).Attributes; string key = attributes.getNamedItem("key").TextContent; string value = attributes.getNamedItem("value").TextContent; string[] equivalentValues = null; if (attributes.getNamedItem("equivalent-values") != null) { equivalentValues = attributes.getNamedItem("equivalent-values").TextContent.Split(","); } sbyte zoom = attributes.getNamedItem("zoom-appear") == null ? defaultZoomAppear : sbyte.Parse(attributes.getNamedItem("zoom-appear").TextContent); bool renderable = attributes.getNamedItem("renderable") == null ? true : bool.Parse(attributes.getNamedItem("renderable").TextContent); bool forcePolygonLine = attributes.getNamedItem("force-polygon-line") == null ? false : bool.Parse(attributes.getNamedItem("force-polygon-line").TextContent); OSMTag osmTag = new OSMTag(this.poiID, key, value, zoom, renderable, forcePolygonLine); if (this.stringToPoiTag.ContainsKey(osmTag.tagKey())) { LOGGER.warning("duplicate osm-tag found in tag-mapping configuration (ignoring): " + osmTag); continue; } LOGGER.finest("adding poi: " + osmTag); this.stringToPoiTag[osmTag.tagKey()] = osmTag; if (equivalentValues != null) { foreach (string equivalentValue in equivalentValues) { this.stringToPoiTag[OSMTag.tagKey(key, equivalentValue)] = osmTag; } } this.idToPoiTag[Convert.ToInt16(this.poiID)] = osmTag; // also fill optimization mapping with identity this.optimizedPoiIds[Convert.ToInt16(this.poiID)] = Convert.ToInt16(this.poiID); // check if this tag overrides the zoom level spec of another tag NodeList zoomOverrideNodes = pois.item(i).ChildNodes; for (int j = 0; j < zoomOverrideNodes.Length; j++) { Node overriddenNode = zoomOverrideNodes.item(j); if (overriddenNode is Element) { string keyOverridden = overriddenNode.Attributes.getNamedItem("key").TextContent; string valueOverridden = overriddenNode.Attributes.getNamedItem("value").TextContent; ISet <string> s = tmpPoiZoomOverrides[Convert.ToInt16(this.poiID)]; if (s == null) { s = new HashSet <>(); tmpPoiZoomOverrides[Convert.ToInt16(this.poiID)] = s; } s.Add(OSMTag.tagKey(keyOverridden, valueOverridden)); } } this.poiID++; } // ---- Get list of way nodes ---- xe = xpath.compile(XPATH_EXPRESSION_WAYS); NodeList ways = (NodeList)xe.evaluate(document, XPathConstants.NODESET); for (int i = 0; i < ways.Length; i++) { NamedNodeMap attributes = ways.item(i).Attributes; string key = attributes.getNamedItem("key").TextContent; string value = attributes.getNamedItem("value").TextContent; string[] equivalentValues = null; if (attributes.getNamedItem("equivalent-values") != null) { equivalentValues = attributes.getNamedItem("equivalent-values").TextContent.Split(","); } sbyte zoom = attributes.getNamedItem("zoom-appear") == null ? defaultZoomAppear : sbyte.Parse(attributes.getNamedItem("zoom-appear").TextContent); bool renderable = attributes.getNamedItem("renderable") == null ? true : bool.Parse(attributes.getNamedItem("renderable").TextContent); bool forcePolygonLine = attributes.getNamedItem("force-polygon-line") == null ? false : bool.Parse(attributes.getNamedItem("force-polygon-line").TextContent); OSMTag osmTag = new OSMTag(this.wayID, key, value, zoom, renderable, forcePolygonLine); if (this.stringToWayTag.ContainsKey(osmTag.tagKey())) { LOGGER.warning("duplicate osm-tag found in tag-mapping configuration (ignoring): " + osmTag); continue; } LOGGER.finest("adding way: " + osmTag); this.stringToWayTag[osmTag.tagKey()] = osmTag; if (equivalentValues != null) { foreach (string equivalentValue in equivalentValues) { this.stringToWayTag[OSMTag.tagKey(key, equivalentValue)] = osmTag; } } this.idToWayTag[Convert.ToInt16(this.wayID)] = osmTag; // also fill optimization mapping with identity this.optimizedWayIds[Convert.ToInt16(this.wayID)] = Convert.ToInt16(this.wayID); // check if this tag overrides the zoom level spec of another tag NodeList zoomOverrideNodes = ways.item(i).ChildNodes; for (int j = 0; j < zoomOverrideNodes.Length; j++) { Node overriddenNode = zoomOverrideNodes.item(j); if (overriddenNode is Element) { string keyOverridden = overriddenNode.Attributes.getNamedItem("key").TextContent; string valueOverridden = overriddenNode.Attributes.getNamedItem("value").TextContent; ISet <string> s = tmpWayZoomOverrides[Convert.ToInt16(this.wayID)]; if (s == null) { s = new HashSet <>(); tmpWayZoomOverrides[Convert.ToInt16(this.wayID)] = s; } s.Add(OSMTag.tagKey(keyOverridden, valueOverridden)); } } this.wayID++; } // copy temporary values from zoom-override data sets foreach (KeyValuePair <short?, ISet <string> > entry in tmpPoiZoomOverrides.SetOfKeyValuePairs()) { ISet <OSMTag> overriddenTags = new HashSet <OSMTag>(); foreach (string tagString in entry.Value) { OSMTag tag = this.stringToPoiTag[tagString]; if (tag != null) { overriddenTags.Add(tag); } } if (overriddenTags.Count > 0) { this.poiZoomOverrides[entry.Key] = overriddenTags; } } foreach (KeyValuePair <short?, ISet <string> > entry in tmpWayZoomOverrides.SetOfKeyValuePairs()) { ISet <OSMTag> overriddenTags = new HashSet <OSMTag>(); foreach (string tagString in entry.Value) { OSMTag tag = this.stringToWayTag[tagString]; if (tag != null) { overriddenTags.Add(tag); } } if (overriddenTags.Count > 0) { this.wayZoomOverrides[entry.Key] = overriddenTags; } } // ---- Error handling ---- } catch (SAXParseException spe) { LOGGER.severe("\n** Parsing error, line " + spe.LineNumber + ", uri " + spe.SystemId); throw new System.InvalidOperationException(spe); } catch (SAXException sxe) { throw new System.InvalidOperationException(sxe); } catch (ParserConfigurationException pce) { throw new System.InvalidOperationException(pce); } catch (IOException ioe) { throw new System.InvalidOperationException(ioe); } catch (XPathExpressionException e) { throw new System.InvalidOperationException(e); } }
private List <string> GetExpectedPathIndicesForTag(OSMListWithPaths resultMetaData, OSMTag tag) { return(resultMetaData.pathsPerItem[tag].Select(o => o.ToString()).ToList()); }
/// <summary> /// Splits ways at road crossings, check for oneway roads and save results in OSMDB /// </summary> /// <returns>OSMDB object with road segments and used nodes</returns> public OSMDB BuildRoutableOSM() { OSMDB result = new OSMDB(); int counter = -1; foreach (OSMRoad route in _storage.Ways) { OSMWay segment = new OSMWay(counter--); OSMTag wayIDTag = new OSMTag("way-id", route.ID.ToString()); OSMTag speedTag = new OSMTag("speed", route.Speed.ToString()); string wayAccessibility = route.IsAccessible() ? "yes" : "no"; OSMTag wayAccessibilityTag = new OSMTag("accessible", wayAccessibility); string wayAccessibilityReverse = route.IsAccessibleReverse() ? "yes" : "no"; OSMTag wayAccessibilityReverseTag = new OSMTag("accessible-reverse", wayAccessibilityReverse); for (int i = 0; i < route.Nodes.Count; i++) { segment.Nodes.Add(route.Nodes[i]); if ((UsedNodes[route.Nodes[i]].Count > 1) && (i > 0) && (i < (route.Nodes.Count - 1))) { segment.Tags.Add(wayIDTag); segment.Tags.Add(speedTag); segment.Tags.Add(wayAccessibilityTag); segment.Tags.Add(wayAccessibilityReverseTag); result.Ways.Add(segment); segment = new OSMWay(counter--); segment.Nodes.Add(route.Nodes[i]); } } segment.Tags.Add(wayIDTag); segment.Tags.Add(speedTag); segment.Tags.Add(wayAccessibilityTag); segment.Tags.Add(wayAccessibilityReverseTag); result.Ways.Add(segment); } foreach (OSMNode node in _storage.Nodes) { OSMNode newNode = new OSMNode(node.ID, node.Latitude, node.Longitude); // preserve junction and highway tags on nodes if (node.Tags.ContainsTag("junction")) { newNode.Tags.Add(node.Tags["junction"]); } if (node.Tags.ContainsTag("highway")) { newNode.Tags.Add(node.Tags["highway"]); } if (_usedNodes[node.ID].Count > 1) { newNode.Tags.Add(new OSMTag("crossroad", "yes")); } result.Nodes.Add(newNode); } return(result); }
/// <summary> /// Convenience method that constructs a new OSMTag with a new id from another OSMTag. /// </summary> /// <param name="otherTag"> /// the OSMTag to copy </param> /// <param name="newID"> /// the new id </param> /// <returns> a newly constructed OSMTag with the attributes of otherTag </returns> public static OSMTag fromOSMTag(OSMTag otherTag, short newID) { return(new OSMTag(newID, otherTag.Key, otherTag.Value, otherTag.ZoomAppear, otherTag.Renderable, otherTag.ForcePolygonLine)); }