File tree Expand file tree Collapse file tree 2 files changed +10
-6
lines changed
main/kotlin/org/jetbrains/kotlinx/dataframe/geo/geotools
test/kotlin/org/jetbrains/kotlinx/dataframe/geo/io Expand file tree Collapse file tree 2 files changed +10
-6
lines changed Original file line number Diff line number Diff line change @@ -40,14 +40,16 @@ fun GeoDataFrame<*>.toSimpleFeatureCollection(
4040 val featureCollection = ListFeatureCollection (featureType)
4141
4242 val featureBuilder = SimpleFeatureBuilder (featureType)
43-
43+ // if ID is present, SortedMap in DefaultFeatureCollection sorts rows by ID lexicographically
44+ // I couldn't disable writing it, so let's generate lexicographically sorted IDs
45+ val format = " f%0${df.rowsCount().toString().length} d"
4446 df.forEach { row ->
4547 val geometry = row[" geometry" ]
4648 featureBuilder.add(geometry)
4749 df.columnNames().filter { it != " geometry" }.forEach { colName ->
4850 featureBuilder.add(row[colName])
4951 }
50- val feature: SimpleFeature = featureBuilder.buildFeature(null )
52+ val feature: SimpleFeature = featureBuilder.buildFeature(String .format(format, index()) )
5153 featureCollection.add(feature)
5254 }
5355
Original file line number Diff line number Diff line change 11package org.jetbrains.kotlinx.dataframe.geo.io
22
3+ import org.geotools.referencing.CRS
34import org.jetbrains.kotlinx.dataframe.api.dataFrameOf
45import org.jetbrains.kotlinx.dataframe.geo.GeoDataFrame
56import org.jetbrains.kotlinx.dataframe.geo.toGeo
@@ -35,17 +36,18 @@ class IOTest {
3536 assert (geodf.crs == null )
3637 }
3738
38- /*
39- TODO: doesn't work for now - writers adds ids that breaks order when read features
4039 @Test
4140 fun writeGeoJson () {
4241 val tempFile = Files .createTempFile(" simple_points" , " .json" ).toFile()
4342 simplePointsGeoDf.writeGeoJson(tempFile)
4443
45- assertEquals(simplePointsGeoDf, GeoDataFrame.readGeoJson(tempFile.toURI().toURL()))
44+ val loadedGeoDataFrame = GeoDataFrame .readGeoJson(tempFile.toURI().toURL())
45+ assertEquals(simplePointsGeoDf.df, loadedGeoDataFrame.df)
46+ // TODO: Doesn't work because of how equality between CRS is checked by geotools
47+ // assertEquals(simplePointsGeoDf, loadedGeoDataFrame)
4648
4749 tempFile.deleteOnExit()
48- }*/
50+ }
4951
5052 @Test
5153 fun readShapefile () {
You can’t perform that action at this time.
0 commit comments