PostgreSQL - Array of overlapping Polygon IdsPostGIS: Strategy for fastest select by BBox with an ORDER BY...
What's the correct term for a waitress in the Middle Ages?
Does the first version of Linux developed by Linus Torvalds have a GUI?
When conversion from Integer to Single may lose precision
Does there exist a word to express a male who behaves as a female?
How to translate “Me doing X” like in online posts?
Average spam confidence
How do I write "Show, Don't Tell" as a person with Asperger Syndrome?
How would a aircraft visually signal in distress?
Cause of continuous spectral lines
Translating 'Liber'
How many pairs of subsets can be formed?
How many times can you cast a card exiled by Release to the Wind?
How bad would a partial hash leak be, realistically?
Should I "tell" my exposition or give it through dialogue?
Is the decompression of compressed and encrypted data without decryption also theoretically impossible?
How Can I Tell The Difference Between Unmarked Sugar and Stevia?
Etymology of 'calcit(r)are'?
What do we gain with higher order logics?
Does an ice chest packed full of frozen food need ice?
Why does Kathryn say this in 12 Monkeys?
Why don't B747s start takeoffs with full throttle?
How to skip replacing first occurrence of a character in each line?
Payment instructions from HomeAway look fishy to me
Are "living" organ banks practical?
PostgreSQL - Array of overlapping Polygon Ids
PostGIS: Strategy for fastest select by BBox with an ORDER BY polygon area clause. Cluster?Performing polygon drilldown/overlay in PostGIS?PostgreSQL Queries pgAdmin versus Function call
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}
I have a database table (overlay) that has columns, id::int, intersections::int array, geom::polygon. I have another table (images) that has id and geom columns. I am trying to populate the intersections array with the ids of the rows in the images table that intersect (and have an area greater than 0.00001). For example, if intersection A (overlay table) intersects B1, B2, and B3 (images table), I am trying to set the intersection column in the overlay table to {B1, B2, B3}. The query below is what I have come up with to accomplish this goal,
UPDATE public.overlay
SET intersections = array_append(intersections, i.id)
FROM (SELECT geom, id FROM images WHERE images.geom IS NOT NULL) i
WHERE ST_AREA(ST_INTERSECTION(ST_MAKEVALID(overlay.geom), i.geom)) > 0.000001
AND NOT ST_TOUCHES(ST_MAKEVALID(overlay.geom), i.geom)
Right now, the above query is only ever adding a single entry to the intersections column and I am not sure why. I am going to walk through what I think is occurring in the hopes that my mistake is quite evident:
UPDATE public.overlay<- The table that needs to be updated
SET intersections = array_append(intersections, i.id)<- use the Postgresarray_appendfunction to update the intersections column. This could also be written asSET intersections = intersections || i.id, but that does not result in the desired output.
FROM (SELECT geom, id FROM images WHERE images.geom IS NOT NULL) i<- Theimagestable has a few entries with NULL geometries, so skip those. The results of the query are pushed into theivariable.
WHERE ST_AREA(ST_INTERSECTION(ST_MAKEVALID(overlay.geom), i.geom)) > 0.000001<- Start of the where clause. Here compute the intersection of the overlay geometry and compute the area so slivers can be omitted.
AND NOT ST_TOUCHES(ST_MAKEVALID(overlay.geom), i.geom)<- The second half of the where clause that omits bordering (touching) polygons. This is redundant, I believe with the area check, but I want to make sure that neighbors are omitted.
postgis postgresql sql
add a comment |
I have a database table (overlay) that has columns, id::int, intersections::int array, geom::polygon. I have another table (images) that has id and geom columns. I am trying to populate the intersections array with the ids of the rows in the images table that intersect (and have an area greater than 0.00001). For example, if intersection A (overlay table) intersects B1, B2, and B3 (images table), I am trying to set the intersection column in the overlay table to {B1, B2, B3}. The query below is what I have come up with to accomplish this goal,
UPDATE public.overlay
SET intersections = array_append(intersections, i.id)
FROM (SELECT geom, id FROM images WHERE images.geom IS NOT NULL) i
WHERE ST_AREA(ST_INTERSECTION(ST_MAKEVALID(overlay.geom), i.geom)) > 0.000001
AND NOT ST_TOUCHES(ST_MAKEVALID(overlay.geom), i.geom)
Right now, the above query is only ever adding a single entry to the intersections column and I am not sure why. I am going to walk through what I think is occurring in the hopes that my mistake is quite evident:
UPDATE public.overlay<- The table that needs to be updated
SET intersections = array_append(intersections, i.id)<- use the Postgresarray_appendfunction to update the intersections column. This could also be written asSET intersections = intersections || i.id, but that does not result in the desired output.
FROM (SELECT geom, id FROM images WHERE images.geom IS NOT NULL) i<- Theimagestable has a few entries with NULL geometries, so skip those. The results of the query are pushed into theivariable.
WHERE ST_AREA(ST_INTERSECTION(ST_MAKEVALID(overlay.geom), i.geom)) > 0.000001<- Start of the where clause. Here compute the intersection of the overlay geometry and compute the area so slivers can be omitted.
AND NOT ST_TOUCHES(ST_MAKEVALID(overlay.geom), i.geom)<- The second half of the where clause that omits bordering (touching) polygons. This is redundant, I believe with the area check, but I want to make sure that neighbors are omitted.
postgis postgresql sql
1
You should probably start by validating your virtual table query. Does it return what you're expecting?
– Vince
9 hours ago
add a comment |
I have a database table (overlay) that has columns, id::int, intersections::int array, geom::polygon. I have another table (images) that has id and geom columns. I am trying to populate the intersections array with the ids of the rows in the images table that intersect (and have an area greater than 0.00001). For example, if intersection A (overlay table) intersects B1, B2, and B3 (images table), I am trying to set the intersection column in the overlay table to {B1, B2, B3}. The query below is what I have come up with to accomplish this goal,
UPDATE public.overlay
SET intersections = array_append(intersections, i.id)
FROM (SELECT geom, id FROM images WHERE images.geom IS NOT NULL) i
WHERE ST_AREA(ST_INTERSECTION(ST_MAKEVALID(overlay.geom), i.geom)) > 0.000001
AND NOT ST_TOUCHES(ST_MAKEVALID(overlay.geom), i.geom)
Right now, the above query is only ever adding a single entry to the intersections column and I am not sure why. I am going to walk through what I think is occurring in the hopes that my mistake is quite evident:
UPDATE public.overlay<- The table that needs to be updated
SET intersections = array_append(intersections, i.id)<- use the Postgresarray_appendfunction to update the intersections column. This could also be written asSET intersections = intersections || i.id, but that does not result in the desired output.
FROM (SELECT geom, id FROM images WHERE images.geom IS NOT NULL) i<- Theimagestable has a few entries with NULL geometries, so skip those. The results of the query are pushed into theivariable.
WHERE ST_AREA(ST_INTERSECTION(ST_MAKEVALID(overlay.geom), i.geom)) > 0.000001<- Start of the where clause. Here compute the intersection of the overlay geometry and compute the area so slivers can be omitted.
AND NOT ST_TOUCHES(ST_MAKEVALID(overlay.geom), i.geom)<- The second half of the where clause that omits bordering (touching) polygons. This is redundant, I believe with the area check, but I want to make sure that neighbors are omitted.
postgis postgresql sql
I have a database table (overlay) that has columns, id::int, intersections::int array, geom::polygon. I have another table (images) that has id and geom columns. I am trying to populate the intersections array with the ids of the rows in the images table that intersect (and have an area greater than 0.00001). For example, if intersection A (overlay table) intersects B1, B2, and B3 (images table), I am trying to set the intersection column in the overlay table to {B1, B2, B3}. The query below is what I have come up with to accomplish this goal,
UPDATE public.overlay
SET intersections = array_append(intersections, i.id)
FROM (SELECT geom, id FROM images WHERE images.geom IS NOT NULL) i
WHERE ST_AREA(ST_INTERSECTION(ST_MAKEVALID(overlay.geom), i.geom)) > 0.000001
AND NOT ST_TOUCHES(ST_MAKEVALID(overlay.geom), i.geom)
Right now, the above query is only ever adding a single entry to the intersections column and I am not sure why. I am going to walk through what I think is occurring in the hopes that my mistake is quite evident:
UPDATE public.overlay<- The table that needs to be updated
SET intersections = array_append(intersections, i.id)<- use the Postgresarray_appendfunction to update the intersections column. This could also be written asSET intersections = intersections || i.id, but that does not result in the desired output.
FROM (SELECT geom, id FROM images WHERE images.geom IS NOT NULL) i<- Theimagestable has a few entries with NULL geometries, so skip those. The results of the query are pushed into theivariable.
WHERE ST_AREA(ST_INTERSECTION(ST_MAKEVALID(overlay.geom), i.geom)) > 0.000001<- Start of the where clause. Here compute the intersection of the overlay geometry and compute the area so slivers can be omitted.
AND NOT ST_TOUCHES(ST_MAKEVALID(overlay.geom), i.geom)<- The second half of the where clause that omits bordering (touching) polygons. This is redundant, I believe with the area check, but I want to make sure that neighbors are omitted.
postgis postgresql sql
postgis postgresql sql
edited 9 hours ago
Vince
15k33050
15k33050
asked 10 hours ago
Jay LauraJay Laura
3,42711538
3,42711538
1
You should probably start by validating your virtual table query. Does it return what you're expecting?
– Vince
9 hours ago
add a comment |
1
You should probably start by validating your virtual table query. Does it return what you're expecting?
– Vince
9 hours ago
1
1
You should probably start by validating your virtual table query. Does it return what you're expecting?
– Vince
9 hours ago
You should probably start by validating your virtual table query. Does it return what you're expecting?
– Vince
9 hours ago
add a comment |
1 Answer
1
active
oldest
votes
Going off the suggestion of @Vince, I was able to get this working using the following:
UPDATE overlay
SET intersections = imgs.iid
FROM (
SELECT overlay.id, array_agg(images.id) as iid
FROM overlay, images
WHERE images.geom is NOT NULL AND
ST_AREA(ST_INTERSECTION(overlay.geom, images.geom)) > 0.000001
GROUP BY overlay.id
) AS imgs
WHERE imgs.id = overlay.id;
Since the selection is all at once, an aggregation was the correct approach. The append might be useful in the future if I want to update existing overlaps, but for now, this is a 'one-and-done' operation.
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
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%2f324604%2fpostgresql-array-of-overlapping-polygon-ids%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
Going off the suggestion of @Vince, I was able to get this working using the following:
UPDATE overlay
SET intersections = imgs.iid
FROM (
SELECT overlay.id, array_agg(images.id) as iid
FROM overlay, images
WHERE images.geom is NOT NULL AND
ST_AREA(ST_INTERSECTION(overlay.geom, images.geom)) > 0.000001
GROUP BY overlay.id
) AS imgs
WHERE imgs.id = overlay.id;
Since the selection is all at once, an aggregation was the correct approach. The append might be useful in the future if I want to update existing overlaps, but for now, this is a 'one-and-done' operation.
add a comment |
Going off the suggestion of @Vince, I was able to get this working using the following:
UPDATE overlay
SET intersections = imgs.iid
FROM (
SELECT overlay.id, array_agg(images.id) as iid
FROM overlay, images
WHERE images.geom is NOT NULL AND
ST_AREA(ST_INTERSECTION(overlay.geom, images.geom)) > 0.000001
GROUP BY overlay.id
) AS imgs
WHERE imgs.id = overlay.id;
Since the selection is all at once, an aggregation was the correct approach. The append might be useful in the future if I want to update existing overlaps, but for now, this is a 'one-and-done' operation.
add a comment |
Going off the suggestion of @Vince, I was able to get this working using the following:
UPDATE overlay
SET intersections = imgs.iid
FROM (
SELECT overlay.id, array_agg(images.id) as iid
FROM overlay, images
WHERE images.geom is NOT NULL AND
ST_AREA(ST_INTERSECTION(overlay.geom, images.geom)) > 0.000001
GROUP BY overlay.id
) AS imgs
WHERE imgs.id = overlay.id;
Since the selection is all at once, an aggregation was the correct approach. The append might be useful in the future if I want to update existing overlaps, but for now, this is a 'one-and-done' operation.
Going off the suggestion of @Vince, I was able to get this working using the following:
UPDATE overlay
SET intersections = imgs.iid
FROM (
SELECT overlay.id, array_agg(images.id) as iid
FROM overlay, images
WHERE images.geom is NOT NULL AND
ST_AREA(ST_INTERSECTION(overlay.geom, images.geom)) > 0.000001
GROUP BY overlay.id
) AS imgs
WHERE imgs.id = overlay.id;
Since the selection is all at once, an aggregation was the correct approach. The append might be useful in the future if I want to update existing overlaps, but for now, this is a 'one-and-done' operation.
answered 7 hours ago
Jay LauraJay Laura
3,42711538
3,42711538
add a comment |
add a comment |
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');
});
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%2f324604%2fpostgresql-array-of-overlapping-polygon-ids%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');
});
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');
});
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');
});
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
You should probably start by validating your virtual table query. Does it return what you're expecting?
– Vince
9 hours ago