-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Fix geojson write GeometryCollection #5080
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| var options = (opt_options && opt_options.rightHanded) ? { | ||
| rightHanded: opt_options.rightHanded | ||
| } : undefined; | ||
| return ol.format.GeoJSON.writeGeometry_(geometry, options); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably safer to do something like
var options = ol.object.assign({}, opt_options);
delete options.featureProjection;
return ol.format.GeoJSON.writeGeometry_(geometry, options);There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shorter too :-) ok, will change this
I'd feel better if you added a test for this pull request too. You can use something like |
|
What exactly would that test? |
| var geometries = geometry.getGeometriesArray().map(function(geometry) { | ||
| return ol.format.GeoJSON.writeGeometry_(geometry, opt_options); | ||
| var options = ol.object.assign({}, opt_options); | ||
| delete options.featureProjection; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make sense to delete options.dataProjection as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's not necessary. If featureProjection isn't set, no transform is performed.
where is |
|
ok. Basic test added, based on the Point test above. |
| expect(geometries[0].getCoordinates()[0]).to.roughlyEqual( | ||
| gotGeometries[0].getCoordinates()[0], 1e-8); | ||
| expect( | ||
| Math.abs(geometries[0].getCoordinates()[1] - |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can also use roughlyEquals here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, I was wondering why the Point test wasn't using roughlyEquals for both coordinates
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
roughlyEqual is just for numbers, so you have to test x and y of a coordinate separately or in a forEach function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the 'transforms and encodes a point' test is using roughlyEqual for the x coord and this Math.abs formula for the y. I'm wondering why.
|
test changed as suggested, so this tests a Point and the first coordinate of a LineString within a GeometryCollection, which should be sufficient. I'll submit another PR to change the Point test to use roughlyEqual for both coords - might as well make these things consistent. |
Fix geojson write GeometryCollection
Thanks. I think a |
I tested my changes mentioned in #3953 on a GeometryCollection, and found they didn't work. However, when I tried doing the same with the current master, I found that didn't work either. examples/geojson has a GeometryCollection so if you do something like
you can see that the coordinates are all screwy. The reason for this is that
writeGeometry_is getting run for the Collection as a whole and then for each individual geometry.writeGeometry_runsol.format.Feature#transformWithOptions(), so the coordinates for each geometry are transformed twice. This PR calls write for the individual geoms without the projection options, so the 2nd transform doesn't occur.From the fact that no-one's noticed this before, I conclude that GeometryCollections aren't used very much. :-) I think tests should be added for this case, but would prefer to include that in my fixes for #3953 so the rounding can be tested as well.