Skip to content

Commit

Permalink
Add a human readable exception to avoid the inifinte recursion stack …
Browse files Browse the repository at this point in the history
…in the reprojectAsPolygon function call

Signed-off-by: Grigory <gr.pomadchin@gmail.com>
  • Loading branch information
pomadchin committed Sep 24, 2019
1 parent 6b63746 commit 9148c5f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ Fixes & Updates
- Bump proj4 version to fix multiple performance issues (`#3039 <https://github.com/locationtech/geotrellis/pull/3039>`_).
- Update dependencies (`#3053 <https://github.com/locationtech/geotrellis/pull/3053>`_).
- Fix HttpRangeReader swallows 404 error (`#3073 https://github.com/locationtech/geotrellis/pull/3073`_)
- reprojectExtentAsPolygon should be more deterministic (`#3083 https://github.com/locationtech/geotrellis/pull/3083`_)

2.3.0
-----
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ object Reproject {
val length = sqrt(pow(x0 - x1, 2) + pow(y0 - y1, 2))

val p2 = m -> (x2, y2)
if (deflect / length < relError) {
if (deflect.isNaN) {
throw new IllegalArgumentException(s"Check the input $extent CRS, it is probably not in the correct projection.")
} else if (deflect / length < relError) {
List(p2)
} else {
refine(p0, p2) ++ (p2 :: refine(p2, p1))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@
* limitations under the License.
*/

package geotrellis.vector
package geotrellis.vector.reproject

import geotrellis.proj4._
import geotrellis.vector._
import geotrellis.vector.testkit._

import org.scalatest._
Expand All @@ -33,5 +34,20 @@ class ReprojectSpec extends FunSpec with Matchers {
wm.reproject(WebMercator, LatLng) should matchGeom(ll, 0.00001)
ll.reproject(LatLng, Sinusoidal).reproject(Sinusoidal, WebMercator) should matchGeom(wm, 0.00001)
}

// see issue https://github.com/locationtech/geotrellis/issues/3023
it("should not go into the infinite recursion stack") {
val ext = Extent(0.0, 0.0, 2606.0, 2208.0)
// we declare the extent as coords in LatLng, see issue #3023
// though valid
// - longitudes are in [-180, 180] degrees ragne
// - latitudes are in [-90, 90] degrees range

val transform = Transform(LatLng, WebMercator)
// should not fail into the recursion stack
intercept[IllegalArgumentException] {
Reproject.reprojectExtentAsPolygon(ext, transform, 0.001)
}
}
}
}

0 comments on commit 9148c5f

Please sign in to comment.