Skip to content
Advertisement

How to create a geometry for each feature in a stringified geometry collection from a BigQuery JavaScript UDF?

I’m new to UDF functions and I have created a BigQuery UDF that takes a polygon geometry and creates points with it. I’m trying to draw dot density maps (converting polygon + population number to points). I’ve adapted the code from this blog post. Because bigQuery doesn’t have a way to log variables, I’ve been testing things out in this codepen.

I’m at a point where the function seems to work right. The output is a geometry collection of points. It says in the bigquery docs that st_geogfromgeojson can accept a geometry collection.

My UDF returns a stringified geometry collection.

But I cannot figure out why st_geogfromgeojson doesn’t work. I can’t tell if I’m simply not unnesting something or what.

But I keep hitting random errors like I’m not using the function right enter image description here

I’m open to all suggestions. I return a string for simplicity but perhaps I need to use a STRUCT. Perhaps I should cut out turf from creating the points? I must be missing something here.

Advertisement

Answer

Two things that fixed it:

  • Returning array<String> instead of string
  • CROSS JOIN UNNEST in the select
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement