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

Merged
merged 4 commits into from
Nov 26, 2024
Merged

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 68.84422% with 62 lines in your changes missing coverage. Please review.

Project coverage is 63.93%. Comparing base (59551e4) to head (fa39c6c).
Report is 1391 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 ⚠️
...sform/function/BaseBinaryGeoTransformFunction.java 66.66% 8 Missing ⚠️
...patial/transform/function/StAsGeoJsonFunction.java 73.91% 4 Missing and 2 partials ⚠️
...ospatial/transform/function/StPolygonFunction.java 0.00% 6 Missing ⚠️
...ansform/function/ConstructFromGeoJsonFunction.java 83.33% 2 Missing and 2 partials ⚠️
...geospatial/transform/function/ScalarFunctions.java 0.00% 3 Missing ⚠️
...eospatial/transform/function/StAsTextFunction.java 81.81% 2 Missing ⚠️
.../transform/function/ConstructFromTextFunction.java 83.33% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master   #14405      +/-   ##
============================================
+ Coverage     61.75%   63.93%   +2.18%     
- Complexity      207     1570    +1363     
============================================
  Files          2436     2681     +245     
  Lines        133233   147100   +13867     
  Branches      20636    22568    +1932     
============================================
+ Hits          82274    94047   +11773     
- Misses        44911    46125    +1214     
- Partials       6048     6928     +880     
Flag Coverage Δ
custom-integration1 100.00% <ø> (+99.99%) ⬆️
integration 100.00% <ø> (+99.99%) ⬆️
integration1 100.00% <ø> (+99.99%) ⬆️
integration2 0.00% <ø> (ø)
java-11 63.89% <68.84%> (+2.18%) ⬆️
java-21 63.81% <68.84%> (+2.18%) ⬆️
skip-bytebuffers-false 63.92% <68.84%> (+2.18%) ⬆️
skip-bytebuffers-true 63.77% <68.84%> (+36.04%) ⬆️
temurin 63.93% <68.84%> (+2.18%) ⬆️
unittests 63.92% <68.84%> (+2.18%) ⬆️
unittests1 55.69% <68.84%> (+8.80%) ⬆️
unittests2 34.51% <3.01%> (+6.78%) ⬆️

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.

@Jackie-Jiang Jackie-Jiang added feature geo documentation release-notes Referenced by PRs that need attention when compiling the next release notes labels Nov 25, 2024
@Jackie-Jiang
Copy link
Contributor

Jackie-Jiang commented Nov 25, 2024

Standard function documentation:

Seems ST_GeogFromGeoJSON is not a standard geo function?

Copy link
Contributor

@Jackie-Jiang Jackie-Jiang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly good

@Jackie-Jiang Jackie-Jiang merged commit b34e805 into apache:master Nov 26, 2024
21 checks passed
@Jackie-Jiang
Copy link
Contributor

Great job! Please help also update the pinot documentation for these new functions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation feature geo release-notes Referenced by PRs that need attention when compiling the next release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants