作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试建立一个包含一些地理空间数据的 PostreSQL 表并进行一些空间查询。但我收到“遇到无效的字节序标志值”错误。我一直在互联网上寻找解决方案,但到目前为止还没有人完成这项工作。没有想法了。需要帮助。
场景是这样的
实体类:
import com.vividsolutions.jts.geom.Point;
import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.geom.LineString;
import com.vividsolutions.jts.geom.Polygon;
@Entity
public class PontodeInteresse implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE)
private Long id;
private String descricao;
private Point ponto;
private LineString linha;
private Geometry geometry;
private Polygon poligono;
/* Getters and setters */
我可以从代码中插入一个多边形。一切似乎都很好:
public void criarGeometry () {
PontodeInteresse ponto = new PontodeInteresse();
GeometryFactory gf = new GeometryFactory();
LinearRing shell = gf.createLinearRing(new Coordinate[] {
new Coordinate(-43.5552982, -22.8839067), new Coordinate(-43.5556591, -22.8838402),
new Coordinate(-43.5554786, -22.8829425), new Coordinate(-43.5555869, -22.8824438),
new Coordinate(-43.5552982, -22.8839067)});
LinearRing[] holes = new LinearRing[0];
Polygon polygon = gf.createPolygon(shell, holes);
ponto.setGeometry(polygon);
colocar(ponto);
}
但是,当我尝试从方法 testar()(如下)运行简单的地理空间查询时,我收到“遇到无效的字节序标志值”错误。 我已经尝试使用 @Column 并设置地理类型,但没有成功。 如果我尝试从 PgAdmin 运行此查询,则会发生完全相同的错误:
从 pontodeinteresse 中选择 ST_AsGeoJSON(ST_GeomFromWKB(geometry));
public void testar() {
try {
GeometryFactory gf = new GeometryFactory();
Point pontoDentro = gf.createPoint( new Coordinate(-43.5658, -22.8722) );
PontodeInteresse bairro = null;
bairro = (PontodeInteresse) entityManager.createQuery("select p from PontodeInteresse p where contains(p.geometry, :ponto) = true").setParameter("ponto",pontoDentro).getSingleResult();
if (bairro != null) {
resultado = "OK";
} else {
resultado = "ERRO";
}//if
} catch(Exception e) {
System.out.println(e.getMessage());
}//try
}
包含 POM 依赖项:
<dependency>
<groupId>com.vividsolutions</groupId>
<artifactId>jts</artifactId>
<version>1.13</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-spatial</artifactId>
<version>5.1.0.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.1.0.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>4.3.1.Final</version>
</dependency>
persistence.xml:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="projetoX_PU" transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>java:/jboss/datasources/projectNameDS</jta-data-source>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="hibernate.hbm2ddl.auto" value="update"/>
<property name="hibernate.dialect" value="org.hibernate.spatial.dialect.postgis.PostgisDialect"/>
</properties>
</persistence-unit>
</persistence>
提前致谢
最佳答案
请检查您的 hibernate 方言是否正确设置为 Postgis 方言。
这是一个使用 Spring boot application.properties 的例子:
spring.jpa.properties.hibernate.dialect=org.hibernate.spatial.dialect.postgis.PostgisDialect
关于java - PostgreSQL:遇到无效的字节序标志值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45951499/
序 大家好呀,我是summo,这次来写写我在上班空闲(摸鱼)的时候做的一个小网站的事。去年阿里云不是推出了个活动嘛,2核2G的云服务器一年只要99块钱,懂行的人应该知道这个价格在业界已经是非常良心了
我尝试根据给定的级别顺序(BFS 顺序)构造 BST。我知道这是可能的,但我不知道我该怎么写。问题是我必须使用 BFS 序列。所以,我不能在这里使用递归,我必须迭代地编写我的程序......我发现这有
我是一名优秀的程序员,十分优秀!