PostGIS function to move a polygon to centre over new point coordinates
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
New contributor
add a comment |
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
New contributor
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
add a comment |
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
New contributor
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
qgis postgis postgresql polygon move
New contributor
New contributor
edited 1 hour ago
Vince
14.6k32748
14.6k32748
New contributor
asked 2 hours ago
DemusDemus
161
161
New contributor
New contributor
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
add a comment |
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
add a comment |
1 Answer
1
active
oldest
votes
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)
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e) {
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom)) {
StackExchange.using('gps', function() { StackExchange.gps.track('embedded_signup_form.view', { location: 'question_page' }); });
$window.unbind('scroll', onScroll);
}
};
$window.on('scroll', onScroll);
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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)
add a comment |
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)
add a comment |
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)
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)
answered 1 hour ago
JGHJGH
12.4k21136
12.4k21136
add a comment |
add a comment |
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.
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e) {
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom)) {
StackExchange.using('gps', function() { StackExchange.gps.track('embedded_signup_form.view', { location: 'question_page' }); });
$window.unbind('scroll', onScroll);
}
};
$window.on('scroll', onScroll);
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e) {
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom)) {
StackExchange.using('gps', function() { StackExchange.gps.track('embedded_signup_form.view', { location: 'question_page' }); });
$window.unbind('scroll', onScroll);
}
};
$window.on('scroll', onScroll);
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e) {
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom)) {
StackExchange.using('gps', function() { StackExchange.gps.track('embedded_signup_form.view', { location: 'question_page' }); });
$window.unbind('scroll', onScroll);
}
};
$window.on('scroll', onScroll);
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e) {
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom)) {
StackExchange.using('gps', function() { StackExchange.gps.track('embedded_signup_form.view', { location: 'question_page' }); });
$window.unbind('scroll', onScroll);
}
};
$window.on('scroll', onScroll);
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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