Newer
Older
osmCoverage / src / osm / jp / api / OsmnodeNode.java
@hayashi hayashi on 27 May 2018 1 KB OverpassAPI
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package osm.jp.api;
  7.  
  8. import java.util.ArrayList;
  9. import org.w3c.dom.NamedNodeMap;
  10. import org.w3c.dom.Node;
  11.  
  12. /**
  13. * OSM.xml の「Area(way)」ノード
  14. * 例)
  15. * <pre>{@code
  16. * <node id="289445748" lat="35.5251815" lon="139.3256576">
  17. * <tag k="amenity" v="fuel"/>
  18. * <tag k="brand" v="出光"/>
  19. * <tag k="name" v="出光"/>
  20. * <tag k="name:en" v="Idemitsu"/>
  21. * <tag k="opening_hours" v="24/7"/>
  22. * </node>
  23. * }</pre>
  24. *
  25. * @author yuu
  26. */
  27. public class OsmnodeNode {
  28. Node node = null;
  29. String id = null;
  30. String latStr = null;
  31. String lonStr = null;
  32. ArrayList<OsmnodeTag> tags = new ArrayList<>();
  33. public OsmnodeNode(Node node) {
  34. this.node = node;
  35. NamedNodeMap attributes = node.getAttributes();
  36. if (attributes != null) {
  37. id = attributes.getNamedItem("id").getNodeValue();
  38. latStr = attributes.getNamedItem("lat").getNodeValue();
  39. lonStr = attributes.getNamedItem("lon").getNodeValue();
  40. }
  41. Node tagNodes = node.getFirstChild();
  42. while(tagNodes != null) {
  43. String nodeName = tagNodes.getNodeName();
  44. switch (nodeName) {
  45. case "tag":
  46. OsmnodeTag nodetag = new OsmnodeTag(tagNodes);
  47. tags.add(nodetag);
  48. break;
  49. }
  50. tagNodes = tagNodes.getNextSibling();
  51. }
  52. }
  53. public String getValue(String key) {
  54. for (OsmnodeTag tag : tags) {
  55. if (tag.key.equals(key)) {
  56. return tag.value;
  57. }
  58. }
  59. return null;
  60. }
  61.  
  62. }