PostGIS function to move a polygon to centre over new point coordinatesBest way to store polygon geospatial...

I am a loser when it comes to jobs, what possibilities do I have?

Can a Hydra make multiple opportunity attacks at once?

Why write a book when there's a movie in my head?

If I have Haste cast on me, does it reduce the casting time for my spells that normally take more than a turn to cast?

Buying a "Used" Router

Is there a way to pause a running process on Linux systems and resume later?

Why can all solutions to the simple harmonic motion equation be written in terms of sines and cosines?

How bad is a Computer Science course that doesn't teach Design Patterns?

bash aliases do not expand even with shopt expand_aliases

Question: "Are you hungry?" Answer: "I feel like eating."

Exploding Numbers

Is layered encryption more secure than long passwords?

What if you do not believe in the project benefits?

Was the Soviet N1 really capable of sending 9.6 GB/s of telemetry?

Dot product with a constant

Do error bars on probabilities have any meaning?

Spells that would be effective against a Modern Day army but would NOT destroy a fantasy one

Do the speed limit reductions due to pollution also apply to electric cars in France?

Is the tritone (A4 / d5) still banned in Roman Catholic music?

3D buried view in Tikz

How can I portray body horror and still be sensitive to people with disabilities?

What is formjacking?

Is it possible to detect 100% of SQLi with a simple regex?

Is it Safe to Plug an Extension Cord Into a Power Strip?



PostGIS function to move a polygon to centre over new point coordinates


Best way to store polygon geospatial data in postgreSQL?Postgis create polygon extent/convex hull from spatial tablePolygon centroid coordinates update errorProblem with PostgreSQL View layer in QGISInconsistent results in ST_DistanceCreating shapes/lines from geo coordinates in postgisProgrammatically move points in front of building polygons in PostGISCreate a Rectangle around a point in PostGISChecking if point lies with GeoJSON Polygon in PostgreSQL?Point Data to journey linestrings - PostGIS













2















Background:



(Note: I am trying to do as much of this as possible in PostGIS/PostgreSQL)



I have a PostgreSQL table containing location data of an aircraft in orbit around a city. Every second a new row is added with new position data.



From this table I have created a view which shows a constantly updating point of only the current position. This view therefore contains only one row.



The Task:



I have created a custom polygon in a different table, which acts as a buffer around the current position point. I want to reposition/move this polygon to always be centred over the constantly updating current position coordinates. Does anyone know how to do this? I have already experimented with rotate and scale. I am happy with them. It is moving the polygon that is confusing me.



I have tried creating a view that uses ST_Translate for the polygon, however from my understanding, this function only moves coordinates by a fixed amount from the origin. It doesn’t allow me to specify exactly what lon lat coordinates I want it to move to. Does anyone know a function/how to move a polygon to new coordinates, centred on a point? Again, I am trying to achieve this from PostGIS.










share|improve this question









New contributor




Demus is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
















  • 1





    ST_Translate moves a geometry by a specified amount in x, y and, optionally, z directions. So, to calculate how much you need to move the polygon, calculate the change in x and y between your new point and the centroid of the polygon

    – John Powell
    1 hour ago
















2















Background:



(Note: I am trying to do as much of this as possible in PostGIS/PostgreSQL)



I have a PostgreSQL table containing location data of an aircraft in orbit around a city. Every second a new row is added with new position data.



From this table I have created a view which shows a constantly updating point of only the current position. This view therefore contains only one row.



The Task:



I have created a custom polygon in a different table, which acts as a buffer around the current position point. I want to reposition/move this polygon to always be centred over the constantly updating current position coordinates. Does anyone know how to do this? I have already experimented with rotate and scale. I am happy with them. It is moving the polygon that is confusing me.



I have tried creating a view that uses ST_Translate for the polygon, however from my understanding, this function only moves coordinates by a fixed amount from the origin. It doesn’t allow me to specify exactly what lon lat coordinates I want it to move to. Does anyone know a function/how to move a polygon to new coordinates, centred on a point? Again, I am trying to achieve this from PostGIS.










share|improve this question









New contributor




Demus is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
















  • 1





    ST_Translate moves a geometry by a specified amount in x, y and, optionally, z directions. So, to calculate how much you need to move the polygon, calculate the change in x and y between your new point and the centroid of the polygon

    – John Powell
    1 hour ago














2












2








2








Background:



(Note: I am trying to do as much of this as possible in PostGIS/PostgreSQL)



I have a PostgreSQL table containing location data of an aircraft in orbit around a city. Every second a new row is added with new position data.



From this table I have created a view which shows a constantly updating point of only the current position. This view therefore contains only one row.



The Task:



I have created a custom polygon in a different table, which acts as a buffer around the current position point. I want to reposition/move this polygon to always be centred over the constantly updating current position coordinates. Does anyone know how to do this? I have already experimented with rotate and scale. I am happy with them. It is moving the polygon that is confusing me.



I have tried creating a view that uses ST_Translate for the polygon, however from my understanding, this function only moves coordinates by a fixed amount from the origin. It doesn’t allow me to specify exactly what lon lat coordinates I want it to move to. Does anyone know a function/how to move a polygon to new coordinates, centred on a point? Again, I am trying to achieve this from PostGIS.










share|improve this question









New contributor




Demus is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












Background:



(Note: I am trying to do as much of this as possible in PostGIS/PostgreSQL)



I have a PostgreSQL table containing location data of an aircraft in orbit around a city. Every second a new row is added with new position data.



From this table I have created a view which shows a constantly updating point of only the current position. This view therefore contains only one row.



The Task:



I have created a custom polygon in a different table, which acts as a buffer around the current position point. I want to reposition/move this polygon to always be centred over the constantly updating current position coordinates. Does anyone know how to do this? I have already experimented with rotate and scale. I am happy with them. It is moving the polygon that is confusing me.



I have tried creating a view that uses ST_Translate for the polygon, however from my understanding, this function only moves coordinates by a fixed amount from the origin. It doesn’t allow me to specify exactly what lon lat coordinates I want it to move to. Does anyone know a function/how to move a polygon to new coordinates, centred on a point? Again, I am trying to achieve this from PostGIS.







qgis postgis postgresql polygon move






share|improve this question









New contributor




Demus is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




Demus is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited 42 mins ago









Vince

14.6k32748




14.6k32748






New contributor




Demus is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 1 hour ago









DemusDemus

111




111




New contributor




Demus is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Demus is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Demus is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.








  • 1





    ST_Translate moves a geometry by a specified amount in x, y and, optionally, z directions. So, to calculate how much you need to move the polygon, calculate the change in x and y between your new point and the centroid of the polygon

    – John Powell
    1 hour ago














  • 1





    ST_Translate moves a geometry by a specified amount in x, y and, optionally, z directions. So, to calculate how much you need to move the polygon, calculate the change in x and y between your new point and the centroid of the polygon

    – John Powell
    1 hour ago








1




1





ST_Translate moves a geometry by a specified amount in x, y and, optionally, z directions. So, to calculate how much you need to move the polygon, calculate the change in x and y between your new point and the centroid of the polygon

– John Powell
1 hour ago





ST_Translate moves a geometry by a specified amount in x, y and, optionally, z directions. So, to calculate how much you need to move the polygon, calculate the change in x and y between your new point and the centroid of the polygon

– John Powell
1 hour ago










1 Answer
1






active

oldest

votes


















3














The easiest would be to have your polygon centered on (0;0) and to use st_translate using the target point X;Y as the delta X and delta Y.



Using any polygon, you would compute the delta by removing the polygon centroid X and Y from the target point X and Y:



WITH pt AS (SELECT 'point(-75.5 47.2)'::geometry geom),
poly AS (SELECT 'polygon((-70 41, -71 41, -71 40,-70 40, -70 41))'::geometry geom)
SELECT st_asText(
ST_TRANSLATE(
poly.geom,
st_x(pt.geom) - st_x(st_centroid(poly.geom)),
st_y(pt.geom) - st_y(st_centroid(poly.geom))
)
)
FROM pt, poly;

st_astext
---------------------------------------------------------
POLYGON((-75 47.7,-76 47.7,-76 46.7,-75 46.7,-75 47.7))
(1 row)





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',
    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
    });


    }
    });






    Demus is a new contributor. Be nice, and check out our Code of Conduct.










    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f313197%2fpostgis-function-to-move-a-polygon-to-centre-over-new-point-coordinates%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    3














    The easiest would be to have your polygon centered on (0;0) and to use st_translate using the target point X;Y as the delta X and delta Y.



    Using any polygon, you would compute the delta by removing the polygon centroid X and Y from the target point X and Y:



    WITH pt AS (SELECT 'point(-75.5 47.2)'::geometry geom),
    poly AS (SELECT 'polygon((-70 41, -71 41, -71 40,-70 40, -70 41))'::geometry geom)
    SELECT st_asText(
    ST_TRANSLATE(
    poly.geom,
    st_x(pt.geom) - st_x(st_centroid(poly.geom)),
    st_y(pt.geom) - st_y(st_centroid(poly.geom))
    )
    )
    FROM pt, poly;

    st_astext
    ---------------------------------------------------------
    POLYGON((-75 47.7,-76 47.7,-76 46.7,-75 46.7,-75 47.7))
    (1 row)





    share|improve this answer




























      3














      The easiest would be to have your polygon centered on (0;0) and to use st_translate using the target point X;Y as the delta X and delta Y.



      Using any polygon, you would compute the delta by removing the polygon centroid X and Y from the target point X and Y:



      WITH pt AS (SELECT 'point(-75.5 47.2)'::geometry geom),
      poly AS (SELECT 'polygon((-70 41, -71 41, -71 40,-70 40, -70 41))'::geometry geom)
      SELECT st_asText(
      ST_TRANSLATE(
      poly.geom,
      st_x(pt.geom) - st_x(st_centroid(poly.geom)),
      st_y(pt.geom) - st_y(st_centroid(poly.geom))
      )
      )
      FROM pt, poly;

      st_astext
      ---------------------------------------------------------
      POLYGON((-75 47.7,-76 47.7,-76 46.7,-75 46.7,-75 47.7))
      (1 row)





      share|improve this answer


























        3












        3








        3







        The easiest would be to have your polygon centered on (0;0) and to use st_translate using the target point X;Y as the delta X and delta Y.



        Using any polygon, you would compute the delta by removing the polygon centroid X and Y from the target point X and Y:



        WITH pt AS (SELECT 'point(-75.5 47.2)'::geometry geom),
        poly AS (SELECT 'polygon((-70 41, -71 41, -71 40,-70 40, -70 41))'::geometry geom)
        SELECT st_asText(
        ST_TRANSLATE(
        poly.geom,
        st_x(pt.geom) - st_x(st_centroid(poly.geom)),
        st_y(pt.geom) - st_y(st_centroid(poly.geom))
        )
        )
        FROM pt, poly;

        st_astext
        ---------------------------------------------------------
        POLYGON((-75 47.7,-76 47.7,-76 46.7,-75 46.7,-75 47.7))
        (1 row)





        share|improve this answer













        The easiest would be to have your polygon centered on (0;0) and to use st_translate using the target point X;Y as the delta X and delta Y.



        Using any polygon, you would compute the delta by removing the polygon centroid X and Y from the target point X and Y:



        WITH pt AS (SELECT 'point(-75.5 47.2)'::geometry geom),
        poly AS (SELECT 'polygon((-70 41, -71 41, -71 40,-70 40, -70 41))'::geometry geom)
        SELECT st_asText(
        ST_TRANSLATE(
        poly.geom,
        st_x(pt.geom) - st_x(st_centroid(poly.geom)),
        st_y(pt.geom) - st_y(st_centroid(poly.geom))
        )
        )
        FROM pt, poly;

        st_astext
        ---------------------------------------------------------
        POLYGON((-75 47.7,-76 47.7,-76 46.7,-75 46.7,-75 47.7))
        (1 row)






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 1 hour ago









        JGHJGH

        12.4k21136




        12.4k21136






















            Demus is a new contributor. Be nice, and check out our Code of Conduct.










            draft saved

            draft discarded


















            Demus is a new contributor. Be nice, and check out our Code of Conduct.













            Demus is a new contributor. Be nice, and check out our Code of Conduct.












            Demus is a new contributor. Be nice, and check out our Code of Conduct.
















            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%2f313197%2fpostgis-function-to-move-a-polygon-to-centre-over-new-point-coordinates%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

            Szabolcs (Ungheria) Altri progetti | Menu di navigazione48°10′14.56″N 21°29′33.14″E /...

            Discografia di Klaus Schulze Indice Album in studio | Album dal vivo | Singoli | Antologie | Colonne...

            How to make inet_server_addr() return localhost in spite of ::1/128RETURN NEXT in Postgres FunctionConnect to...