Skip to content

GeoJSON to GeoShapeQuery #1926

Closed Answered by cramey
cramey asked this question in Q&A
Dec 3, 2023 · 2 comments · 1 reply
Discussion options

You must be logged in to vote

What that testing function does is unmarshal several GeoShapeQuerys to compare expected results with output. It's not a complete answer because it uses query.ParseQuery() and expects JSON compatible with a GeoShapeQuery, which includes GeoJSON, but isn't exclusively GeoJSON. It did lead me around to geo.ParseGeoJSONShape(), which can be used to Unmarshal GeoJSON into struct compatible with a GeoShapeQuery. Here's my code:

shape, err := geo.ParseGeoJSONShape([]byte(geojson))
if err != nil {
	// Handle error
}

gs_query := &query.GeoShapeQuery{
	FieldVal: "geog",
	Geometry: query.Geometry{
		Shape: shape,
		Relation: "intersects",
	},
}

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@cramey
Comment options

Answer selected by cramey
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants