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 31753
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T13:39:16+00:00 2026-05-10T13:39:16+00:00

In postgis, is the ST_GeomFromText call very expensive? I ask mostly because I have

  • 0

In postgis, is the ST_GeomFromText call very expensive? I ask mostly because I have a frequently called query that attempts to find the point that is nearest another point that matches some criteria, and which is also within a certain distance of that other point, and the way I currently wrote it, it’s doing the same ST_GeomFromText twice:

 $findNearIDMatchStmt = $postconn->prepare(     'SELECT     internalid ' .     'FROM       waypoint ' .     'WHERE      id = ? AND ' .     '           category = ? AND '.     '           (b.category in (1, 3) OR type like ?) AND '.     '           ST_DWithin(point, ST_GeomFromText(?,' . SRID .     '           ),'.  SMALL_EPSILON . ') ' .     '           ORDER BY ST_Distance(point, ST_GeomFromText(?,', SRID .     '           )) ' .     '           LIMIT 1'); 

Is there a better way to re-write this?

Slightly OT: In the preview screen, all my underscores are being rendered as & # 9 5 ; – I hope that’s not going to show up that way in the post.

  • 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. 2026-05-10T13:39:17+00:00Added an answer on May 10, 2026 at 1:39 pm

    I don’t believe ST_GeomFromText() is particularly expensive, although in the past I’ve optimized PostGIS queries by creating a function, declaring a variable and then assigning the result of ST_GeomFromText to the variable.

    Have you tried checking the execution plan for you query with a variety of different parameters because that should give you a definite idea of which bits of the query are taking the time?

    I’m guessing most of the execution time will be in the calls to ST_DWithin() and ST_Distance(), although if the id and category columns aren’t indexed then it might be doing some interesting table scanning.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to build a PostGIS query that uses an alias of the JOIN
I'm using postgres (postgis) and i want to perform a query that returns all
We have a table that has millions of rows with PostGIS geometries in them.
I'm using Rails 3.1, and I have tables with the PostGIS geometry datatype. These
I have a PostgreSQL\PostGIS spatial database which contains Hebrew text columns. The system runs
EDIT: I have been using Postgres with PostGIS for a few months now, and
I'm running Geodjango/Postgres 9.1/PostGIS and I'm trying to get the following query (and others
I have a PostgreSQL database with PostGIS functions loaded into it. I would like
I have an instance in Engineyard and I want to install postgis. I tried
I have a data file in CSV format that has the some data like

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.