Skip to content
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
1 change: 1 addition & 0 deletions dataframe-arrow/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ dependencies {
implementation(libs.kotlin.datetimeJvm)

testImplementation(libs.junit)
testImplementation(projects.dataframeJson)
testImplementation(libs.kotestAssertions) {
exclude("org.jetbrains.kotlin", "kotlin-stdlib-jdk8")
}
Expand Down
1 change: 1 addition & 0 deletions dataframe-geo/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ dependencies {
implementation(libs.ktor.serialization.kotlinx.json)

testImplementation(kotlin("test"))
testImplementation(projects.dataframeJson)
}

tasks.withType<KotlinCompile>().configureEach {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,16 @@ fun GeoDataFrame<*>.toSimpleFeatureCollection(
val featureCollection = ListFeatureCollection(featureType)

val featureBuilder = SimpleFeatureBuilder(featureType)

// if ID is present, SortedMap in DefaultFeatureCollection sorts rows by ID lexicographically
// I couldn't disable writing it, so let's generate lexicographically sorted IDs
val format = "f%0${df.rowsCount().toString().length}d"
df.forEach { row ->
val geometry = row["geometry"]
featureBuilder.add(geometry)
df.columnNames().filter { it != "geometry" }.forEach { colName ->
featureBuilder.add(row[colName])
}
val feature: SimpleFeature = featureBuilder.buildFeature(null)
val feature: SimpleFeature = featureBuilder.buildFeature(String.format(format, index()))
featureCollection.add(feature)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.jetbrains.kotlinx.dataframe.geo.io

import org.geotools.referencing.CRS
import org.jetbrains.kotlinx.dataframe.api.dataFrameOf
import org.jetbrains.kotlinx.dataframe.geo.GeoDataFrame
import org.jetbrains.kotlinx.dataframe.geo.toGeo
Expand Down Expand Up @@ -35,17 +36,18 @@ class IOTest {
assert(geodf.crs == null)
}

/*
TODO: doesn't work for now - writers adds ids that breaks order when read features
@Test
fun writeGeoJson() {
val tempFile = Files.createTempFile("simple_points", ".json").toFile()
simplePointsGeoDf.writeGeoJson(tempFile)

assertEquals(simplePointsGeoDf, GeoDataFrame.readGeoJson(tempFile.toURI().toURL()))
val loadedGeoDataFrame = GeoDataFrame.readGeoJson(tempFile.toURI().toURL())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to add more IO overloads ;)

assertEquals(simplePointsGeoDf.df, loadedGeoDataFrame.df)
// TODO: Doesn't work because of how equality between CRS is checked by geotools
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The proper way to check CRS equality in Geotools is
CRS.equals, or CRS.equalsIgnoreMetadata if you don't want to compare metedata.

But there, shouldn't they be equal?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't help :(
println(CRS.equalsIgnoreMetadata(simplePointsGeoDf.crs, loadedGeoDataFrame.crs))

false

They are in fact identical, two lines just go in different order
image

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait, then there's problem here! In GeoDataFrame (as in GeoJson specification) longitude should always go first! That's important!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting. This is how CRS looks right after reading of features:
image

Order of longitude is broken?
image

Content of the file we're reading from:
"crs":{"type":"name","properties":{"name":"EPSG:4326"}}

I see that our default CRS is created with longitudeFirst = true: CRS.decode("EPSG:4326", true)

image

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Related to
#1187 (comment)
Now we can leave it as it is.

// assertEquals(simplePointsGeoDf, loadedGeoDataFrame)

tempFile.deleteOnExit()
}*/
}

@Test
fun readShapefile() {
Expand Down