Skip to content

Commit 0ff0ee8

Browse files
fix crs equals checks
1 parent b724f9d commit 0ff0ee8

File tree

2 files changed

+11
-3
lines changed
  • dataframe-geo/src
    • main/kotlin/org/jetbrains/kotlinx/dataframe/geo
    • test/kotlin/org/jetbrains/kotlinx/dataframe/geo/io

2 files changed

+11
-3
lines changed

dataframe-geo/src/main/kotlin/org/jetbrains/kotlinx/dataframe/geo/GeoDataFrame.kt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ class GeoDataFrame<T : WithGeometry>(val df: DataFrame<T>, val crs: CoordinateRe
3636
* @return A new `GeoDataFrame` with reprojected geometries and the specified CRS.
3737
*/
3838
fun applyCrs(targetCrs: CoordinateReferenceSystem): GeoDataFrame<T> {
39+
if (crs == null) {
40+
return GeoDataFrame(df, targetCrs)
41+
}
3942
if (targetCrs == this.crs) return this
4043
// Use WGS 84 by default TODO
4144
val sourceCRS: CoordinateReferenceSystem = this.crs ?: DEFAULT_CRS
@@ -47,8 +50,14 @@ class GeoDataFrame<T : WithGeometry>(val df: DataFrame<T>, val crs: CoordinateRe
4750
}
4851

4952
override fun equals(other: Any?): Boolean {
53+
if (this === other) return true
5054
if (other !is GeoDataFrame<*>) return false
51-
return df == other.df && crs == other.crs
55+
56+
return df == other.df && when {
57+
crs == null && other.crs == null -> true
58+
crs == null || other.crs == null -> false
59+
else -> CRS.equalsIgnoreMetadata(crs, other.crs)
60+
}
5261
}
5362

5463
companion object {

dataframe-geo/src/test/kotlin/org/jetbrains/kotlinx/dataframe/geo/io/IOTest.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class IOTest {
2121
"Point 2", point2
2222
)
2323
}
24-
private val simplePointsGeoDf = simplePointsDf.toGeo(null)
24+
private val simplePointsGeoDf = simplePointsDf.toGeo(GeoDataFrame.DEFAULT_CRS)
2525
private val classLoader = (this::class as Any).javaClass.classLoader
2626

2727
@Test
@@ -61,7 +61,6 @@ class IOTest {
6161
simplePointsGeoDf.writeShapefile(tempShapefileDir)
6262
val shapefile = File("${tempShapefileDir.path}/simple_points.shp")
6363
assertEquals(simplePointsGeoDf, GeoDataFrame.readShapefile(shapefile.toURI().toURL()))
64-
6564
tempDir.deleteOnExit()
6665
}
6766
}

0 commit comments

Comments
 (0)