Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GeoJSON support. #14405

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

bziobrowski
Copy link
Contributor

@bziobrowski bziobrowski commented Nov 7, 2024

This PR adds support for GeoJSON format (see 1 & 2) via following functions:

ST_GeomFromGeoJson(string) -> binary
ST_GeogFromGeoJson(string) -> binary
ST_AsGeoJson(binary) -> string

Supported data types:

  • Point
  • LineString
  • Polygon
  • MultiPoint
  • MultiLineString
  • MultiPolygon
  • GeometryCollection
  • Feature
  • FeatureCollection

Examples:

A. Convert from WKT to GeoJSON:

  • convert Point geometry
select ST_AsGeoJson(ST_GeomFromText('POINT (1 2)'))

returns

{ 
  "type":"Point",
  "coordinates":[1,2],
  "crs":{"type":"name","properties":{"name":"EPSG:0"}}
}
  • convert point geography
select ST_AsGeoJson(ST_GeogFromText('POINT (1 2)'))

returns

{
  "type":"Point",
  "coordinates":[1,2],
  "crs":{"type":"name","properties":{"name":"EPSG:4326"}}
}
  • convert MultiLineString geometry
select ST_AsGeoJson(ST_GeomFromText('MULTILINESTRING ((1 1, 5 1), (2 4, 4 4))'))

returns

{
  "type":"MultiLineString",
  "coordinates":[[[1,1],[5,1]],[[2,4],[4,4]]],
  "crs":{"type":"name","properties":{"name":"EPSG:0"}}
}
  • convert MultiLineString geography
select ST_AsGeoJson(ST_GeogFromText('MULTILINESTRING ((1 1, 5 1), (2 4, 4 4))')) 

returns

{
  "type":"MultiLineString",
  "coordinates":[[[1,1],[5,1]],[[2,4],[4,4]]],
  "crs":{"type":"name","properties":{"name":"EPSG:4326"}}
}

B. Convert from GeoJson to WKT:

  • convert Point geometry
select ST_AsText(ST_GeomFromGeoJson('{"type":"Point","coordinates":[1,2]}')) 

returns
POINT (1 2)

  • convert MultiLineString geometry
select ST_AsText(ST_GeomFromGeoJson('{"type":"MultiLineString","coordinates":[[[1,1],[5,1]],[[2,4],[4,4]]]}'')

returns
MULTILINESTRING ((1 1, 5 1), (2 4, 4 4))

References:

  1. https://geojson.org/
  2. https://datatracker.ietf.org/doc/html/rfc7946

@codecov-commenter
Copy link

codecov-commenter commented Nov 7, 2024

Codecov Report

Attention: Patch coverage is 62.50000% with 48 lines in your changes missing coverage. Please review.

Project coverage is 63.75%. Comparing base (59551e4) to head (6d5545e).
Report is 1299 commits behind head on master.

Files with missing lines Patch % Lines
...re/geospatial/transform/function/StringReader.java 40.62% 18 Missing and 1 partial ⚠️
...patial/transform/function/StringBuilderWriter.java 43.47% 13 Missing ⚠️
...ansform/function/ConstructFromGeoJsonFunction.java 76.92% 3 Missing and 3 partials ⚠️
...patial/transform/function/StAsGeoJsonFunction.java 72.72% 3 Missing and 3 partials ⚠️
...geospatial/transform/function/ScalarFunctions.java 0.00% 3 Missing ⚠️
...eospatial/transform/function/StAsTextFunction.java 85.71% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master   #14405      +/-   ##
============================================
+ Coverage     61.75%   63.75%   +2.00%     
- Complexity      207     1556    +1349     
============================================
  Files          2436     2666     +230     
  Lines        133233   146102   +12869     
  Branches      20636    22363    +1727     
============================================
+ Hits          82274    93149   +10875     
- Misses        44911    46059    +1148     
- Partials       6048     6894     +846     
Flag Coverage Δ
custom-integration1 100.00% <ø> (+99.99%) ⬆️
integration 100.00% <ø> (+99.99%) ⬆️
integration1 100.00% <ø> (+99.99%) ⬆️
integration2 0.00% <ø> (ø)
java-11 63.74% <62.50%> (+2.03%) ⬆️
java-21 63.64% <62.50%> (+2.01%) ⬆️
skip-bytebuffers-false 63.75% <62.50%> (+2.00%) ⬆️
skip-bytebuffers-true 63.62% <62.50%> (+35.89%) ⬆️
temurin 63.75% <62.50%> (+2.00%) ⬆️
unittests 63.75% <62.50%> (+2.00%) ⬆️
unittests1 55.46% <62.50%> (+8.57%) ⬆️
unittests2 34.12% <4.68%> (+6.39%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants