1

I have many polygons one example is like so

POLYGON ((-6.17635568766753 106.81217949327073, -6.177086740025682 106.81236308865992, -6.177909092611173 106.81256741425203, -6.178459760710375 106.81270423581032, -6.178946642579903 106.81282348367647,-6.17635568766753 106.81217949327073)) 

The position is all wrong so when I used ST_GEOGFROMTEXT in BigQuery it reads wrong. How do I reverse the position so that the polygon becomes like so

POLYGON ((106.81217949327073 -6.17635568766753,  106.81236308865992 -6.177086740025682,  106.81256741425203 -6.177909092611173,  106.81270423581032 -6.178459760710375,  106.81282348367647 -6.178946642579903, 106.81217949327073 -6.17635568766753))

so that when I use ST_Within it's able to read the polygon data.

How can I do this in BigQuery?

2
  • 1
    Welcome to GIS SE. As a new user, please take the Tour, which emphasizes the importance of asking One question per Question.. Please Edit the Question to choose one of the two platforms (Python or BigQuery), and include your coding attempt.
    – Vince
    Commented Nov 11, 2022 at 13:52
  • My solution here would probably help to solve this here too: gis.stackexchange.com/questions/485485/…
    – cputoaster
    Commented Oct 22 at 15:11

1 Answer 1

1

Use Python (list comprehension)

from shapely.geometry import Polygon
from shapely.wkt import loads
poly = loads("POLYGON ((-6.17635568766753 106.81217949327073, -6.177086740025682 106.81236308865992, -6.177909092611173 106.81256741425203, -6.178459760710375 106.81270423581032, -6.178946642579903 106.81282348367647,-6.17635568766753 106.81217949327073)) ")
print(poly)
POLYGON ((-6.17635568766753 106.8121794932707, -6.177086740025682 106.8123630886599, -6.177909092611173 106.812567414252, -6.178459760710375 106.8127042358103, -6.178946642579903 106.8128234836765, -6.17635568766753 106.8121794932707))

ring = list(poly.exterior.coords)
new_ring = [(lat,lon) for (lon,lat) in ring]
poly2 = Polygon(new_ring)
print(poly2)
POLYGON ((106.8121794932707 -6.17635568766753, 106.8123630886599 -6.177086740025682, 106.812567414252 -6.177909092611173, 106.8127042358103 -6.178459760710375, 106.8128234836765 -6.178946642579903, 106.8121794932707 -6.17635568766753))
1

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.