Hi I have a java program which I want to query my PostGIS databaes and return those nodes that are a certain distance from a given centre point.

I am not sure how to pass the centre point into the query. I have the following so far:

 public ArrayList<Node> getOsmPoiNodes(Point centrePoint) throws SQLException {

        /* 
         * Create a statement and execute a select query. 
         */ 
        Statement s = conn.createStatement(); 
        String sql = "select ST_Distance(" + centrePoint + ",way), ST_AsGeoJSON(ST_Transform(way,94326) from planet_osm_point;";

How could I pass the PostGis Point object in properly?

Also, when I am defining the distance from the centre point. Can I simply do a HAVING(ST_Distance(centrePoint, way) <= '100' where 100 would be in metres?

Thanks

asked 03 Dec '12, 16:30

srose's gravatar image

srose
146101015
accept rate: 0%


Use ST_GeomFromText:

Example: select st_geomfromtext('point(-23.4 -46.2)'::text, 93426); -- Lat/Lon/SRID

I would say that, unless some other optimizations are made, that this way of querying the database would - most likely - be VERY slow.

See: ST_Distance and ST_GeomFromText

permanent link

answered 22 Dec '12, 22:13

MCPicoli's gravatar image

MCPicoli
2.1k123046
accept rate: 24%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×531
×120
×61
×17

question asked: 03 Dec '12, 16:30

question was seen: 3,127 times

last updated: 22 Dec '12, 22:13

powered by OSQA