NOTICE: help.openstreetmap.org is no longer in use from 1st March 2024. Please use the OpenStreetMap Community Forum

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
161101016
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.2k133047
accept rate: 24%

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:

×710
×134
×76
×18

question asked: 03 Dec '12, 16:30

question was seen: 4,722 times

last updated: 22 Dec '12, 22:13

NOTICE: help.openstreetmap.org is no longer in use from 1st March 2024. Please use the OpenStreetMap Community Forum