Skip to content

geo: fix GeoJSON and allow options in ST_AsGeoJSON#49888

Merged
craig[bot] merged 1 commit intocockroachdb:masterfrom
otan-cockroach:geojson
Jun 8, 2020
Merged

geo: fix GeoJSON and allow options in ST_AsGeoJSON#49888
craig[bot] merged 1 commit intocockroachdb:masterfrom
otan-cockroach:geojson

Conversation

@otan
Copy link
Copy Markdown
Contributor

@otan otan commented Jun 4, 2020

There was a bug in GeoJSON where we used the high level name:"Feature"
field, as opposed to the inner Geometry. This has been fixed.

We also support more options for ST_AsGeoJSON now that these changes are
in twpayne/go-geom.

Resolves #48381.

Release note (sql change): Implement ST_AsGeoJSON with options to show
bbox and CRS information.

@otan otan requested review from a team and sumeerbhola June 4, 2020 23:37
@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

@otan otan force-pushed the geojson branch 4 times, most recently from 062fb41 to 59292a9 Compare June 5, 2020 23:46
Copy link
Copy Markdown
Collaborator

@sumeerbhola sumeerbhola left a comment

Choose a reason for hiding this comment

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

Reviewed 9 of 9 files at r1.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @otan)


pkg/geo/encode_test.go, line 99 at r1 (raw file):

		{"SRID=4004;POINT(1.0 1.0)", EWKBToGeoJSONFlagShortCRS, `{"type":"Point","crs":{"type":"name","properties":{"name":"EPSG:4004"}},"coordinates":[1,1]}`},
		{"SRID=4004;POINT(1.0 1.0)", EWKBToGeoJSONFlagShortCRS | EWKBToGeoJSONFlagIncludeBBox, `{"type":"Point","bbox":[1,1,1,1],"crs":{"type":"name","properties":{"name":"EPSG:4004"}},"coordinates":[1,1]}`},
		{"SRID=4326;POINT(1.0 1.0)", EWKBToGeoJSONFlagShortCRSIfNot4326, `{"type":"Point","coordinates":[1,1]}`},

can you repeat this last case with "SRID=4004"


pkg/geo/parse_test.go, line 228 at r1 (raw file):

		},
		{
			`{ "type": "Point", "coordinates": [1.0, 1.0] }`,

I'm assuming we don't currently support the following "feature" example from the PostGIS documentation -- correct?

SELECT ST_AsGeoJSON(t.*)
FROM (VALUES
  (1, 'one', 'POINT(1 1)'::geometry),
  (2, 'two', 'POINT(2 2)'),
  (3, 'three', 'POINT(3 3)'))
AS t(id, name, geom);
                                                  st_asgeojson
-----------------------------------------------------------------------------------------------------------------
 {"type": "Feature", "geometry": {"type":"Point","coordinates":[1,1]}, "properties": {"id": 1, "name": "one"}}
 {"type": "Feature", "geometry": {"type":"Point","coordinates":[2,2]}, "properties": {"id": 2, "name": "two"}}
 {"type": "Feature", "geometry": {"type":"Point","coordinates":[3,3]}, "properties": {"id": 3, "name": "three"}}

pkg/sql/sem/builtins/geo_builtins.go, line 948 at r1 (raw file):

Options is a flag that can be bitmasked. The options are:
* 0: no option

https://postgis.net/docs/ST_AsGeoJSON.html suggests 0 is the default for geography
text ST_AsGeoJSON(geography geog, integer maxdecimaldigits=9, integer options=0);

Copy link
Copy Markdown
Contributor Author

@otan otan left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @sumeerbhola)


pkg/geo/encode_test.go, line 99 at r1 (raw file):

Previously, sumeerbhola wrote…

can you repeat this last case with "SRID=4004"

Done.


pkg/geo/parse_test.go, line 228 at r1 (raw file):

Previously, sumeerbhola wrote…

I'm assuming we don't currently support the following "feature" example from the PostGIS documentation -- correct?

SELECT ST_AsGeoJSON(t.*)
FROM (VALUES
  (1, 'one', 'POINT(1 1)'::geometry),
  (2, 'two', 'POINT(2 2)'),
  (3, 'three', 'POINT(3 3)'))
AS t(id, name, geom);
                                                  st_asgeojson
-----------------------------------------------------------------------------------------------------------------
 {"type": "Feature", "geometry": {"type":"Point","coordinates":[1,1]}, "properties": {"id": 1, "name": "one"}}
 {"type": "Feature", "geometry": {"type":"Point","coordinates":[2,2]}, "properties": {"id": 2, "name": "two"}}
 {"type": "Feature", "geometry": {"type":"Point","coordinates":[3,3]}, "properties": {"id": 3, "name": "three"}}

Yeah we don't suppoer the "record" type.


pkg/sql/sem/builtins/geo_builtins.go, line 948 at r1 (raw file):

Previously, sumeerbhola wrote…

https://postgis.net/docs/ST_AsGeoJSON.html suggests 0 is the default for geography
text ST_AsGeoJSON(geography geog, integer maxdecimaldigits=9, integer options=0);

oops, typo

Copy link
Copy Markdown
Collaborator

@sumeerbhola sumeerbhola left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewed 3 of 3 files at r2.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @sumeerbhola)

@otan
Copy link
Copy Markdown
Contributor Author

otan commented Jun 8, 2020

bors r=sumeerbhola

@otan
Copy link
Copy Markdown
Contributor Author

otan commented Jun 8, 2020

bors r-

@craig
Copy link
Copy Markdown
Contributor

craig bot commented Jun 8, 2020

Canceled

There was a bug in GeoJSON where we used the high level name:"Feature"
field, as opposed to the inner Geometry. This has been fixed.

We also support more options for ST_AsGeoJSON now that these changes are
in twpayne/go-geom.

Release note (sql change): Implement ST_AsGeoJSON with options to show
bbox and CRS information.
@otan
Copy link
Copy Markdown
Contributor Author

otan commented Jun 8, 2020

bors r=sumeerbhola

@craig
Copy link
Copy Markdown
Contributor

craig bot commented Jun 8, 2020

Merge conflict (retrying...)

1 similar comment
@craig
Copy link
Copy Markdown
Contributor

craig bot commented Jun 8, 2020

Merge conflict (retrying...)

@craig
Copy link
Copy Markdown
Contributor

craig bot commented Jun 8, 2020

Build succeeded

@craig craig bot merged commit 31d7475 into cockroachdb:master Jun 8, 2020
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.

geo/geogfn: implement ST_AsGeoJSON({geography,int4,int4})

3 participants