Newer
Older
osmCoverage / src / osm / jp / api / OsmnodeNode.java
@hayashi hayashi on 27 May 2018 1 KB OverpassAPI
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package osm.jp.api;

import java.util.ArrayList;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;

/**
 * OSM.xml の「Area(way)」ノード
 * 例)
 * <pre>{@code 
 *  <node id="289445748" lat="35.5251815" lon="139.3256576">
 *   <tag k="amenity" v="fuel"/>
 *   <tag k="brand" v="出光"/>
 *   <tag k="name" v="出光"/>
 *   <tag k="name:en" v="Idemitsu"/>
 *   <tag k="opening_hours" v="24/7"/>
 * </node>
 * }</pre>
 * 
 * @author yuu
 */
public class OsmnodeNode {
    Node node = null;
    String id = null;
    String latStr = null;
    String lonStr = null;
    ArrayList<OsmnodeTag> tags = new ArrayList<>();
    
    public OsmnodeNode(Node node) {
        this.node = node;
        
        NamedNodeMap attributes = node.getAttributes();
        if (attributes != null) {
            id = attributes.getNamedItem("id").getNodeValue();
            latStr = attributes.getNamedItem("lat").getNodeValue();
            lonStr = attributes.getNamedItem("lon").getNodeValue();
        }
        
        Node tagNodes = node.getFirstChild();
        while(tagNodes != null) {
            String nodeName = tagNodes.getNodeName();
            switch (nodeName) {
            case "tag":
                OsmnodeTag nodetag = new OsmnodeTag(tagNodes);
                tags.add(nodetag);
                break;
            }
            tagNodes = tagNodes.getNextSibling();
        }
    }
    
    public String getValue(String key) {
        for (OsmnodeTag tag : tags) {
            if (tag.key.equals(key)) {
                return tag.value;
            }
        }
        return null;
    }

}