- /*
- * 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="5645448449" lat="35.7506438" lon="139.7516866"/>
- * <node id="5645448450" lat="35.7507261" lon="139.7516913"/>
- * <node id="5645448451" lat="35.7507196" lon="139.7518665"/>
- * <node id="5645448452" lat="35.7506374" lon="139.7518619"/>
- * <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>
- * <way id="591327850">
- * <nd ref="5645448449"/>
- * <nd ref="5645448450"/>
- * <nd ref="5645448451"/>
- * <nd ref="5645448452"/>
- * <nd ref="5645448449"/>
- * <tag k="amenity" v="fuel"/>
- * <tag k="name" v="Mobil"/>
- * <tag k="name:ja" v="モービル"/>
- * </way>
- *
- * }</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();
- Node nn = attributes.getNamedItem("lat");
- if (nn != null) {
- latStr = nn.getNodeValue();
- }
- Node nodeLon = attributes.getNamedItem("lon");
- if (nodeLon != null) {
- lonStr = nodeLon.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;
- }
- public boolean isRemoved() {
- for (OsmnodeTag tag : tags) {
- if (tag.key.startsWith("disused:")) {
- return true;
- }
- if (tag.key.startsWith("abandoned:")) {
- return true;
- }
- if (tag.key.startsWith("demolished:")) {
- return true;
- }
- if (tag.key.startsWith("removed:")) {
- return true;
- }
- if (tag.key.startsWith("no:")) {
- return true;
- }
- if (tag.key.startsWith("historic:")) {
- return true;
- }
- if (tag.key.startsWith("was:")) {
- return true;
- }
- }
- return false;
- }
- }