我正在尝试使用 jdbi 对 PostGIS 数据库进行空间查询,我尝试进行的查询是
@SqlQuery(
"SELECT ST_asText( way ) " +
"FROM planet_osm_roads " +
"WHERE ST_DWithin( way, ST_GeomFromText( \'POINT( :lat :lng )\', ST_SRID( way ) ), :radius )" )
public List<Road> getRoadsNearPoint( @Bind("lat") double lat, @Bind("lng") double lng, @Bind("radius") int radius );
试图做到这一点
DBI dbi = new DBI( m_dataSource );
RoadDAO dao = dbi.onDemand( RoadDAO.class );
System.out.println( dao.getRoadsNearPoint( 16839484.09, -3997003.76, 10 ) );
导致此异常
Exception in thread "main" org.skife.jdbi.v2.exceptions.UnableToExecuteStatementException: org.postgresql.util.PSQLException: ERROR: parse error - invalid geometry
Hint: "POINT( :l" <-- parse error at position 9 within geometry [statement:"SELECT ST_asText( way ) FROM planet_osm_roads WHERE ST_DWithin( way, ST_GeomFromText( 'POINT( :lat :lng )', ST_SRID( way ) ), :radius )", located:"SELECT ST_asText( way ) FROM planet_osm_roads WHERE ST_DWithin( way, ST_GeomFromText( 'POINT( :lat :lng )', ST_SRID( way ) ), :radius )", rewritten:"SELECT ST_asText( way ) FROM planet_osm_roads WHERE ST_DWithin( way, ST_GeomFromText( 'POINT( :lat :lng )', ST_SRID( way ) ), ? )", arguments:{ positional:{}, named:{lng:-3997003.76,radius:10,lat:1.683948409E7}, finder:[]}]
at org.skife.jdbi.v2.SQLStatement.internalExecute(SQLStatement.java:1334)
at org.skife.jdbi.v2.Query.fold(Query.java:173)
at org.skife.jdbi.v2.Query.list(Query.java:82)
at org.skife.jdbi.v2.sqlobject.ResultReturnThing$IterableReturningThing.result(ResultReturnThing.java:255)
at org.skife.jdbi.v2.sqlobject.ResultReturnThing.map(ResultReturnThing.java:48)
at org.skife.jdbi.v2.sqlobject.QueryHandler.invoke(QueryHandler.java:45)
at org.skife.jdbi.v2.sqlobject.SqlObject.invoke(SqlObject.java:175)
at org.skife.jdbi.v2.sqlobject.SqlObject$1.intercept(SqlObject.java:75)
at org.skife.jdbi.v2.sqlobject.CloseInternalDoNotUseThisClass$$EnhancerByCGLIB$$1c23157f.getRoadsNearPoint(<generated>)
at com.elevations.Application.main(Application.java:36)
Caused by: org.postgresql.util.PSQLException: ERROR: parse error - invalid geometry
Hint: "POINT( :l" <-- parse error at position 9 within geometry
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2182)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1911)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:173)
at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:615)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:465)
at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:458)
at org.skife.jdbi.v2.SQLStatement.internalExecute(SQLStatement.java:1328)
... 9 more
我怀疑问题是试图绑定到引号内的东西,我尝试只使用“POINT(val val)”作为我的绑定值并将其绑定到某个:point,但这也不起作用。你怎么做到这一点?