1

I edit my question to be more clear. the last answers were not helpful for me, maybe I did not ask well my question.

I have a file of nodes and a file of polylines. In my file polylines, I have 2 fields, "NODEA" and "NODEB". In my node file, I have a unique "identifier" field for each node. I want to retrieve with a small line of code the identifier of the node at each end of my polyline.

I try this query but no results.

select id, 
       (select id_arret 
        from noeuds n 
        where st_within(st_startpoint(p.geometry), st_buffer(n.geometry, 1))) n_deb, 
       (select id_arret 
        from noeuds n 
        where st_within(st_endpoint(p.geometry), st_buffer(n.geometry, 1))) n_fin
from polylignes p;

"My purpose is to get for each line of the multiline the start and the end node of a line and to fill in 2 colomuns of my multiline table the good node."

3
  • Do you mean to say the polyline is in PostGIS?
    – Techie_Gus
    Commented May 30, 2017 at 7:40
  • yes the polyline is in postgis database
    – hounto
    Commented May 30, 2017 at 7:51
  • to clarify: you have two tables in PostGIS (let's call them 'node' and 'polyline')? what are the values of 'NODEA' and 'NODEB' in 'polyline', are those geometries or the same identifier (for example an ID number) as the 'identifier' in your 'node' table'? and does the 'node' table have geometries or is that a plain table with other values?
    – geozelot
    Commented May 30, 2017 at 9:28

2 Answers 2

3

You need to get a geometry dump ('split' mulit geometries into their single parts) of your polyline first. Use ST_StartPoint/ST_EndPoint in conjunction with ST_Dump. A simple example:

SELECT ST_StartPoint(dmp.geom) AS sp,
       ST_EndPoint(dmp.geom) AS ep
FROM   <your_polyline_table>,
       LATERAL ST_Dump(<your_geometry_column>) AS dmp
;

EDIT (as above answer is useless after clarifying the question):

You cannot use ST_StartPoint/ST_EndPoint on MULTILINESTRINGs, these functions only work on LINESTRING geometries and that is supposedly why your query has no effect.
Getting the start/end point of a MULTILINESTRING unfortunately is no trivial task and a solution or workaround strongly depends on the actual topology of your MULTILINESTRINGs.

There is the possibility that your MULTILINESTRINGs can safely be convertet into LINESTRINGs wich would make your task way easier. Try the steps mentioned in this post and update your question with the result (e.g. if your table has actual MULTI geometries or not). Or, in case your geometries can be converted to LINESTRINGs, do that and run your query on these and see if you get any useful results.

4
  • okay, so now after you updated your question, this has become a completely different task and my answer has indeed no use for you as it is (@communitiy: do I delete the answer then?).
    – geozelot
    Commented May 30, 2017 at 9:24
  • yes the answer is deleted. have you an idea for the answer to this question? thanks
    – hounto
    Commented May 30, 2017 at 9:30
  • your other question was deleted but I meant my own answer as it is useless ,) check my comment above and maybe provide some more details
    – geozelot
    Commented May 30, 2017 at 9:35
  • i tried your query but get the geometry of the points. i'am not looking for the geometry of the points. my purpose is to get for each line of the multiline the start and the end node of a line and to fill in 2 colomuns of my multiline table the good node. sorry for my english but i'm a french. tks
    – hounto
    Commented May 30, 2017 at 9:38
0

The request was good

select id, (select id_arret from noeuds n where st_within(st_startpoint(p.geometry), st_buffer(n.geometry, 1))) n_deb, (select id_arret from noeuds n where st_within(st_endpoint(p.geometry), st_buffer(n.geometry, 1))) n_fin from polylignes p;

I followed the steps advised by https://gis.stackexchange.com/users/93656/thingumabob and I get useful results. I changed the multilinestring to linestring and it works very well.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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