Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Mysql - distance from a point

Status
Not open for further replies.

dbrb2

Instructor
Jul 19, 2004
121
GB
Hello,

I'm trying to get my head around MySQL GIS functionality. Can anyone tell me why the below query, lifted from a mysql example page, returns NULL whenever it is run? I am trying to use something similar to query a table based on distance from a point.

Code:
SELECT ROUND(GLength(
	LineStringFromWKB(
		LineString(
			AsBinary(GeomFromText('POINT(5571 3510)')),
			AsBinary(GeomFromText('POINT(0 3510)'))
			  )
			 )
	      )
      )
FROM dual;

Cheers,

Ben
 
I don't know why, but the LineString function does not seem to like it when you feed it the output of AsBinary. So the following seems to work:
Code:
SELECT ROUND(GLength(
    LineStringFromWKB(
        LineString(
            GeomFromText('POINT(5571 3510)'),
            GeomFromText('POINT(0 3510)')
              )
             )
          )
      )
FROM dual;

Note: I don't know anything about the spatial functions. I just ran the query from the bottom (GeomFromText, then AsBinary, etc) and looked where it went wrong. One thing to remember is NULL propagation: whenever a value is NULL, most functions with that value as parameter also return NULL.

+++ Despite being wrong in every important aspect, that is a very good analogy +++
Hex (in Darwin's Watch)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top