PostGIS st_makeline extra columns in resultproblem transforming pgr route to a line - unexpected extra lines from St_MakeLinePostGIS Group By ErrorOrder by geometry columnsCreate a “wide” table recording all overlaps between polygons in PostGISSt_ClosestPoint within St_MakeLine Query problemInsert geometry into new postgis table using python 2PostGIS: Update table with st_geometryfromtextpsycopg2 not working because column “geom” does not existPostGIS MakeLine issueCreate continuous line network using PostgreSQL

A word that means "blending into a community too much"

Why are trash cans referred to as "zafacón" in Puerto Rico?

Is it safe to change the harddrive power feature so that it never turns off?

sed + add word before string only if not exists

Why didn't Voldemort recognize that Dumbledore was affected by his curse?

Warning about needing "authorization" when booking ticket

How can I get an unreasonable manager to approve time off?

Why am I getting a strange double quote (“) in Open Office instead of the ordinary one (")?

Is it expected that a reader will skip parts of what you write?

Is White controlling this game?

CSV how to trim values to 2 places in multiple columns using UNIX

English word for "product of tinkering"

How to safely destroy (a large quantity of) valid checks?

If I leave the US through an airport, do I have to return through the same airport?

Can I use trees and other climbable objects to get on Tenser's Floating Disk?

Extreme flexible working hours: how to get to know people and activities?

Russian word for a male zebra

Who are the Missing Members of this Noble Family?

Print lines between start & end pattern, but if end pattern does not exist, don't print

ed command: Delete from line 1 until the first blank line

What is the maximum number of net attacks that one can make in a round?

Meaning of 'lose their grip on the groins of their followers'

Determining fair price for profitable mobile app business

How to communicate to my GM that not being allowed to use stealth isn't fun for me?



PostGIS st_makeline extra columns in result


problem transforming pgr route to a line - unexpected extra lines from St_MakeLinePostGIS Group By ErrorOrder by geometry columnsCreate a “wide” table recording all overlaps between polygons in PostGISSt_ClosestPoint within St_MakeLine Query problemInsert geometry into new postgis table using python 2PostGIS: Update table with st_geometryfromtextpsycopg2 not working because column “geom” does not existPostGIS MakeLine issueCreate continuous line network using PostgreSQL






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








3















From a table of point data, there are some groups of points that can define a line (cross sections of a water course). 'cross_section' is the name of the table with the point data, geometrypoint the column with the geometry. 'code_sequence_nr' is the column that specifies the point sequence, so it becomes a nice line.
To make lines from groups of point data I have the following query:



CREATE TABLE cross_section_lines AS
SELECT st_makeline(geometrypoint) as cross_section,
cross_section.profile_code,
cross_section.administrative_area_id,
FROM (SELECT geometrypoint, profile_code, administrative_area_id
FROM cross_section
ORDER BY code_sequence_nr) cross_section
GROUP BY cross_section.profile_code, cross_section.administrative_area_id;


Now I need more information than the columns used for grouping, but if I add a column like this:



CREATE TABLE cross_section_lines AS
SELECT st_makeline(geometrypoint) as cross_section,
cross_section.profile_code,
cross_section.administrative_area_id,
cross_section.profile_type_id
FROM (SELECT geometrypoint, profile_code, administrative_area_id
FROM cross_section
ORDER BY code_sequence_nr) cross_section
GROUP BY cross_section.profile_code, cross_section.administrative_area_id;


The following error occurs:



ProgrammingError: (psycopg2.errors.UndefinedColumn) column cross_section.profile_type_id does not exist


But that column is certainly there. Now how do I add the profile type (and other usefull columns) to the resulting table that is created?










share|improve this question






























    3















    From a table of point data, there are some groups of points that can define a line (cross sections of a water course). 'cross_section' is the name of the table with the point data, geometrypoint the column with the geometry. 'code_sequence_nr' is the column that specifies the point sequence, so it becomes a nice line.
    To make lines from groups of point data I have the following query:



    CREATE TABLE cross_section_lines AS
    SELECT st_makeline(geometrypoint) as cross_section,
    cross_section.profile_code,
    cross_section.administrative_area_id,
    FROM (SELECT geometrypoint, profile_code, administrative_area_id
    FROM cross_section
    ORDER BY code_sequence_nr) cross_section
    GROUP BY cross_section.profile_code, cross_section.administrative_area_id;


    Now I need more information than the columns used for grouping, but if I add a column like this:



    CREATE TABLE cross_section_lines AS
    SELECT st_makeline(geometrypoint) as cross_section,
    cross_section.profile_code,
    cross_section.administrative_area_id,
    cross_section.profile_type_id
    FROM (SELECT geometrypoint, profile_code, administrative_area_id
    FROM cross_section
    ORDER BY code_sequence_nr) cross_section
    GROUP BY cross_section.profile_code, cross_section.administrative_area_id;


    The following error occurs:



    ProgrammingError: (psycopg2.errors.UndefinedColumn) column cross_section.profile_type_id does not exist


    But that column is certainly there. Now how do I add the profile type (and other usefull columns) to the resulting table that is created?










    share|improve this question


























      3












      3








      3








      From a table of point data, there are some groups of points that can define a line (cross sections of a water course). 'cross_section' is the name of the table with the point data, geometrypoint the column with the geometry. 'code_sequence_nr' is the column that specifies the point sequence, so it becomes a nice line.
      To make lines from groups of point data I have the following query:



      CREATE TABLE cross_section_lines AS
      SELECT st_makeline(geometrypoint) as cross_section,
      cross_section.profile_code,
      cross_section.administrative_area_id,
      FROM (SELECT geometrypoint, profile_code, administrative_area_id
      FROM cross_section
      ORDER BY code_sequence_nr) cross_section
      GROUP BY cross_section.profile_code, cross_section.administrative_area_id;


      Now I need more information than the columns used for grouping, but if I add a column like this:



      CREATE TABLE cross_section_lines AS
      SELECT st_makeline(geometrypoint) as cross_section,
      cross_section.profile_code,
      cross_section.administrative_area_id,
      cross_section.profile_type_id
      FROM (SELECT geometrypoint, profile_code, administrative_area_id
      FROM cross_section
      ORDER BY code_sequence_nr) cross_section
      GROUP BY cross_section.profile_code, cross_section.administrative_area_id;


      The following error occurs:



      ProgrammingError: (psycopg2.errors.UndefinedColumn) column cross_section.profile_type_id does not exist


      But that column is certainly there. Now how do I add the profile type (and other usefull columns) to the resulting table that is created?










      share|improve this question
















      From a table of point data, there are some groups of points that can define a line (cross sections of a water course). 'cross_section' is the name of the table with the point data, geometrypoint the column with the geometry. 'code_sequence_nr' is the column that specifies the point sequence, so it becomes a nice line.
      To make lines from groups of point data I have the following query:



      CREATE TABLE cross_section_lines AS
      SELECT st_makeline(geometrypoint) as cross_section,
      cross_section.profile_code,
      cross_section.administrative_area_id,
      FROM (SELECT geometrypoint, profile_code, administrative_area_id
      FROM cross_section
      ORDER BY code_sequence_nr) cross_section
      GROUP BY cross_section.profile_code, cross_section.administrative_area_id;


      Now I need more information than the columns used for grouping, but if I add a column like this:



      CREATE TABLE cross_section_lines AS
      SELECT st_makeline(geometrypoint) as cross_section,
      cross_section.profile_code,
      cross_section.administrative_area_id,
      cross_section.profile_type_id
      FROM (SELECT geometrypoint, profile_code, administrative_area_id
      FROM cross_section
      ORDER BY code_sequence_nr) cross_section
      GROUP BY cross_section.profile_code, cross_section.administrative_area_id;


      The following error occurs:



      ProgrammingError: (psycopg2.errors.UndefinedColumn) column cross_section.profile_type_id does not exist


      But that column is certainly there. Now how do I add the profile type (and other usefull columns) to the resulting table that is created?







      python postgis postgresql






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited May 23 at 11:15









      JGH

      14.4k21439




      14.4k21439










      asked May 23 at 9:47









      Rob RikkenRob Rikken

      183




      183




















          2 Answers
          2






          active

          oldest

          votes


















          2














          Since you don't want the column in the GROUP BY section, you would have to aggregate the values of this column.



          For instance, you can use STRING_AGG and possibly keep only the distinct values via the DISTINCT keyword.
          You may have to cast the column to text as well



          SELECT id, string_agg(distinct colA::text, ',')
          FROM mytable
          GROUP BY id;





          share|improve this answer























          • I've decided to solve my problem in a different way, using multiple lines that are noded. But this answer solves my question well.

            – Rob Rikken
            May 23 at 14:24


















          3














          profile_type_id is not in your select statement so the outer select can't see it. You need to try something like:



          CREATE TABLE cross_section_lines AS
          SELECT st_makeline(geometrypoint) as cross_section,
          cross_section.profile_code,
          cross_section.administrative_area_id,
          cross_section.profile_type_id
          FROM (SELECT geometrypoint, profile_code, administrative_area_id, profile_type_id
          FROM cross_section
          ORDER BY code_sequence_nr) cross_section
          GROUP BY cross_section.profile_code, cross_section.administrative_area_id, cross_section.profile_type_id;





          share|improve this answer

























          • Unfortunately that didn't do the trick: ProgrammingError: (psycopg2.errors.GroupingError) column "cross_section.profile_type_id" must appear in the GROUP BY clause or be used in an aggregate function

            – Rob Rikken
            May 23 at 9:57












          • That would work for the profile code, because that's the same for the whole profile. But there are other columns that are not the same for the whole profile. In that case the line would be split in however many groups there are of that item.

            – Rob Rikken
            May 23 at 10:06






          • 2





            In this case, you need to add to your question the INPUT - structure of your source table and an example of its content and OUTPUT what you would like to get...

            – Cyril
            May 23 at 10:11











          • That's probably true. This is my first question on stackexchange, so I was not really sure how much information people need to figure out a question :) .

            – Rob Rikken
            May 23 at 12:12











          Your Answer








          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "79"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f323680%2fpostgis-st-makeline-extra-columns-in-result%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          2














          Since you don't want the column in the GROUP BY section, you would have to aggregate the values of this column.



          For instance, you can use STRING_AGG and possibly keep only the distinct values via the DISTINCT keyword.
          You may have to cast the column to text as well



          SELECT id, string_agg(distinct colA::text, ',')
          FROM mytable
          GROUP BY id;





          share|improve this answer























          • I've decided to solve my problem in a different way, using multiple lines that are noded. But this answer solves my question well.

            – Rob Rikken
            May 23 at 14:24















          2














          Since you don't want the column in the GROUP BY section, you would have to aggregate the values of this column.



          For instance, you can use STRING_AGG and possibly keep only the distinct values via the DISTINCT keyword.
          You may have to cast the column to text as well



          SELECT id, string_agg(distinct colA::text, ',')
          FROM mytable
          GROUP BY id;





          share|improve this answer























          • I've decided to solve my problem in a different way, using multiple lines that are noded. But this answer solves my question well.

            – Rob Rikken
            May 23 at 14:24













          2












          2








          2







          Since you don't want the column in the GROUP BY section, you would have to aggregate the values of this column.



          For instance, you can use STRING_AGG and possibly keep only the distinct values via the DISTINCT keyword.
          You may have to cast the column to text as well



          SELECT id, string_agg(distinct colA::text, ',')
          FROM mytable
          GROUP BY id;





          share|improve this answer













          Since you don't want the column in the GROUP BY section, you would have to aggregate the values of this column.



          For instance, you can use STRING_AGG and possibly keep only the distinct values via the DISTINCT keyword.
          You may have to cast the column to text as well



          SELECT id, string_agg(distinct colA::text, ',')
          FROM mytable
          GROUP BY id;






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered May 23 at 11:14









          JGHJGH

          14.4k21439




          14.4k21439












          • I've decided to solve my problem in a different way, using multiple lines that are noded. But this answer solves my question well.

            – Rob Rikken
            May 23 at 14:24

















          • I've decided to solve my problem in a different way, using multiple lines that are noded. But this answer solves my question well.

            – Rob Rikken
            May 23 at 14:24
















          I've decided to solve my problem in a different way, using multiple lines that are noded. But this answer solves my question well.

          – Rob Rikken
          May 23 at 14:24





          I've decided to solve my problem in a different way, using multiple lines that are noded. But this answer solves my question well.

          – Rob Rikken
          May 23 at 14:24













          3














          profile_type_id is not in your select statement so the outer select can't see it. You need to try something like:



          CREATE TABLE cross_section_lines AS
          SELECT st_makeline(geometrypoint) as cross_section,
          cross_section.profile_code,
          cross_section.administrative_area_id,
          cross_section.profile_type_id
          FROM (SELECT geometrypoint, profile_code, administrative_area_id, profile_type_id
          FROM cross_section
          ORDER BY code_sequence_nr) cross_section
          GROUP BY cross_section.profile_code, cross_section.administrative_area_id, cross_section.profile_type_id;





          share|improve this answer

























          • Unfortunately that didn't do the trick: ProgrammingError: (psycopg2.errors.GroupingError) column "cross_section.profile_type_id" must appear in the GROUP BY clause or be used in an aggregate function

            – Rob Rikken
            May 23 at 9:57












          • That would work for the profile code, because that's the same for the whole profile. But there are other columns that are not the same for the whole profile. In that case the line would be split in however many groups there are of that item.

            – Rob Rikken
            May 23 at 10:06






          • 2





            In this case, you need to add to your question the INPUT - structure of your source table and an example of its content and OUTPUT what you would like to get...

            – Cyril
            May 23 at 10:11











          • That's probably true. This is my first question on stackexchange, so I was not really sure how much information people need to figure out a question :) .

            – Rob Rikken
            May 23 at 12:12















          3














          profile_type_id is not in your select statement so the outer select can't see it. You need to try something like:



          CREATE TABLE cross_section_lines AS
          SELECT st_makeline(geometrypoint) as cross_section,
          cross_section.profile_code,
          cross_section.administrative_area_id,
          cross_section.profile_type_id
          FROM (SELECT geometrypoint, profile_code, administrative_area_id, profile_type_id
          FROM cross_section
          ORDER BY code_sequence_nr) cross_section
          GROUP BY cross_section.profile_code, cross_section.administrative_area_id, cross_section.profile_type_id;





          share|improve this answer

























          • Unfortunately that didn't do the trick: ProgrammingError: (psycopg2.errors.GroupingError) column "cross_section.profile_type_id" must appear in the GROUP BY clause or be used in an aggregate function

            – Rob Rikken
            May 23 at 9:57












          • That would work for the profile code, because that's the same for the whole profile. But there are other columns that are not the same for the whole profile. In that case the line would be split in however many groups there are of that item.

            – Rob Rikken
            May 23 at 10:06






          • 2





            In this case, you need to add to your question the INPUT - structure of your source table and an example of its content and OUTPUT what you would like to get...

            – Cyril
            May 23 at 10:11











          • That's probably true. This is my first question on stackexchange, so I was not really sure how much information people need to figure out a question :) .

            – Rob Rikken
            May 23 at 12:12













          3












          3








          3







          profile_type_id is not in your select statement so the outer select can't see it. You need to try something like:



          CREATE TABLE cross_section_lines AS
          SELECT st_makeline(geometrypoint) as cross_section,
          cross_section.profile_code,
          cross_section.administrative_area_id,
          cross_section.profile_type_id
          FROM (SELECT geometrypoint, profile_code, administrative_area_id, profile_type_id
          FROM cross_section
          ORDER BY code_sequence_nr) cross_section
          GROUP BY cross_section.profile_code, cross_section.administrative_area_id, cross_section.profile_type_id;





          share|improve this answer















          profile_type_id is not in your select statement so the outer select can't see it. You need to try something like:



          CREATE TABLE cross_section_lines AS
          SELECT st_makeline(geometrypoint) as cross_section,
          cross_section.profile_code,
          cross_section.administrative_area_id,
          cross_section.profile_type_id
          FROM (SELECT geometrypoint, profile_code, administrative_area_id, profile_type_id
          FROM cross_section
          ORDER BY code_sequence_nr) cross_section
          GROUP BY cross_section.profile_code, cross_section.administrative_area_id, cross_section.profile_type_id;






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited May 23 at 10:21

























          answered May 23 at 9:51









          Ian TurtonIan Turton

          51.3k548121




          51.3k548121












          • Unfortunately that didn't do the trick: ProgrammingError: (psycopg2.errors.GroupingError) column "cross_section.profile_type_id" must appear in the GROUP BY clause or be used in an aggregate function

            – Rob Rikken
            May 23 at 9:57












          • That would work for the profile code, because that's the same for the whole profile. But there are other columns that are not the same for the whole profile. In that case the line would be split in however many groups there are of that item.

            – Rob Rikken
            May 23 at 10:06






          • 2





            In this case, you need to add to your question the INPUT - structure of your source table and an example of its content and OUTPUT what you would like to get...

            – Cyril
            May 23 at 10:11











          • That's probably true. This is my first question on stackexchange, so I was not really sure how much information people need to figure out a question :) .

            – Rob Rikken
            May 23 at 12:12

















          • Unfortunately that didn't do the trick: ProgrammingError: (psycopg2.errors.GroupingError) column "cross_section.profile_type_id" must appear in the GROUP BY clause or be used in an aggregate function

            – Rob Rikken
            May 23 at 9:57












          • That would work for the profile code, because that's the same for the whole profile. But there are other columns that are not the same for the whole profile. In that case the line would be split in however many groups there are of that item.

            – Rob Rikken
            May 23 at 10:06






          • 2





            In this case, you need to add to your question the INPUT - structure of your source table and an example of its content and OUTPUT what you would like to get...

            – Cyril
            May 23 at 10:11











          • That's probably true. This is my first question on stackexchange, so I was not really sure how much information people need to figure out a question :) .

            – Rob Rikken
            May 23 at 12:12
















          Unfortunately that didn't do the trick: ProgrammingError: (psycopg2.errors.GroupingError) column "cross_section.profile_type_id" must appear in the GROUP BY clause or be used in an aggregate function

          – Rob Rikken
          May 23 at 9:57






          Unfortunately that didn't do the trick: ProgrammingError: (psycopg2.errors.GroupingError) column "cross_section.profile_type_id" must appear in the GROUP BY clause or be used in an aggregate function

          – Rob Rikken
          May 23 at 9:57














          That would work for the profile code, because that's the same for the whole profile. But there are other columns that are not the same for the whole profile. In that case the line would be split in however many groups there are of that item.

          – Rob Rikken
          May 23 at 10:06





          That would work for the profile code, because that's the same for the whole profile. But there are other columns that are not the same for the whole profile. In that case the line would be split in however many groups there are of that item.

          – Rob Rikken
          May 23 at 10:06




          2




          2





          In this case, you need to add to your question the INPUT - structure of your source table and an example of its content and OUTPUT what you would like to get...

          – Cyril
          May 23 at 10:11





          In this case, you need to add to your question the INPUT - structure of your source table and an example of its content and OUTPUT what you would like to get...

          – Cyril
          May 23 at 10:11













          That's probably true. This is my first question on stackexchange, so I was not really sure how much information people need to figure out a question :) .

          – Rob Rikken
          May 23 at 12:12





          That's probably true. This is my first question on stackexchange, so I was not really sure how much information people need to figure out a question :) .

          – Rob Rikken
          May 23 at 12:12

















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Geographic Information Systems Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f323680%2fpostgis-st-makeline-extra-columns-in-result%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          How to write a 12-bar blues melodyI-IV-V blues progressionHow to play the bridges in a standard blues progressionHow does Gdim7 fit in C# minor?question on a certain chord progressionMusicology of Melody12 bar blues, spread rhythm: alternative to 6th chord to avoid finger stretchChord progressions/ Root key/ MelodiesHow to put chords (POP-EDM) under a given lead vocal melody (starting from a good knowledge in music theory)Are there “rules” for improvising with the minor pentatonic scale over 12-bar shuffle?Confusion about blues scale and chords

          What if the end-user didn't have the required library?What is setup.py?What is a clean, pythonic way to have multiple constructors in Python?What does Ruby have that Python doesn't, and vice versa?What is the reason for having '//' in Python?How do I create a namespace package in Python?How to package shared objects that python modules depend on?setuptools vs. distutils: why is distutils still a thing?Navigation in Windows 10 vs code not going to virtualenv library when the same library is installed at user levelPython create package for local usePackaging a project that uses multiple python versionsWhy is permission denied on pip install except for when “--user” is included at end of command?

          Esgonzo ibérico Índice Descrición Distribución Hábitat Ameazas Notas Véxase tamén "Acerca dos nomes dos anfibios e réptiles galegos""Chalcides bedriagai"Chalcides bedriagai en Carrascal, L. M. Salvador, A. (Eds). Enciclopedia virtual de los vertebrados españoles. Museo Nacional de Ciencias Naturales, Madrid. España.Fotos