Map a PostGIS geometry point field with Hibernate on Spring Boot

前端 未结 5 654
忘掉有多难
忘掉有多难 2020-12-24 07:30

In my PostgreSQL 9.3 + PostGIS 2.1.5 I have a table PLACE with a column coordinates of type Geometry(Point,26910).

I want to m

5条回答
  •  爱一瞬间的悲伤
    2020-12-24 07:57

    The solutions above helped me to fix the problem. I simplify it so other people can understand.

    I included this library in my pom.xml:

    
      com.bedatadriven
      jackson-datatype-jts
      2.2
    
    

    This is the POJO object I used. Then I was able to get the REST call to work without the envelope error and proper coodinates.

    import com.bedatadriven.jackson.datatype.jts.serialization.GeometryDeserializer;
    import com.bedatadriven.jackson.datatype.jts.serialization.GeometrySerializer;
    import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
    import com.fasterxml.jackson.databind.annotation.JsonSerialize;
    import com.vividsolutions.jts.geom.Geometry;
    
    @Entity
    @Table(name = "boundary")
    public class Boundary {
    
        private int id;
        private Geometry geomertry;
    
        @Id
        public int getId() {
            return ogc_fid;
        }
    
        public void setId(int id) {
            this.id = id;
        }
    
        @JsonSerialize(using = GeometrySerializer.class)
        @JsonDeserialize(using = GeometryDeserializer.class)
        @Column(name = "geometry", columnDefinition = "Geometry")
        public Geometry getGeomertry() {
            return geomertry;
        }
    
        public void setGeomertry(Geometry geomertry) {
            this.geomertry = geomertry;
        }
    }
    

    My table had these 2 columns:

    id       | integer            
    geometry | geometry(Geometry,4326) | 
    

提交回复
热议问题