File tree Expand file tree Collapse file tree 2 files changed +13
-3
lines changed
dataframe-geo/src/main/kotlin/org/jetbrains/kotlinx/dataframe/geo/io Expand file tree Collapse file tree 2 files changed +13
-3
lines changed Original file line number Diff line number Diff line change @@ -12,16 +12,25 @@ import java.net.URL
12
12
fun GeoDataFrame.Companion.readGeoJson (path : String ): GeoDataFrame <* > = readGeoJson(asURL(path))
13
13
14
14
fun GeoDataFrame.Companion.readGeoJson (url : URL ): GeoDataFrame <* > =
15
- (FeatureJSON ().readFeatureCollection(url.openStream()) as SimpleFeatureCollection ).toGeoDataFrame()
15
+ url.openStream().use { inputStream ->
16
+ val featureCollection = FeatureJSON ().readFeatureCollection(inputStream) as SimpleFeatureCollection
17
+ featureCollection.toGeoDataFrame()
18
+ }
16
19
17
20
fun DataFrame.Companion.readGeoJson (path : String ): GeoDataFrame <* > = GeoDataFrame .readGeoJson(path)
18
21
19
22
fun DataFrame.Companion.readGeoJson (url : URL ): GeoDataFrame <* > = GeoDataFrame .readGeoJson(url)
20
23
21
24
fun GeoDataFrame.Companion.readShapefile (path : String ): GeoDataFrame <* > = readShapefile(asURL(path))
22
25
23
- fun GeoDataFrame.Companion.readShapefile (url : URL ): GeoDataFrame <* > =
24
- ShapefileDataStoreFactory ().createDataStore(url).featureSource.features.toGeoDataFrame()
26
+ fun GeoDataFrame.Companion.readShapefile (url : URL ): GeoDataFrame <* > {
27
+ val dataStore = ShapefileDataStoreFactory ().createDataStore(url)
28
+ try {
29
+ return dataStore.featureSource.features.toGeoDataFrame()
30
+ } finally {
31
+ dataStore.dispose()
32
+ }
33
+ }
25
34
26
35
fun DataFrame.Companion.readShapefile (path : String ): GeoDataFrame <* > = GeoDataFrame .readShapefile(path)
27
36
Original file line number Diff line number Diff line change @@ -52,6 +52,7 @@ fun GeoDataFrame<*>.writeShapefile(directory: File) {
52
52
e.printStackTrace()
53
53
transaction.rollback()
54
54
} finally {
55
+ dataStore.dispose()
55
56
transaction.close()
56
57
}
57
58
}
You can’t perform that action at this time.
0 commit comments