Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I think my question is stupid but I'm blocking. I just work with postgis ST_Line_Locate_Point function (linestring, point). to find the ends of lines. My problem is that my objects geometry type, not point. So how can I convert the geometry to geometry (point) ..?

share|improve this question
add comment

2 Answers

up vote 2 down vote accepted

To get identify a geometry's type use the GeometryType function.

SELECT GeometryType(ST_AsText('LINESTRING(1 2, 3 4, 5 6)'));

That returns 'LINESTRING'. You can put in any geometry and it will give back the type.

Expanding on @Nicklas' and @simplexios's answers, you can use the ST_DumpPoints function to return the points of a line in order. Note that this is a set-returning function which means that it returns a set of rows formed by a geometry (given by .geom) and an array of integers (given by .path).

Edit: You can also extract the GeometryType at the same time.

SELECT
    (line.a).path, ST_AsText((line.a).geom), GeometryType((line.a).geom)

FROM ( SELECT
    ST_DumpPoints(ST_AsText('LINESTRING(1 2, 3 4, 5 6)')) as a
    ) as line;

That one returns:

"{1}";"POINT(1 2)";"POINT"
"{2}";"POINT(3 4)";"POINT"
"{3}";"POINT(5 6)";"POINT"
share|improve this answer
    
thank you very much for your answer.The objects are the result of ST_Intersection and their type is geometry. I tried with GeometryType and she returned Point and Multipoint type. I try to use ST_DumpPoints and it returns a geometry_dump. But I can not apply ST_line_locate_point (geom, point) in this case. How can I access the geometry type Point by ST_DumpPoints that returns {INT},POINT? –  inesjg Mar 14 '13 at 13:11
    
I added another field to the example that gives the geometry type. Does that help? –  katahdin Mar 14 '13 at 13:29
    
Yes thank you it help me to solve the problem –  inesjg Mar 15 '13 at 9:31
    
Great! Please up vote and accept the answer. :) –  katahdin Mar 15 '13 at 9:59
add comment

If you want the end of line why not use ST_EndPoint

If it is all the points you want then use ST_DumpPoints

EDIT:

You use ST_DumpPoints like this:

SELECT (ST_DumpPoints(geom)).geom as geom from my_table;

to det the geometry part of the dump type.

share|improve this answer
    
I want exactly all the vertices of linestring in order . –  inesjg Mar 14 '13 at 10:34
1  
st_dump return path and points –  simplexio Mar 14 '13 at 10:43
    
Just i don't understant the similarity of geometry dump type and geometry point? –  inesjg Mar 14 '13 at 12:27
    
@inesjg, see update –  Nicklas Avén Mar 14 '13 at 13:01
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.