4

I am trying to upload the FCC's Study Area Boundaries into Google BigQuery for analysis with other data. I used QGIS to fix the geometries and convert the shapefile to a newline delimited geojson. Shapely and QGIS say that all the polygons in the geojson are valid. However, when I attempt to make a BigQuery table from the geojson, BigQuery has the following error:

Could not convert JSON value to geography: Invalid polygon loop: Edge 52 crosses edge 54; in loop 15 Field: geometry; Value: {"type": "MultiPolygon", "coordinates": [[[[-71.084213, 45.305475], [-71.084695, 45.305694], ...

I found the coordinates for edge 52 and edge 54 in loop 15, and this is what they look like in QGIS:Edge 52 goes down at an acute angle, Edge 53 goes to the right, and then edge 54 goes to the left across edge 53. Edge 52 touches edge 54 but doesn't actually cross it. If I remove the coordinate that sticks out, the error changes to be about another set of points that do the same thing.

How can I find all the errors of this type, and, ideally, fix them without manually removing each extraneous coordinate?

2 Answers 2

4

BigQuery can now repair such polygons too, see make_valid argument to st_geogfromgeojson.

https://cloud.google.com/bigquery/docs/reference/standard-sql/geography_functions#st_geogfromgeojson

And here is a post with some guidelines:

https://mentin.medium.com/new-options-for-bigquery-gis-geospatial-data-ingestion-9b05eb1abea

2
  • If I understand we have to download the corrupted polygon and after fixing it (by creating a new table) in BQ. Is there any way to doing the fix when loading the CSV file?
    – ucsky
    Commented Sep 23, 2021 at 9:00
  • It would be useful to have this in ST_GeogFrom also, given that there is no ST_MakeValid function in BQ. Commented Sep 28, 2023 at 12:47
1

This kind of topological error can creep into a dataset depending upon how the data was created. A self intersection can be fixed using the Repair geometry tool in ArcMap.

Here is a polygon with a self intersection Error

After running the dataset through the Repair tool we see that it has removed this self-intersecting spur.

Cleaned

Warning: always run this sort of bulk correction on a backed up dataset as sometime these can cause more problems than they fix!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.