<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Kotlin SDK how to load GeoJSON file in Kotlin Maps SDK Questions</title>
    <link>https://community.esri.com/t5/kotlin-maps-sdk-questions/kotlin-sdk-how-to-load-geojson-file/m-p/1648790#M591</link>
    <description>&lt;P&gt;I am developing an Android application using the ArcGIS Maps SDK for Kotlin (version 200.x) and I'm trying to load and display a GeoJSON file from local device storage.&lt;/P&gt;&lt;P&gt;I found the &lt;A href="https://developers.arcgis.com/kotlin/api-reference/arcgis-maps-kotlin/com.arcgismaps.data/-feature-collection/-companion/from-json-or-null.html" target="_self"&gt;FeatureCollection.fromJsonOrNull&lt;/A&gt;&amp;nbsp; to try to load&amp;nbsp;the file.But it cannot be analyzed correctly.&lt;/P&gt;&lt;LI-CODE lang="kotlin"&gt;   fun loadGeoJSONFromContentUri(context:Context, uri: Uri, fileExtension: String) {

        try {

            val tempFile = File(context.cacheDir, "temp_${System.currentTimeMillis()}.$fileExtension")

            context.contentResolver.openInputStream(uri)?.use { inputStream -&amp;gt;
                FileOutputStream(tempFile).use { outputStream -&amp;gt;
                    inputStream.copyTo(outputStream)
                }
            }

            val geoJsonString = tempFile.readText(Charsets.UTF_8)
            val featureCollection = FeatureCollection.fromJsonOrNull(geoJsonString)

            if(featureCollection == null){
                tempFile.delete()
                return
            }

            featureCollection.tables.forEach {
                it.layer?.let { layer -&amp;gt;
                    arcGISMap.operationalLayers.add(layer)
                }
            }

            tempFile.delete()
            
        } catch (e: Exception) {
            Toast.makeText(context, e.message ?: "GeoJSON file load faild", Toast.LENGTH_SHORT).show()
            Log.e(TAG, " ${e.printStackTrace()}")
        }
    }&lt;/LI-CODE&gt;&lt;P&gt;&lt;STRONG&gt;&lt;SPAN&gt;Am I using the wrong method, or is there another recommended way to load a GeoJSON file?&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 09 Sep 2025 00:31:47 GMT</pubDate>
    <dc:creator>LiqiangZhu</dc:creator>
    <dc:date>2025-09-09T00:31:47Z</dc:date>
    <item>
      <title>Kotlin SDK how to load GeoJSON file</title>
      <link>https://community.esri.com/t5/kotlin-maps-sdk-questions/kotlin-sdk-how-to-load-geojson-file/m-p/1648790#M591</link>
      <description>&lt;P&gt;I am developing an Android application using the ArcGIS Maps SDK for Kotlin (version 200.x) and I'm trying to load and display a GeoJSON file from local device storage.&lt;/P&gt;&lt;P&gt;I found the &lt;A href="https://developers.arcgis.com/kotlin/api-reference/arcgis-maps-kotlin/com.arcgismaps.data/-feature-collection/-companion/from-json-or-null.html" target="_self"&gt;FeatureCollection.fromJsonOrNull&lt;/A&gt;&amp;nbsp; to try to load&amp;nbsp;the file.But it cannot be analyzed correctly.&lt;/P&gt;&lt;LI-CODE lang="kotlin"&gt;   fun loadGeoJSONFromContentUri(context:Context, uri: Uri, fileExtension: String) {

        try {

            val tempFile = File(context.cacheDir, "temp_${System.currentTimeMillis()}.$fileExtension")

            context.contentResolver.openInputStream(uri)?.use { inputStream -&amp;gt;
                FileOutputStream(tempFile).use { outputStream -&amp;gt;
                    inputStream.copyTo(outputStream)
                }
            }

            val geoJsonString = tempFile.readText(Charsets.UTF_8)
            val featureCollection = FeatureCollection.fromJsonOrNull(geoJsonString)

            if(featureCollection == null){
                tempFile.delete()
                return
            }

            featureCollection.tables.forEach {
                it.layer?.let { layer -&amp;gt;
                    arcGISMap.operationalLayers.add(layer)
                }
            }

            tempFile.delete()
            
        } catch (e: Exception) {
            Toast.makeText(context, e.message ?: "GeoJSON file load faild", Toast.LENGTH_SHORT).show()
            Log.e(TAG, " ${e.printStackTrace()}")
        }
    }&lt;/LI-CODE&gt;&lt;P&gt;&lt;STRONG&gt;&lt;SPAN&gt;Am I using the wrong method, or is there another recommended way to load a GeoJSON file?&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 09 Sep 2025 00:31:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/kotlin-maps-sdk-questions/kotlin-sdk-how-to-load-geojson-file/m-p/1648790#M591</guid>
      <dc:creator>LiqiangZhu</dc:creator>
      <dc:date>2025-09-09T00:31:47Z</dc:date>
    </item>
    <item>
      <title>Re: Kotlin SDK how to load GeoJSON file</title>
      <link>https://community.esri.com/t5/kotlin-maps-sdk-questions/kotlin-sdk-how-to-load-geojson-file/m-p/1648824#M592</link>
      <description>&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;ArcGIS Maps SDK for Kotlin (version 200.6)&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 09 Sep 2025 07:09:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/kotlin-maps-sdk-questions/kotlin-sdk-how-to-load-geojson-file/m-p/1648824#M592</guid>
      <dc:creator>LiqiangZhu</dc:creator>
      <dc:date>2025-09-09T07:09:44Z</dc:date>
    </item>
    <item>
      <title>Re: Kotlin SDK how to load GeoJSON file</title>
      <link>https://community.esri.com/t5/kotlin-maps-sdk-questions/kotlin-sdk-how-to-load-geojson-file/m-p/1652751#M594</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/935019"&gt;@LiqiangZhu&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;STRONG&gt;&lt;SPAN&gt;Am I using the wrong method, or is there another recommended way to load a GeoJSON file?&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;The ArcGIS Maps SDKs don't support GeoJSON yet.&amp;nbsp;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;FeatureCollection.fromJsonOrNull&lt;/FONT&gt;&lt;/STRONG&gt; can only parse json that conforms with the &lt;A href="https://developers.arcgis.com/web-map-specification/" target="_self"&gt;webmap specification&lt;/A&gt;.&lt;BR /&gt;&lt;BR /&gt;You could parse the GeoJSON file by yourself to deserialize geometries and attributes. Once you have those you can create a Feature via &lt;A href="https://developers.arcgis.com/kotlin/api-reference/arcgis-maps-kotlin/com.arcgismaps.data/-feature-table/create-feature.html" target="_self"&gt;FeatureCollectionTable.createFeature&lt;/A&gt;&amp;nbsp;and adding the new feature to the feature table via &lt;A href="https://developers.arcgis.com/kotlin/api-reference/arcgis-maps-kotlin/com.arcgismaps.data/-feature-table/add-feature.html" target="_self"&gt;FeatureCollectionTable.addFeature&lt;/A&gt;. See &lt;A href="https://developers.arcgis.com/kotlin/api-reference/arcgis-maps-kotlin/com.arcgismaps.data/-feature-collection-table/index.html" target="_self"&gt;FeatureCollectionTable&lt;/A&gt; for how to create one.&lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://github.com/Esri/arcgis-maps-sdk-kotlin-samples/tree/main/samples/add-custom-dynamic-entity-data-source" target="_self"&gt;This sample&lt;/A&gt; shows how to parse geometries and attributes from json using &lt;A href="https://kotlinlang.org/api/kotlinx.serialization/kotlinx-serialization-json/kotlinx.serialization.json/-json/" target="_self"&gt;Kotlin json serialization&lt;/A&gt;. Relevant parsing code &lt;A href="https://github.com/Esri/arcgis-maps-sdk-kotlin-samples/blob/main/samples/add-custom-dynamic-entity-data-source/src/main/java/com/esri/arcgismaps/sample/addcustomdynamicentitydatasource/components/CustomEntityFeedProvider.kt#L146-L174" target="_self"&gt;here&lt;/A&gt;.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Sep 2025 10:16:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/kotlin-maps-sdk-questions/kotlin-sdk-how-to-load-geojson-file/m-p/1652751#M594</guid>
      <dc:creator>GuntherHeppner</dc:creator>
      <dc:date>2025-09-24T10:16:09Z</dc:date>
    </item>
    <item>
      <title>Re: Kotlin SDK how to load GeoJSON file</title>
      <link>https://community.esri.com/t5/kotlin-maps-sdk-questions/kotlin-sdk-how-to-load-geojson-file/m-p/1653697#M598</link>
      <description>&lt;P&gt;Thank you very much.I have solved this problem!&lt;/P&gt;</description>
      <pubDate>Sun, 28 Sep 2025 00:54:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/kotlin-maps-sdk-questions/kotlin-sdk-how-to-load-geojson-file/m-p/1653697#M598</guid>
      <dc:creator>LiqiangZhu</dc:creator>
      <dc:date>2025-09-28T00:54:22Z</dc:date>
    </item>
  </channel>
</rss>

