Skip to content

Commit

Permalink
CASL-663 fix GEO_JSON decoding in naksha.sql
Browse files Browse the repository at this point in the history
Signed-off-by: Jakub Amanowicz <[email protected]>
  • Loading branch information
Amaneusz committed Nov 12, 2024
1 parent 126b50b commit cfcbada
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ internal object WriteFeatureUtils {
feature = PgUtil.encodeFeature(feature, flags, encodingDict),
tags = PgUtil.encodeTags(
feature.properties.xyz.tags?.toTagMap(),
storage.defaultFlags,
flags,
encodingDict
),
attachment = attachment,
Expand Down
22 changes: 22 additions & 0 deletions here-naksha-lib-psql/src/commonTest/kotlin/naksha/psql/SridTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import naksha.geo.SpLineString
import naksha.model.*
import naksha.model.GeoEncoding.GeoEncoding_C.EWKB
import naksha.model.GeoEncoding.GeoEncoding_C.EWKB_GZIP
import naksha.model.GeoEncoding.GeoEncoding_C.GEO_JSON
import naksha.model.GeoEncoding.GeoEncoding_C.GEO_JSON_GZIP
import naksha.model.GeoEncoding.GeoEncoding_C.TWKB
import naksha.model.GeoEncoding.GeoEncoding_C.TWKB_GZIP
import naksha.model.GeoEncoding.GeoEncoding_C.WKB
Expand Down Expand Up @@ -65,6 +67,16 @@ class SridTest : PgTestBase() {
encodingName = "EWKB_GZIP",
flags = flagsFor(EWKB_GZIP),
collectionId = "srid_test_ewkb_gzip"
),
GEO_JSON to SridTestConfig(
encodingName = "GEO_JSON",
flags = flagsFor(GEO_JSON),
collectionId = "srid_test_geojson"
),
GEO_JSON_GZIP to SridTestConfig(
encodingName = "GEO_JSON_GZIP",
flags = flagsFor(GEO_JSON_GZIP),
collectionId = "srid_test_geojson_gzip"
)
)
}
Expand Down Expand Up @@ -113,6 +125,16 @@ class SridTest : PgTestBase() {
runTestFor(EWKB_GZIP)
}

@Test
fun shouldPreserveSridForGeoJson() {
runTestFor(GEO_JSON)
}

@Test
fun shouldPreserveSridForGeoJsonGzip() {
runTestFor(GEO_JSON_GZIP)
}

private fun runTestFor(encoding: Int) {
// Given: test config
val testConfig = testConfigs[encoding]
Expand Down
2 changes: 1 addition & 1 deletion here-naksha-lib-psql/src/jvmMain/resources/naksha.sql
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ BEGIN
elsif (encoding = 4) then
RETURN ST_GeomFromEWKB(geo);
elsif (encoding = 6) then
RETURN ST_GeomFromGeoJSON(geo::text);
RETURN ST_GeomFromGeoJSON(convert_from(geo, 'UTF8'));
end if;
-- Unknown encoding
return null;
Expand Down

0 comments on commit cfcbada

Please sign in to comment.