Skip to content
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

Fix GeometryCollection::getAll extension method #3295

Merged
merged 2 commits into from
Nov 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed
- Fix `Encoder[GeometryCollection]` including subclasses of GeometryCollection twice in the json
(MultiPolygon, Multipoint,MultiLinestring) [#3167](https://github.com/locationtech/geotrellis/issues/3167)
-Fix `LayoutTileSource` buffer should only be 1/2 a cellsize to avoid going out of bounds and creating `NODATA` values [#3302](https://github.com/locationtech/geotrellis/pull/3302)
- Fix `LayoutTileSource` buffer should only be 1/2 a cellsize to avoid going out of bounds and creating `NODATA` values [#3302](https://github.com/locationtech/geotrellis/pull/3302)
- Remove unused allocation from CroppedTile [#3297](https://github.com/locationtech/geotrellis/pull/3297)
- Fix GeometryCollection::getAll extension method [#3295](https://github.com/locationtech/geotrellis/pull/3295)

## [3.5.0] - 2020-08-18

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ trait ExtraGeometryCollectionMethods extends MethodExtensions[GeometryCollection
def getAll[G <: Geometry : ClassTag]: Seq[G] = {
val lb = scala.collection.mutable.ListBuffer.empty[G]
cfor(0)(_ < self.getNumGeometries, _ + 1){ i =>
if (classTag[G].runtimeClass.isInstance(self.getGeometryN(i)))
if (classTag[G].runtimeClass == self.getGeometryN(i).getClass)
lb += self.getGeometryN(i).asInstanceOf[G]
}
lb.toSeq
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Copyright 2016 Azavea
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package geotrellis.vector

import geotrellis.proj4.{LatLng, WebMercator}

import org.scalatest.matchers.should.Matchers
import org.scalatest.funspec.AnyFunSpec

class GeometryCollectionSpec extends AnyFunSpec with Matchers {
describe("GeometryCollection") {
it("should reproject without duplication") {
val p = Point(1,1)
val mp = MultiPoint(p, p)
val gc = GeometryCollection(multiPoints = Seq(mp))

val pp = p.reproject(LatLng, WebMercator)
val mpp = MultiPoint(pp, pp)
val gcp = GeometryCollection(multiPoints = Seq(mpp))

gc.reproject(LatLng, WebMercator) should be (gcp)
}

it("getAll should work right for all types") {
val p0 = Point(0, 0)
val p1 = Point(1, 0)
val p2 = Point(0, 1)
val ls = LineString(p0, p1)
val pg = Polygon(p0, p1, p2, p0)
val mp = MultiPoint(p0, p1, p2)
val mpg = MultiPolygon(pg)
val mls = MultiLineString(ls)
val gc = GeometryCollection(points = Seq(p0))

val gc1 = GeometryCollection(points = Seq(p0),
lines = Seq(ls),
polygons = Seq(pg),
multiPoints = Seq(mp),
multiLines = Seq(mls),
multiPolygons = Seq(mpg),
geometryCollections = Seq(gc))

gc1.getAll[Point] should be (Seq(p0))
gc1.getAll[LineString] should be (Seq(ls))
gc1.getAll[Polygon] should be (Seq(pg))
gc1.getAll[MultiPoint] should be (Seq(mp))
gc1.getAll[MultiLineString] should be (Seq(mls))
gc1.getAll[MultiPolygon] should be (Seq(mpg))
gc1.getAll[GeometryCollection] should be (Seq(gc))
}
}
}