I fixed a BUG ! please push to the master
hoogw opened this issue · 16 comments
This is a typo, easy fix, but will throw error if not fix.
terraformer.js
line 900
`
if (primitive.type === "MultiPolygon") {
// point.within(multipolygon)
if (this.type === "Point") {
if (primitive.coordinates.length) {
for (i = 0; i < primitive.coordinates.length; i++) {
coordinates = primitive.coordinates[i];
if (polygonContainsPoint(coordinates, this.coordinates) && arraysIntersectArrays([this.coordinates], primitive.coordinates) === false) {
return true;
}
}
}
return false;
// polygon.within(multipolygon)
} else if (this.type === "Polygon") {
// original code, will throw undefined error !!!!
//for (i = 0; i < this.coordinates.length; i++) {
// fixed code, works like a charm !!!!!!
for (i = 0; i < primitive.coordinates.length; i++) {
if (primitive.coordinates[i].length === this.coordinates.length) {
for (j = 0; j < this.coordinates.length; j++) {
if (coordinatesEqual(this.coordinates[j], primitive.coordinates[i][j])) {
return true;
}
}
}
}`
thx @hoogw! can you open a pull request for this instead of an issue please?
yes, I am trying, but due to covid-19 spreading, I suspend all my work, quarantine, it may take a while.
Another issue, I found is,
I see a warning message on console "point intersect with multipolygon are NOT supported"
However, I do see some points if not all do show on result.
What this warning message means?
it certainly looks like you've caught a simple typo and i've opened #339 with the fix, but i'd like to include a new test before it is merged.
original code, will throw undefined error !!!!
can you share the specific case that currently throws an error? i took a look and it wasn't immediately apparent how that could happen with a valid Polygon and MultiPolygon.
I see a warning message on console "point intersect with multipolygon are NOT supported"
However, I do see some points if not all do show on result.
you can find the answer to that question in #314.
I found even without this typo, assume fix this typo,
use multipolygon "interact" with polygon, still have issue, failed to work in my case.
How is my test case build? When I work on 180 meridian issue
you can see picture, in the post, that I use 2 bounding box( 2 polygon) split by 180 meridian to select the polygon interact.
It in fact multipolygon interact with polygon failed.
I abandon the 2 polygon method, until terrorformer fix the issue.
I could take a closer look later, but now days is really hard due to covid19.
The test case I used is inside my website, is a component part of a web page. The whole page is complex. I can re-produce the error, it shows failed to query when use multipolygon interact polygon, I get empty at emit data event.( after I fix the typo). Before fix typo, I get undefined error. I have to close look the original source code of geostore.js to figure out why and test on my page after.
thanks for your follow up comment.
i only partially follow your explanation so i greatly look forward to looking at two specific geometries to compare and contrast the behavior before/after your fix is applied.
working on it, but slowly, because I am rebuild the previously abandoned complex page in order to re-produce the error message. When I use geostore, I use multipolygon interact with polygon, it should emit data, but it silently does not emit anything, no error message on console, it should show some error message on console, unless it involve 180th meridian problem, no error message on console, no emit data. I am not sure what happen, have to modify geostore.js add some console log to track the error message.
Ok, I have build a test page, I can confirm that when use multipolygon intersect with polygon, terraformer failed to do so, it only use one of the polygon(my test multipolygon have 2 polygon part, left and right)
This is my multiplygon (left rectangular and right rectangular), I need query all feature intersect with either left box, or/and right box
you can see result missing left side content, only feature fall in right side box shows
I can confirm that, when use multipolygon intersect with polygon, only the last polygon in mulipolygon will be count and used. The previous parts of polygon will be ignored/or cause error, failed to output results.
multipolygon have (left box and right box), left box is first polygon, right box is last polygon
if all feature fall in right box, all feature will be show correctly
if all feature fall into left box(first polyon), will cause error, no result output, see, the processing bar on left top corner of this page, also on console, I see nothing output, where it should, this is where terraformer run into error. The yellow polygon on googlemaps is actually is last time result, I would not clear last time result until I receive new result.
as long as you do not use multipolygon, it will be ok.
otherwise, you will run into error.
How to fix multipolygon issue? I have to look deep into the code. I know where the code is,
just not pay attention to understand it, I will continue to take a closer look where cause the problem in the next few weeks.
is the behavior you're describing what happens without the typo fix you're proposing or with it?
the screenshots are helpful, but a code snippet with the simplest GeoJSON needed to reproduce the error would be outstanding.
when use multipolygon intersect with polygon, only the last polygon in multipolygon will be used. The previous parts of polygon will be ignored/or cause error,
thanks for trying to provide more information, but i can't repro any of the behavior you're describing. without making any changes to Terraformer, it throws no errors and uses all of a MultiPolygon's interior geometries when performing an intersect with a Polygon.
when i asked for "a code snippet with the simplest GeoJSON needed to reproduce the error.", this is what i meant.
// http://geojson.io/#id=gist:jgravois/b28f541b2243a3d998cfaebd162c64c3&map=5/0.879/10.942
it("shouldn't throw when detecting intersection of MultiPolygon and Polygon", function () {
var mp = new Terraformer.MultiPolygon([
[
[
[1, 1], [11, 1], [11, 6], [1, 6], [1, 1]
]
],
[
[
[11, 1], [21, 1], [21, 6], [11, 6], [11, 1]
]
]
]);
var polygon1 = new Terraformer.Polygon([[[0, 0], [10, 0], [10, 5], [0, 0]]]);
var polygon2 = new Terraformer.Polygon([[[12, 3], [15, 3], [14, 5], [12, 3]]]);
var polygon3 = new Terraformer.Polygon([[[33, 3], [35, 3], [34, 5], [33, 3]]]);
expect(mp.intersects(polygon1)).toEqual(true);
expect(mp.intersects(polygon2)).toEqual(true);
expect(mp.intersects(polygon3)).toEqual(false);
});
i appreciate all the screenshots and context setting you tried to give, but you dumped ~100x times more code on me than i was interested in reading and the closest thing you gave me to a specific geometry wasn't very helpful either
// what are any of these variables assigned to??
[[
[SWlong, SWlat],
[SClong, SClat],
[NClong, NClat],
[NWlong, NWlat],
[SWlong, SWlat]
]], // ...
if you can either alter the test case i shared to demonstrate a problem or come up with one of your own, i'd be happy to take another look. to date though, i've already burned a lot of time on this without much to show for it because you didn't provide what i asked for back on March 25th.
I removed the unwanted code above. I kind of know the reason.
Your test case is multipolygon intersects with a single polygon.
My test case is total different, my test case, is
a feature collection of 100k single polgyon.
select all single polygon that intersects with a multipolygon( have 2 polygon parts)
it works fine in your case, but may not work in my case, since there are different.
my case should be
` test_geojson.features = [polygon1, polygon2, polygon3]
geostore.add(test_geojson)
geostore.intersects(mp)
`
I found another issue: when geostore use indexedDB as storage, it failed.
Mybe the latest indexedDB does not fit terraformer,
indexedDB seems more important feature, must have.
Because, large geojson, store in memory, easily crash browser, specially in mobile browser.
You have to use indexedDB to store in physical hard disk to avoid browser crash.
I am digging into this direction, because it is more critical.
my case should be
test_geojson.features = [polygon1, polygon2, polygon3]
geostore.add(test_geojson)
geostore.intersects(mp)
you're still not giving me a specific test case with actual GeoJSON geometries. i'm happy to reopen this ticket if you can down the line.