Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7851471
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T19:11:35+00:00 2026-06-02T19:11:35+00:00

I have such problem and I would be nice If somebody can help me.

  • 0

I have such problem and I would be nice If somebody can help me.
I have points table with GIST index. Those points don’t change in time.

I would like to fetch points that are near some given linestring.
Example: Imagine that linestring is the road and points are poi along the road.
I would like to fetch poi’s that are in 5 km distance from the given road. I would like to fetch those pois in correct order (driving order along the road). Look at the image:

image

For given road from point 1 to 5 i would like to fetch POIs that is in 5 km max from the road and in order from point 1 to 5 along the road. So the result should be:

POI_ID
1
5
6
8
9
10
12
13

This should tell me what POI I can visit during traveling along the road with minimum cost.

Does anybody have some ideas how to do it with postgres and postgis?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T19:11:37+00:00Added an answer on June 2, 2026 at 7:11 pm

    Assuming you have geometry columns geom that use a projected SRID of meters in tables road (LINESTRING) and poi (POINT), your query to find all POIs within 5 km of road (where id = 123) should be something like:

    SELECT poi.*, ST_Distance(road.geom, poi.geom)/1000.0 AS distance_km
    FROM road, poi
    WHERE road.id = 123 AND ST_DWithin(road.geom, poi.geom, 5000.0)
    ORDER BY ST_LineLocatePoint(road.geom, poi.geom),
             ST_Distance(road.geom, poi.geom);
    

    The first ORDER part with ST_LineLocatePoint uses a fraction between 0.0 and 1.0, depending where the point is along the LINESTRING. If the direction of the road is going “the wrong way”, then append DESC to reverse the order. The second ORDER part is based on distance, which could be used if the point is slightly past the start/end of the LINESTRING (where ST_LineLocatePoint would return 0.0 or 1.0, respectively).

    This query might also work if you are using the geography type with Long/Latitude values, since it automagically calculates metres — not degrees. Check out docs for more:

    • ST_Distance
    • ST_DWithin
    • ST_LineLocatePoint (or ST_Line_Locate_Point for older versions of PostGIS)
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have such a basic problem in Delphi,I can't solve it. My Code: Note:DataR
I have some problem whith such mysql_query INSERT INTO table VALUES ('', CURDATE()-1) why
I have a problem such that i have zip files uploaded from forms and
I do not have problem as such but I am quite new to Ruby.
I have big problem with my small database(DERBY) application. I am getting such an
I have some complicated, problem to be solved. Now I need to write such
I have another thread asking help on missing zlib. With the nice help the
have such zend query: $select = $this->_table ->select() ->where('title LIKE ?', '%'.$searchWord.'%') ->where('description LIKE
I have such a form: <form id=new-application method=post enctype=multipart/form-data data-remote=true action=/inv/claims?locale=uk accept-charset=UTF-8> <a rel=nofollow
I have such code: <h:inputText id=input value=#{bean.input}> <f:convertNumber /> <rich:ajaxValidator event=onblur /> </h:inputText> I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.