Newer
Older
osmCoverage / src / osm / jp / api / OsmnodeNode.java
@hayashi hayashi on 5 Jun 2018 3 KB xxx
  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="5645448449" lat="35.7506438" lon="139.7516866"/>
  17. * <node id="5645448450" lat="35.7507261" lon="139.7516913"/>
  18. * <node id="5645448451" lat="35.7507196" lon="139.7518665"/>
  19. * <node id="5645448452" lat="35.7506374" lon="139.7518619"/>
  20. * <node id="289445748" lat="35.5251815" lon="139.3256576">
  21. * <tag k="amenity" v="fuel"/>
  22. * <tag k="brand" v="出光"/>
  23. * <tag k="name" v="出光"/>
  24. * <tag k="name:en" v="Idemitsu"/>
  25. * <tag k="opening_hours" v="24/7"/>
  26. * </node>
  27. * <way id="591327850">
  28. * <nd ref="5645448449"/>
  29. * <nd ref="5645448450"/>
  30. * <nd ref="5645448451"/>
  31. * <nd ref="5645448452"/>
  32. * <nd ref="5645448449"/>
  33. * <tag k="amenity" v="fuel"/>
  34. * <tag k="name" v="Mobil"/>
  35. * <tag k="name:ja" v="モービル"/>
  36. * </way>
  37. *
  38. * }</pre>
  39. *
  40. * @author yuu
  41. */
  42. public class OsmnodeNode {
  43. Node node = null;
  44. String id = null;
  45. String latStr = null;
  46. String lonStr = null;
  47. ArrayList<OsmnodeTag> tags = new ArrayList<>();
  48. public OsmnodeNode(Node node) {
  49. this.node = node;
  50. NamedNodeMap attributes = node.getAttributes();
  51. if (attributes != null) {
  52. id = attributes.getNamedItem("id").getNodeValue();
  53. Node nn = attributes.getNamedItem("lat");
  54. if (nn != null) {
  55. latStr = nn.getNodeValue();
  56. }
  57. Node nodeLon = attributes.getNamedItem("lon");
  58. if (nodeLon != null) {
  59. lonStr = nodeLon.getNodeValue();
  60. }
  61. }
  62. Node tagNodes = node.getFirstChild();
  63. while(tagNodes != null) {
  64. String nodeName = tagNodes.getNodeName();
  65. switch (nodeName) {
  66. case "tag":
  67. OsmnodeTag nodetag = new OsmnodeTag(tagNodes);
  68. tags.add(nodetag);
  69. break;
  70. }
  71. tagNodes = tagNodes.getNextSibling();
  72. }
  73. }
  74. public String getValue(String key) {
  75. for (OsmnodeTag tag : tags) {
  76. if (tag.key.equals(key)) {
  77. return tag.value;
  78. }
  79. }
  80. return null;
  81. }
  82. public boolean isRemoved() {
  83. for (OsmnodeTag tag : tags) {
  84. if (tag.key.startsWith("disused:")) {
  85. return true;
  86. }
  87. if (tag.key.startsWith("abandoned:")) {
  88. return true;
  89. }
  90. if (tag.key.startsWith("demolished:")) {
  91. return true;
  92. }
  93. if (tag.key.startsWith("removed:")) {
  94. return true;
  95. }
  96. if (tag.key.startsWith("no:")) {
  97. return true;
  98. }
  99. if (tag.key.startsWith("historic:")) {
  100. return true;
  101. }
  102. if (tag.key.startsWith("was:")) {
  103. return true;
  104. }
  105. }
  106. return false;
  107. }
  108. }