Selecting polygon id's if their centroid falls in another polygon using PostGIS?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
2
down vote

favorite












I'm trying to select polygons which centroids fall in another polygon:



enter image description here



SELECT smaller_polygons.id
FROM big_polygon
LEFT JOIN big_polygon smaller_polygons
ON ST_Within(ST_Centroid(smaller_polygons.wkb_geometry),big_polygon.wkb_geometry)


I expect 33,44 to be selected but I get id of the big polygon.



What am I doing wrong?










share|improve this question



















  • 1




    Hi BERA, it seems LEFT JOIN limits the records to the ones provided by the big_polygon table. How about CROSS JOIN?
    – Kazuhito
    1 hour ago










  • INNER JOIN seems to work with correct FROM table etc.
    – BERA
    50 mins ago














up vote
2
down vote

favorite












I'm trying to select polygons which centroids fall in another polygon:



enter image description here



SELECT smaller_polygons.id
FROM big_polygon
LEFT JOIN big_polygon smaller_polygons
ON ST_Within(ST_Centroid(smaller_polygons.wkb_geometry),big_polygon.wkb_geometry)


I expect 33,44 to be selected but I get id of the big polygon.



What am I doing wrong?










share|improve this question



















  • 1




    Hi BERA, it seems LEFT JOIN limits the records to the ones provided by the big_polygon table. How about CROSS JOIN?
    – Kazuhito
    1 hour ago










  • INNER JOIN seems to work with correct FROM table etc.
    – BERA
    50 mins ago












up vote
2
down vote

favorite









up vote
2
down vote

favorite











I'm trying to select polygons which centroids fall in another polygon:



enter image description here



SELECT smaller_polygons.id
FROM big_polygon
LEFT JOIN big_polygon smaller_polygons
ON ST_Within(ST_Centroid(smaller_polygons.wkb_geometry),big_polygon.wkb_geometry)


I expect 33,44 to be selected but I get id of the big polygon.



What am I doing wrong?










share|improve this question















I'm trying to select polygons which centroids fall in another polygon:



enter image description here



SELECT smaller_polygons.id
FROM big_polygon
LEFT JOIN big_polygon smaller_polygons
ON ST_Within(ST_Centroid(smaller_polygons.wkb_geometry),big_polygon.wkb_geometry)


I expect 33,44 to be selected but I get id of the big polygon.



What am I doing wrong?







postgis






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 1 hour ago









PolyGeo♦

52.1k1779235




52.1k1779235










asked 1 hour ago









BERA

12.4k51737




12.4k51737







  • 1




    Hi BERA, it seems LEFT JOIN limits the records to the ones provided by the big_polygon table. How about CROSS JOIN?
    – Kazuhito
    1 hour ago










  • INNER JOIN seems to work with correct FROM table etc.
    – BERA
    50 mins ago












  • 1




    Hi BERA, it seems LEFT JOIN limits the records to the ones provided by the big_polygon table. How about CROSS JOIN?
    – Kazuhito
    1 hour ago










  • INNER JOIN seems to work with correct FROM table etc.
    – BERA
    50 mins ago







1




1




Hi BERA, it seems LEFT JOIN limits the records to the ones provided by the big_polygon table. How about CROSS JOIN?
– Kazuhito
1 hour ago




Hi BERA, it seems LEFT JOIN limits the records to the ones provided by the big_polygon table. How about CROSS JOIN?
– Kazuhito
1 hour ago












INNER JOIN seems to work with correct FROM table etc.
– BERA
50 mins ago




INNER JOIN seems to work with correct FROM table etc.
– BERA
50 mins ago










1 Answer
1






active

oldest

votes

















up vote
2
down vote













This seems to work:



SELECT 
smaller_polygons.id
FROM smaller_polygons
INNER JOIN big_polygon
ON ST_Within(ST_Centroid(smaller_polygons.wkb_geometry),big_polygon.wkb_geometry)





share|improve this answer




















    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',
    convertImagesToLinks: false,
    noModals: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    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%2f299579%2fselecting-polygon-ids-if-their-centroid-falls-in-another-polygon-using-postgis%23new-answer', 'question_page');

    );

    Post as a guest






























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    2
    down vote













    This seems to work:



    SELECT 
    smaller_polygons.id
    FROM smaller_polygons
    INNER JOIN big_polygon
    ON ST_Within(ST_Centroid(smaller_polygons.wkb_geometry),big_polygon.wkb_geometry)





    share|improve this answer
























      up vote
      2
      down vote













      This seems to work:



      SELECT 
      smaller_polygons.id
      FROM smaller_polygons
      INNER JOIN big_polygon
      ON ST_Within(ST_Centroid(smaller_polygons.wkb_geometry),big_polygon.wkb_geometry)





      share|improve this answer






















        up vote
        2
        down vote










        up vote
        2
        down vote









        This seems to work:



        SELECT 
        smaller_polygons.id
        FROM smaller_polygons
        INNER JOIN big_polygon
        ON ST_Within(ST_Centroid(smaller_polygons.wkb_geometry),big_polygon.wkb_geometry)





        share|improve this answer












        This seems to work:



        SELECT 
        smaller_polygons.id
        FROM smaller_polygons
        INNER JOIN big_polygon
        ON ST_Within(ST_Centroid(smaller_polygons.wkb_geometry),big_polygon.wkb_geometry)






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 58 mins ago









        BERA

        12.4k51737




        12.4k51737



























             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f299579%2fselecting-polygon-ids-if-their-centroid-falls-in-another-polygon-using-postgis%23new-answer', 'question_page');

            );

            Post as a guest













































































            Comments

            Popular posts from this blog

            What does second last employer means? [closed]

            List of Gilmore Girls characters

            Confectionery