Beispiel #1
0
        /// <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++;
            }
        }
Beispiel #2
0
        // /**
        // * @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)]);
        }
Beispiel #3
0
        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);
            }
        }