Newer
Older
task-bldg / src / main / java / osm / surveyor / task / util / JsonFeature.java
  1. package osm.surveyor.task.util;
  2.  
  3. import com.fasterxml.jackson.databind.JsonNode;
  4.  
  5. import lombok.Getter;
  6. import lombok.Setter;
  7.  
  8. /**
  9. * {
  10. * "geometry":{
  11. * "coordinates":[141.35625,42.90416666666667],
  12. * "type":"Point"
  13. * },
  14. * "type":"Feature",
  15. * "properties":{"id":"64412288"}
  16. * },
  17. * {
  18. * "geometry":{
  19. * "coordinates":[
  20. * [141.35,42.9],
  21. * [141.36249999999998,42.9],
  22. * [141.36249999999998,42.90833333333333],
  23. * [141.35,42.90833333333333],
  24. * [141.35,42.9]
  25. * ],
  26. * "type":"LineString"
  27. * },
  28. * "type":"Feature",
  29. * "properties":{"id":"64412288"}
  30. * },
  31. */
  32. @Getter
  33. @Setter
  34. public class JsonFeature extends JsonTemple {
  35. private JsonGeometryPoint geometryPoint;
  36. private JsonGeometryLine geometryLine;
  37. private String type;
  38. private JsonProperties properties;
  39. public String toString() {
  40. StringBuffer sb = new StringBuffer();
  41. boolean c = false;
  42. sb.append("{");
  43. c = outStr(c, sb, "type", this.type);
  44. c = out(c, sb, "properties", this.properties.toString());
  45. c = out(c, sb, "geometry", this.geometryPoint);
  46. c = out(c, sb, "geometry", this.geometryLine);
  47. sb.append("}");
  48. return sb.toString();
  49. }
  50. public void parse(JsonNode node) {
  51. JsonNode node1 = node.get("type");
  52. if (node1 != null) {
  53. this.type = node1.textValue();
  54. }
  55. node1 = node.get("properties");
  56. if (node1 != null) {
  57. this.properties = new JsonProperties();
  58. this.properties.parse(node1);
  59. }
  60. node1 = node.get("geometry");
  61. if (node1 != null) {
  62. JsonNode node2 = node1.get("type");
  63. if (node2 != null) {
  64. String type2 = node2.textValue();
  65. if (type2.equals("Point")) {
  66. this.geometryLine = null;
  67. this.geometryPoint = new JsonGeometryPoint();
  68. this.geometryPoint.parse(node1);
  69. }
  70. else if (type2.equals("LineString")) {
  71. this.geometryPoint = null;
  72. this.geometryLine = new JsonGeometryLine();
  73. this.geometryLine.parse(node1);
  74. }
  75. }
  76. }
  77. }
  78. }