diff --git a/class.png b/class.png index 912e422..c3fff7f 100644 --- a/class.png +++ b/class.png Binary files differ diff --git a/class.pu b/class.pu index 96fbd23..16bbd96 100644 --- a/class.pu +++ b/class.pu @@ -19,6 +19,17 @@ role :VARCHAR 255 username :VARCHAR 20 } + + entity task { + + id : BIGINT + - citycode : VARCHAR 255 + - meshcode : VARCHAR 255 + version :VARCHAR 255 + path : VARCHAR 255 + line : VARCHAR 255 + point :VARCHAR 255 + } + task }|- city : citycode } note bottom of db : spring.datasource.url=jdbc:h2:./taskdb\nspring.jpa.hibernate.ddl-auto=update @@ -76,36 +87,32 @@ SiteUserRepository <|-- SiteUser class City <> { + site : static String + id : Long + citycode : String - cityname : String - folder : String - lng : String - lat : String + + setSite(String) + + getSite() : String + setLng(BigDecimal) + setLat(BigDecimal) - + setCoordinates(lng,lat) - + getCoordinates() : Coordinates + + setPoint(lng,lat) + + getPoint() : Point + toString() : String } City .. city -class Coordinates { +class Point { - lng : Double - lat : Double + toString() : String } -City .> Coordinates - -class CityIndex { - - site : String - - list : List[] -} -CityIndex *-- City +City .> Point interface CityRepository <> { - deleteByCitycode(String) - findByCitycode(String) : Object + findByCitycode(String) : City } CityRepository <|-- City @@ -119,14 +126,29 @@ } CityController ..> CityRepository -class CityIndexController <> { - - repository : CityIndexRepository - + show(model) - + addCity(city) - + process(city, result) - + deleteCity(id) +class TaskController <> { + - repository : TaskRepository + + showList(citycode, model) } -CityIndexController ..> CityIndexRepository +TaskController ..> TaskRepository + +interface TaskRepository <> { + findByCitycode() : List +} +TaskRepository <|-- Task + +class Task <> { + + id : Long + - citycode : String + - meshcode : String + version : String + path : String + point : String + line : String + + setPoint(Point) + + setLine(JsonLine) +} +Task .. task interface CommandLineRunner diff --git a/controller.png b/controller.png index cf25323..d4eb0e9 100644 --- a/controller.png +++ b/controller.png Binary files differ diff --git a/controller.pu b/controller.pu index 0ff02c3..5328af8 100644 --- a/controller.pu +++ b/controller.pu @@ -11,6 +11,7 @@ state "BLDGデータ登録" as add logout --> logout : /logout } +indeies --> cities : /city state "login" as login { login : Username @@ -45,12 +46,20 @@ } list_ --> list : /admin/list -state cities - cities : *{citycode} - cities : *{cityname} - cities : *{path} +state cities { + state city_list { + city_list : *{citycode} + city_list : *{cityname} + city_list : *{path} + } } -indeies --> cities : /city +cities --> cities : /city/delete/{citycode} +cities --> form : /city/edit/{citycode} +cities --> tasks : /task/{citycode} + +state tasks { + state task_list +} state form { state city { @@ -60,8 +69,6 @@ } } -cities --> cities : /city/delete/{citycode} -cities --> form : /city/edit/{citycode} add --> form : /city/add form --> sidebar : [!hasErrors] form --> form : [hasErrors] diff --git a/geojson.png b/geojson.png new file mode 100644 index 0000000..a866471 --- /dev/null +++ b/geojson.png Binary files differ diff --git a/geojson.pu b/geojson.pu new file mode 100644 index 0000000..df3de6a --- /dev/null +++ b/geojson.pu @@ -0,0 +1,81 @@ +@startuml + +class Geojson { + type : "FeatureCollection" + crs : JsonCrs + features : List + out() : boolean + toString() : String + parse(JsonNode) +} +Geojson *--|| JsonCrs : crs +Geojson *--|{ JsonFeature : features + +class JsonCrs { + type : "name" + properties : JsonProperties + toString() : String + parse(JsonNode) +} + +class JsonProperties { + name : String + path : String + id : String + version : String + toString() : String + parse(JsonNode) +} +JsonCrs *.. JsonProperties + +class JsonFeature { + geometryPoint : JsonGeometryPoint + geometryLine : JsonGeometryLine + type : String + properties : JsonProperties + toString() : String + parse(JsonNode) +} +JsonFeature o..o| JsonProperties +JsonFeature o..o| JsonGeometry + +interface JsonGeometry { +} +JsonGeometry <|-- JsonGeometryLine +JsonGeometry <|-- JsonGeometryPoint + +class JsonGeometryLine { + type : "LineString" + coordinates : List + toString() : String + parse(JsonNode) +} +JsonGeometryLine *..|{ Point + +class JsonGeometryPoint { + type : "Point" + coordinates : Point + toString() : String + parse(JsonNode) +} +JsonGeometryPoint *..|| Point + +class Point { + lng : String + lnt : String + setLng(BigDecimal) + setLng(String) + setLat(BigDecimal) + setLat(String) + store() + toString() : String + parse(JsonNode) +} +Point --|> JsonNumberArray + +class JsonNumberArray { + list : List + toString() : String +} + +@enduml \ No newline at end of file diff --git a/src/main/java/osm/surveyor/task/city/CityRepository.java b/src/main/java/osm/surveyor/task/city/CityRepository.java index a53971f..58fb1ba 100644 --- a/src/main/java/osm/surveyor/task/city/CityRepository.java +++ b/src/main/java/osm/surveyor/task/city/CityRepository.java @@ -5,4 +5,6 @@ import osm.surveyor.task.city.model.City; public interface CityRepository extends JpaRepository { + + City findByCitycode(String citycode); } diff --git a/src/main/java/osm/surveyor/task/city/DataLoader.java b/src/main/java/osm/surveyor/task/city/DataLoader.java index f2bce90..27d63f7 100644 --- a/src/main/java/osm/surveyor/task/city/DataLoader.java +++ b/src/main/java/osm/surveyor/task/city/DataLoader.java @@ -1,18 +1,21 @@ package osm.surveyor.task.city; +import java.io.IOException; import java.io.InputStream; import org.springframework.boot.CommandLineRunner; import org.springframework.core.io.ClassPathResource; import org.springframework.stereotype.Component; +import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import lombok.RequiredArgsConstructor; import osm.surveyor.task.city.model.CitiesJson; import osm.surveyor.task.city.model.City; import osm.surveyor.task.city.model.CityJson; -import osm.surveyor.task.city.model.Coordinates; +import osm.surveyor.task.util.Geojson; +import osm.surveyor.task.util.Point; @RequiredArgsConstructor @Component @@ -25,17 +28,38 @@ // 「src/main/resources/static/city/index.json」を読み込む try (InputStream is = new ClassPathResource("static/city/index.json").getInputStream()) { CitiesJson pojo = new ObjectMapper().readValue(is, CitiesJson.class); + String site = pojo.getSite(); for (CityJson citiesJson : pojo.getList()) { City city = new City(); + city.setSite(site); city.setCitycode(citiesJson.getCode()); city.setCityname(citiesJson.getName()); city.setFolder(citiesJson.getPath()); - Coordinates coordinates = citiesJson.toCoordinates(); - city.setCoordinates(coordinates.getLng(), coordinates.getLat()); + Point coordinates = citiesJson.toCoordinates(); + city.setLng(coordinates.getLng()); + city.setLat(coordinates.getLat()); repository.save(city); + storeTask(city); } } } + + private void storeTask(City city) throws IOException { + String folder = city.getFolder(); + String path = "static/city/"+ folder +"/bldg/index.geojson"; + try (InputStream is = new ClassPathResource(path).getInputStream()) { + ObjectMapper mapper = new ObjectMapper(); + JsonNode node = mapper.readTree(is); + Geojson geojson = new Geojson(); + geojson.parse(node); + + // TODO: + System.out.println("["+ path + "] " + geojson.toString()); + } + + // TODO: + + } } \ No newline at end of file diff --git a/src/main/java/osm/surveyor/task/city/TaskController.java b/src/main/java/osm/surveyor/task/city/TaskController.java new file mode 100644 index 0000000..92d80ea --- /dev/null +++ b/src/main/java/osm/surveyor/task/city/TaskController.java @@ -0,0 +1,24 @@ +package osm.surveyor.task.city; + +import java.util.List; + +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; + +import lombok.RequiredArgsConstructor; +import osm.surveyor.task.city.model.Task; + +@RequiredArgsConstructor +@Controller +public class TaskController { + private final TaskRepository repository; + + @GetMapping("/task/{citycode}") + public String showList(@PathVariable String citycode, Model model) { + List tasks = repository.findByCitycode(citycode); + model.addAttribute("tasks", tasks); + return "tasks"; + } +} diff --git a/src/main/java/osm/surveyor/task/city/TaskRepository.java b/src/main/java/osm/surveyor/task/city/TaskRepository.java new file mode 100644 index 0000000..d9112cb --- /dev/null +++ b/src/main/java/osm/surveyor/task/city/TaskRepository.java @@ -0,0 +1,12 @@ +package osm.surveyor.task.city; + +import java.util.List; + +import org.springframework.data.jpa.repository.JpaRepository; + +import osm.surveyor.task.city.model.Task; + +public interface TaskRepository extends JpaRepository { + + List findByCitycode(String citycode); +} diff --git a/src/main/java/osm/surveyor/task/city/model/City.java b/src/main/java/osm/surveyor/task/city/model/City.java index 6f5a7fd..5240d9b 100644 --- a/src/main/java/osm/surveyor/task/city/model/City.java +++ b/src/main/java/osm/surveyor/task/city/model/City.java @@ -9,11 +9,13 @@ import lombok.Getter; import lombok.Setter; +import osm.surveyor.task.util.Point; @Getter @Setter @Entity public class City { + private static String site; // 全体に適用する @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @@ -34,6 +36,14 @@ @NotBlank private String lat = "0.0"; + public void setSite(String site) { + City.site = site; + } + + public String getSite() { + return City.site; + } + public void setCitycode(String citycode) { this.citycode = citycode; } @@ -59,16 +69,16 @@ setLat(lat); } - public void setCoordinates(String lng, String lat) { + public void setPoint(String lng, String lat) { setLng(lng); setLat(lat); } - public Coordinates getCoordinates() { - Coordinates coordinates = new Coordinates(); - coordinates.setLng(getLng()); - coordinates.setLat(getLat()); - return coordinates; + public Point getPoint() { + Point point = new Point(); + point.setLng(getLng()); + point.setLat(getLat()); + return point; } @Override @@ -78,7 +88,7 @@ sb.append("\"code\":\""+ getCitycode() +"\""); sb.append(",\"name\":\""+ getCityname() +"\""); sb.append(",\"path\":\""+ getFolder() +"\""); - sb.append(",\"coordinates\":"+ getCoordinates().toString()); + sb.append(",\"coordinates\":"+ getPoint().toString()); sb.append("}"); return sb.toString(); } diff --git a/src/main/java/osm/surveyor/task/city/model/CityJson.java b/src/main/java/osm/surveyor/task/city/model/CityJson.java index 6a29d5f..4666876 100644 --- a/src/main/java/osm/surveyor/task/city/model/CityJson.java +++ b/src/main/java/osm/surveyor/task/city/model/CityJson.java @@ -5,6 +5,7 @@ import lombok.Getter; import lombok.Setter; +import osm.surveyor.task.util.Point; @Getter @Setter @@ -18,8 +19,8 @@ private List coordinates = new ArrayList<>(); - public Coordinates toCoordinates() { - Coordinates obj = new Coordinates(); + public Point toCoordinates() { + Point obj = new Point(); if (this.coordinates.size() >= 2) { obj.setLng(Double.toString(this.coordinates.get(0))); obj.setLat(Double.toString(this.coordinates.get(1))); diff --git a/src/main/java/osm/surveyor/task/city/model/Coordinates.java b/src/main/java/osm/surveyor/task/city/model/Coordinates.java deleted file mode 100644 index 3738939..0000000 --- a/src/main/java/osm/surveyor/task/city/model/Coordinates.java +++ /dev/null @@ -1,40 +0,0 @@ -package osm.surveyor.task.city.model; - -import java.math.BigDecimal; - -import lombok.Getter; -import lombok.Setter; - -@Getter -@Setter -public class Coordinates { - - private String lng = "0.0"; - - private String lat = "0.0"; - - public void setLng(String str) { - this.lng = str; - } - - public void setLng(BigDecimal dec) { - this.lng = dec.toString(); - } - - public void setLat(String str) { - this.lat = str; - } - - public void setLat(BigDecimal dec) { - this.lat = dec.toString(); - } - - public String toString() { - StringBuffer sb = new StringBuffer(); - sb.append("["); - sb.append(getLng()); - sb.append(getLat()); - sb.append("]"); - return sb.toString(); - } -} diff --git a/src/main/java/osm/surveyor/task/city/model/Task.java b/src/main/java/osm/surveyor/task/city/model/Task.java new file mode 100644 index 0000000..fc98316 --- /dev/null +++ b/src/main/java/osm/surveyor/task/city/model/Task.java @@ -0,0 +1,45 @@ +package osm.surveyor.task.city.model; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.validation.constraints.NotBlank; + +import lombok.Getter; +import lombok.Setter; +import osm.surveyor.task.util.JsonGeometryLine; +import osm.surveyor.task.util.Point; + +@Getter +@Setter +@Entity +public class Task { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @NotBlank + private String citycode; + + @NotBlank + private String meshcode; + + @NotBlank + private String version; + + @NotBlank + private String path; + + private String point; + + private String line; + + public void setPoint(Point p) { + this.point = p.toString(); + } + + public void setLine(JsonGeometryLine p) { + this.line = p.toString(); + } +} diff --git a/src/main/java/osm/surveyor/task/util/Geojson.java b/src/main/java/osm/surveyor/task/util/Geojson.java new file mode 100644 index 0000000..0f7889f --- /dev/null +++ b/src/main/java/osm/surveyor/task/util/Geojson.java @@ -0,0 +1,94 @@ +package osm.surveyor.task.util; + +import java.util.ArrayList; +import java.util.List; + +import com.fasterxml.jackson.databind.JsonNode; + +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public class Geojson { + + private String type = "FeatureCollection"; + + private JsonCrs crs; + + private List features = new ArrayList<>(); + + public String toString() { + StringBuffer sb = new StringBuffer(); + boolean c = false; + sb.append("{"); + c = Geojson.outStr(c, sb, "type", this.type); + c = Geojson.out(c, sb, "crs", this.crs); + if (c) { + sb.append(","); + } + sb.append("\"features\":["); + boolean c2 = false; + for (JsonFeature f : features) { + c2 = Geojson.out(c2, sb, null, f); + } + sb.append("]"); + + sb.append("}"); + return sb.toString(); + } + + public void parse(JsonNode node) { + setType(node.get("type").textValue()); + + JsonNode nodeCrs = node.get("crs"); + if (nodeCrs != null) { + this.crs = new JsonCrs(); + this.crs.parse(nodeCrs); + } + + JsonNode f = node.get("features"); + if (f != null) { + this.features = new ArrayList(); + for (JsonNode f1 : f) { + JsonFeature feature = new JsonFeature(); + feature.parse(f1); + this.features.add(feature); + } + } + } + + public static boolean out(boolean c, StringBuffer sb, String name, Object obj) { + boolean c1 = c; + if (obj != null) { + if (c1) { + sb.append(","); + } + else { + c1 = true; + } + if (name != null) { + sb.append("\""+ name +"\":"); + } + sb.append(obj.toString()); + } + return c1; + } + + public static boolean outStr(boolean c, StringBuffer sb, String name, Object obj) { + boolean c1 = c; + if (obj != null) { + if (c1) { + sb.append(","); + } + else { + c1 = true; + } + if (name != null) { + sb.append("\""+ name +"\":"); + } + sb.append("\""+ obj.toString() +"\""); + } + return c1; + } +} diff --git a/src/main/java/osm/surveyor/task/util/JsonCrs.java b/src/main/java/osm/surveyor/task/util/JsonCrs.java new file mode 100644 index 0000000..6f70126 --- /dev/null +++ b/src/main/java/osm/surveyor/task/util/JsonCrs.java @@ -0,0 +1,42 @@ +package osm.surveyor.task.util; + +import com.fasterxml.jackson.databind.JsonNode; + +import lombok.Getter; +import lombok.Setter; + +/** + "crs": { + "type":"name", + "properties":{ + "name":"urn:ogc:def:crs:OGC:1.3:CRS84" + } + } +*/ +@Getter +@Setter +public class JsonCrs { + + private String type = "name"; + private JsonProperties properties; + + public String toString() { + StringBuffer sb = new StringBuffer(); + boolean c1 = false; + sb.append("{"); + c1 = Geojson.outStr(c1, sb, "type", this.type); + c1 = Geojson.out(c1, sb, "properties", this.properties); + sb.append("}"); + return sb.toString(); + } + + public void parse(JsonNode node) { + setType(node.get("type").textValue()); + + JsonNode node1 = node.get("properties"); + if (node1 != null) { + this.properties = new JsonProperties(); + this.properties.parse(node1); + } + } +} diff --git a/src/main/java/osm/surveyor/task/util/JsonFeature.java b/src/main/java/osm/surveyor/task/util/JsonFeature.java new file mode 100644 index 0000000..ff80166 --- /dev/null +++ b/src/main/java/osm/surveyor/task/util/JsonFeature.java @@ -0,0 +1,84 @@ +package osm.surveyor.task.util; + +import com.fasterxml.jackson.databind.JsonNode; + +import lombok.Getter; +import lombok.Setter; + +/** + * { + * "geometry":{ + * "coordinates":[141.35625,42.90416666666667], + * "type":"Point" + * }, + * "type":"Feature", + * "properties":{"id":"64412288"} + * }, + * { + * "geometry":{ + * "coordinates":[ + * [141.35,42.9], + * [141.36249999999998,42.9], + * [141.36249999999998,42.90833333333333], + * [141.35,42.90833333333333], + * [141.35,42.9] + * ], + * "type":"LineString" + * }, + * "type":"Feature", + * "properties":{"id":"64412288"} + * }, + */ +@Getter +@Setter +public class JsonFeature { + private JsonGeometryPoint geometryPoint; + private JsonGeometryLine geometryLine; + + private String type; + + private JsonProperties properties; + + public String toString() { + StringBuffer sb = new StringBuffer(); + boolean c = false; + sb.append("{"); + c = Geojson.outStr(c, sb, "type", this.type); + c = Geojson.out(c, sb, "properties", this.properties.toString()); + c = Geojson.out(c, sb, "geometry", this.geometryPoint); + c = Geojson.out(c, sb, "geometry", this.geometryLine); + sb.append("}"); + return sb.toString(); + } + + public void parse(JsonNode node) { + JsonNode node1 = node.get("type"); + if (node1 != null) { + this.type = node1.textValue(); + } + + node1 = node.get("properties"); + if (node1 != null) { + this.properties = new JsonProperties(); + this.properties.parse(node1); + } + + node1 = node.get("geometry"); + if (node1 != null) { + JsonNode node2 = node1.get("type"); + if (node2 != null) { + String type2 = node2.textValue(); + if (type2.equals("Point")) { + this.geometryLine = null; + this.geometryPoint = new JsonGeometryPoint(); + this.geometryPoint.parse(node1); + } + else if (type2.equals("LineString")) { + this.geometryPoint = null; + this.geometryLine = new JsonGeometryLine(); + this.geometryLine.parse(node1); + } + } + } + } +} diff --git a/src/main/java/osm/surveyor/task/util/JsonGeometry.java b/src/main/java/osm/surveyor/task/util/JsonGeometry.java new file mode 100644 index 0000000..636df82 --- /dev/null +++ b/src/main/java/osm/surveyor/task/util/JsonGeometry.java @@ -0,0 +1,4 @@ +package osm.surveyor.task.util; + +public interface JsonGeometry { +} diff --git a/src/main/java/osm/surveyor/task/util/JsonGeometryLine.java b/src/main/java/osm/surveyor/task/util/JsonGeometryLine.java new file mode 100644 index 0000000..ba19215 --- /dev/null +++ b/src/main/java/osm/surveyor/task/util/JsonGeometryLine.java @@ -0,0 +1,68 @@ +package osm.surveyor.task.util; + +import java.util.ArrayList; +import java.util.List; + +import com.fasterxml.jackson.databind.JsonNode; + +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public class JsonGeometryLine { + + /** + * { + * "coordinates":[ + * [141.35,42.9], + * [141.36249999999998,42.9], + * [141.36249999999998,42.90833333333333], + * [141.35,42.90833333333333], + * [141.35,42.9] + * ], + * "type":"LineString" + * } + */ + + private List coordinates; + + private String type = "LineString"; + + public String toString() { + StringBuffer sb = new StringBuffer(); + boolean first = false; + sb.append("{"); + if (coordinates != null) { + first = true; + boolean c1 = false; + sb.append("["); + for (JsonNumberArray arry : coordinates) { + c1 = Geojson.out(c1, sb, null, arry); + } + sb.append("]"); + } + if (type != null) { + first = Geojson.outStr(first, sb, "type", getType()); + } + sb.append("}"); + return sb.toString(); + } + + public void parse(JsonNode node) { + JsonNode node1 = node.get("type"); + if (node1 != null) { + this.type = node1.textValue(); + } + + node1 = node.get("coordinates"); + if (node1 != null) { + this.coordinates = new ArrayList(); + for (JsonNode node2 : node1) { + Point point = new Point(); + point.parse(node2); + this.coordinates.add(point); + } + } + } +} diff --git a/src/main/java/osm/surveyor/task/util/JsonGeometryPoint.java b/src/main/java/osm/surveyor/task/util/JsonGeometryPoint.java new file mode 100644 index 0000000..c03efe9 --- /dev/null +++ b/src/main/java/osm/surveyor/task/util/JsonGeometryPoint.java @@ -0,0 +1,43 @@ +package osm.surveyor.task.util; + +import com.fasterxml.jackson.databind.JsonNode; + +import lombok.Getter; +import lombok.Setter; + +/** + * { + * "coordinates":[141.35625,42.90416666666667], + * "type":"Point" + * } + */ +@Getter +@Setter +public class JsonGeometryPoint { + private Point coordinates; + + private String type = "Point"; + + public String toString() { + StringBuffer sb = new StringBuffer(); + boolean c = false; + sb.append("{"); + c = Geojson.out(c, sb, "coordinates", this.coordinates); + c = Geojson.outStr(c, sb, "type", this.type); + sb.append("}"); + return sb.toString(); + } + + public void parse(JsonNode node) { + JsonNode node1 = node.get("type"); + if (node1 != null) { + this.type = node1.textValue(); + } + + node1 = node.get("coordinates"); + if (node1 != null) { + this.coordinates = new Point(); + this.coordinates.parse(node1); + } + } +} diff --git a/src/main/java/osm/surveyor/task/util/JsonLineString.java b/src/main/java/osm/surveyor/task/util/JsonLineString.java new file mode 100644 index 0000000..d476176 --- /dev/null +++ b/src/main/java/osm/surveyor/task/util/JsonLineString.java @@ -0,0 +1,71 @@ +package osm.surveyor.task.util; + +import java.util.ArrayList; +import java.util.List; + +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public class JsonLineString { + + private List line = new ArrayList<>(); + + public void addPoint(Point point) { + this.line.add(point); + } + + /* + * [ + * [141.35,42.9], + * [141.36249999999998,42.9], + * [141.36249999999998,42.90833333333333], + * [141.35,42.90833333333333], + * [141.35,42.9] + * ] + */ + public String toString() { + StringBuffer sb = new StringBuffer(); + sb.append("["); + boolean first = true; + for (Point point : this.line) { + if (first) { + first = false; + } + else { + sb.append(","); + } + sb.append(point.toString()); + } + sb.append("]"); + return sb.toString(); + } + + /** + * { + * "geometry":{ + * "coordinates":[ + * [141.35,42.9], + * [141.36249999999998,42.9], + * [141.36249999999998,42.90833333333333], + * [141.35,42.90833333333333], + * [141.35,42.9] + * ], + * "type":"LineString" + * }, + * "type":"Feature", + * "properties":{"id":"64412288"} + * } + */ + public String getGeometry() { + StringBuffer sb = new StringBuffer(); + sb.append("{"); + sb.append("\"geometry\":{"); + sb.append("\"type\":\"LineString\""); + sb.append(",\"coordinates\":"+ toString()); + sb.append("}"); + sb.append("}"); + return sb.toString(); + } +} diff --git a/src/main/java/osm/surveyor/task/util/JsonNumberArray.java b/src/main/java/osm/surveyor/task/util/JsonNumberArray.java new file mode 100644 index 0000000..cd75c3a --- /dev/null +++ b/src/main/java/osm/surveyor/task/util/JsonNumberArray.java @@ -0,0 +1,39 @@ +package osm.surveyor.task.util; + +import java.util.ArrayList; +import java.util.List; + +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public class JsonNumberArray { + + private List list = new ArrayList<>(); + + public void setList(List list) { + this.list = new ArrayList<>(); + for (String str : list) { + add(str); + } + } + + public void add(String str) { + this.list.add(str); + } + + /* + * [141.35625,42.90416666666667] + */ + public String toString() { + StringBuffer sb = new StringBuffer(); + sb.append("["); + boolean first = false; + for (String str : this.list) { + first = Geojson.out(first, sb, null, str); + } + sb.append("]"); + return sb.toString(); + } +} diff --git a/src/main/java/osm/surveyor/task/util/JsonProperties.java b/src/main/java/osm/surveyor/task/util/JsonProperties.java new file mode 100644 index 0000000..a1f6250 --- /dev/null +++ b/src/main/java/osm/surveyor/task/util/JsonProperties.java @@ -0,0 +1,54 @@ +package osm.surveyor.task.util; + +import com.fasterxml.jackson.databind.JsonNode; + +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public class JsonProperties { + /* + * "properties":{ + * "id":"64412288" + * } + */ + private String name; + private String path; + private String id; + private String version; + + public String toString() { + StringBuffer sb = new StringBuffer(); + boolean c1 = false; + sb.append("{"); + c1 = Geojson.outStr(c1, sb, "name", this.name); + c1 = Geojson.outStr(c1, sb, "path", this.path); + c1 = Geojson.outStr(c1, sb, "id", this.id); + c1 = Geojson.outStr(c1, sb, "version", this.version); + sb.append("}"); + return sb.toString(); + } + + public void parse(JsonNode node) { + JsonNode node1 = node.get("name"); + if (node1 != null) { + this.name = node1.textValue(); + } + + node1 = node.get("path"); + if (node1 != null) { + this.path = node1.textValue(); + } + + node1 = node.get("id"); + if (node1 != null) { + this.id = node1.textValue(); + } + + node1 = node.get("version"); + if (node1 != null) { + this.version = node1.textValue(); + } + } +} diff --git a/src/main/java/osm/surveyor/task/util/Point.java b/src/main/java/osm/surveyor/task/util/Point.java new file mode 100644 index 0000000..74f971e --- /dev/null +++ b/src/main/java/osm/surveyor/task/util/Point.java @@ -0,0 +1,92 @@ +package osm.surveyor.task.util; + +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.List; + +import com.fasterxml.jackson.databind.JsonNode; + +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public class Point extends JsonNumberArray { + + private String lng = "0.0"; + + private String lat = "0.0"; + + public void setLng(String str) { + this.lng = str; + } + + public void setLng(BigDecimal dec) { + this.lng = dec.toString(); + } + + public void setLat(String str) { + this.lat = str; + } + + public void setLat(BigDecimal dec) { + this.lat = dec.toString(); + } + + private void store() { + List list = new ArrayList<>(); + list.add(getLng()); + list.add(getLat()); + setList(list); + } + + /* + * [141.35625,42.90416666666667] + */ + @Override + public String toString() { + store(); + return super.toString(); + } + + public void parse(JsonNode node) { + if (node != null) { + boolean one = false; + for (JsonNode node2 : node) { + if (!one) { + setLng(node2.asText()); + one = true; + } + else { + setLat(node2.asText()); + } + } + } + } + + /* + * { + * "geometry":{ + * "coordinates":[141.35625,42.90416666666667], + * "type":"Point" + * }, + * "type":"Feature", + * "properties":{ + * "path":"64412288_bldg_6697_op.zip", + * "id":"64412288", + * "version":"1.4.6" + * } + * } + */ + public String getGeometry() { + store(); + StringBuffer sb = new StringBuffer(); + sb.append("{"); + sb.append("\"geometry\":{"); + sb.append("\"type\":\"Point\""); + sb.append(",\"coordinates\":"+ toString()); + sb.append("}"); + sb.append("}"); + return sb.toString(); + } +} diff --git a/src/main/resources/static/city/01100_sapporo-shi_2020/bldg/index.geojson b/src/main/resources/static/city/01100_sapporo-shi_2020/bldg/index.geojson index d6f5758..37dded7 100644 --- a/src/main/resources/static/city/01100_sapporo-shi_2020/bldg/index.geojson +++ b/src/main/resources/static/city/01100_sapporo-shi_2020/bldg/index.geojson @@ -1,9 +1,40 @@ { "type": "FeatureCollection", - "crs": {"type":"name","properties":{"name":"urn:ogc:def:crs:OGC:1.3:CRS84"}}, + "crs": { + "type":"name", + "properties":{ + "name":"urn:ogc:def:crs:OGC:1.3:CRS84" + } + }, "features": [ - {"geometry":{"coordinates":[141.35625,42.90416666666667],"type":"Point"},"type":"Feature","properties":{"path":"64412288_bldg_6697_op.zip","id":"64412288","version":"1.4.6"}}, - {"geometry":{"coordinates":[[141.35,42.9],[141.36249999999998,42.9],[141.36249999999998,42.90833333333333],[141.35,42.90833333333333],[141.35,42.9]],"type":"LineString"},"type":"Feature","properties":{"id":"64412288"}}, + { + "geometry":{ + "coordinates":[141.35625,42.90416666666667], + "type":"Point" + }, + "type":"Feature", + "properties":{ + "path":"64412288_bldg_6697_op.zip", + "id":"64412288", + "version":"1.4.6" + } + }, + { + "geometry":{ + "coordinates":[ + [141.35,42.9], + [141.36249999999998,42.9], + [141.36249999999998,42.90833333333333], + [141.35,42.90833333333333], + [141.35,42.9] + ], + "type":"LineString" + }, + "type":"Feature", + "properties":{ + "id":"64412288" + } + }, {"geometry":{"coordinates":[141.21875,42.95416666666667],"type":"Point"},"type":"Feature","properties":{"path":"64413147_bldg_6697_op.zip","id":"64413147","version":"1.4.6"}}, {"geometry":{"coordinates":[[141.2125,42.95],[141.225,42.95],[141.225,42.958333333333336],[141.2125,42.958333333333336],[141.2125,42.95]],"type":"LineString"},"type":"Feature","properties":{"id":"64413147"}}, {"geometry":{"coordinates":[141.40625,43.02916666666667],"type":"Point"},"type":"Feature","properties":{"path":"64414332_bldg_6697_op.zip","id":"64414332","version":"1.4.6"}}, diff --git a/src/main/resources/static/css/img/osm_200x200.png b/src/main/resources/static/css/img/osm_200x200.png new file mode 100644 index 0000000..f1f47c9 --- /dev/null +++ b/src/main/resources/static/css/img/osm_200x200.png Binary files differ diff --git a/src/main/resources/static/css/img/photo.jpg b/src/main/resources/static/css/img/photo.jpg new file mode 100644 index 0000000..3dc82c0 --- /dev/null +++ b/src/main/resources/static/css/img/photo.jpg Binary files differ diff --git a/src/main/resources/static/img/osm_200x200.png b/src/main/resources/static/img/osm_200x200.png deleted file mode 100644 index f1f47c9..0000000 --- a/src/main/resources/static/img/osm_200x200.png +++ /dev/null Binary files differ diff --git a/src/main/resources/static/img/photo.jpg b/src/main/resources/static/img/photo.jpg deleted file mode 100644 index 3dc82c0..0000000 --- a/src/main/resources/static/img/photo.jpg +++ /dev/null Binary files differ diff --git a/src/main/resources/templates/cities.html b/src/main/resources/templates/cities.html index eb7c425..5007bae 100644 --- a/src/main/resources/templates/cities.html +++ b/src/main/resources/templates/cities.html @@ -55,6 +55,7 @@ citycode cityname folder + site @@ -64,7 +65,13 @@ + + + + タスク + + 編集 diff --git a/src/test/java/osm/surveyor/task/util/GeojsonTest.java b/src/test/java/osm/surveyor/task/util/GeojsonTest.java new file mode 100644 index 0000000..b58d64d --- /dev/null +++ b/src/test/java/osm/surveyor/task/util/GeojsonTest.java @@ -0,0 +1,49 @@ +package osm.surveyor.task.util; + +import java.io.IOException; +import java.io.InputStream; + +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.core.io.ClassPathResource; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; + +class GeojsonTest { + + @BeforeAll + static void setUpBeforeClass() throws Exception { + } + + @AfterAll + static void tearDownAfterClass() throws Exception { + } + + @BeforeEach + void setUp() throws Exception { + } + + @AfterEach + void tearDown() throws Exception { + } + + @Test + @DisplayName("'Sapporo'のGeojsonをパース") + void readSapporo() throws IOException { + String path = "static/city/01100_sapporo-shi_2020/bldg/index.geojson"; + try (InputStream is = new ClassPathResource(path).getInputStream()) { + ObjectMapper mapper = new ObjectMapper(); + JsonNode node = mapper.readTree(is); + Geojson geojson = new Geojson(); + geojson.parse(node); + + System.out.println(geojson.toString()); + } + } + +}