使用JPA在Spring Boot中将数据存储为坐标的ArrayList,作为多边形。

huangapple go评论68阅读模式
英文:

Use JPA to store data in Array-list of coordinates as a polygon in spring-boot

问题

"boundary": {
  "type": "Polygon",
  "coordinates": [
    [
      [-73.9493302, 40.7851967],
      [-73.9538181, 40.7870864],
      [-73.9541536, 40.7872279],
      [-73.9557237, 40.7878894],
      [-73.9604089, 40.7815447],
      [-73.9539823, 40.7788333],
      [-73.9493302, 40.7851967]
    ]
  ]
}

我从API获取到了上述数据,我有用于保存所有其他数据的POJO。然而,我无法从这些坐标创建一个多边形,以便将其保存在MySQL中并在以后检索。

@JsonProperty("coordinates")
private Polygon geometry;

上述方法不起作用。我在这方面相对较新,所以任何帮助都受欢迎。


<details>
<summary>英文:</summary>

&quot;boundary&quot;: {
  &quot;type&quot;: &quot;Polygon&quot;,
  &quot;coordinates&quot;: [
    [
      [
        -73.9493302,
        40.7851967
      ],
      [
        -73.9538181,
        40.7870864
      ],
      [
        -73.9541536,
        40.7872279
      ],
      [
        -73.9557237,
        40.7878894
      ],
      [
        -73.9604089,
        40.7815447
      ],
      [
        -73.9539823,
        40.7788333
      ],
      [
        -73.9493302,
        40.7851967
      ]
    ]
  ]
}
I am getting the above data from an API and I have POJOs to save all the other data. I am however failing to create a polygon from the coordinates in order to save it in MySQL and retrieve later. 

@JsonProperty(&quot;coordinates&quot;)
private Polygon geomertry;
The above won&#39;t work. I am fairly new to this so any help is welcome.

</details>


# 答案1
**得分**: 1

你必须使用数组或`List`。

    @JsonProperty("coordinates")
    private double[][][] geomertry;

<details>
<summary>英文:</summary>

You have to use arrays or `List`. 

    @JsonProperty(&quot;coordinates&quot;)
    private double[][][] geomertry;


</details>



huangapple
  • 本文由 发表于 2020年9月28日 15:58:08
  • 转载请务必保留本文链接:https://go.coder-hub.com/64098107.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定