Warm tip: This article is reproduced from serverfault.com, please click

How to load MULTIPOLYGON data from CSV into Bigquery?

发布于 2020-11-29 00:02:08

I am trying to load MULTIPOLYGON data from csv into BigQuery.

csv data example:

MULTIPOLYGON (((-87.6641550000406 41.95200900002041, -87.66414600001889 41.95172499998634, -87.66413300004291 41.951287000019256, -87.6641250000014 41.950975999991, -87.66411799997235 41.950710999997796, -87.66410699996321 41.95034600003051, -87.6640770000379 41.94925300002996, -87.66406700002733 41.948889000025126, -87.66405600002722 41.948524000007794, -87.66402699996873 41.94754299997942, -87.6640239999718 41.947431999990286, -87.664014999989 41.94706800000302, -87.66425699995835 41.94706299998119, -87.66463300004028 41.947057000019434, -87.66498599997365 41.94705200001454, -87.6652299999552 41.94704900003057, -87.66547100004216 41.94704499999217, -87.66619700000436 41.94703200001018, -87.66643899997062 41.94702899996759, -87.66668100004101 41.94702499997284, -87.66740899996688 41.94701300001905, -87.66765200003078 41.947009999995494, -87.66789300003049 41.94700500002556, -87.66825299997625 41.94700000001595, -87.66861599999213 41.94699100002117, -87.66866599995834 41.946989999984524, -87.66885799997794 41.946990000007425, -87.66886599999077 41.947353999977324, -87.6688750000215 41.947693000027144, -87.66889399995708 41.948214000019604, -87.66889900002306 41.948449000008935, -87.6689069999759 41.948814000013044, -87.66891599997123 41.949179000018155, -87.66894600003023 41.95027399996467, -87.6689559999787 41.950640000027136, -87.66896700002104 41.951005000030705, -87.66897100003573 41.951096999964946, -87.66898999998284 41.951944000026266, -87.6689930000197 41.952100000007114, -87.66900099996057 41.95246599997254, -87.66900800001966 41.95282999997927, -87.66901199997486 41.95299300002933, -87.66903400002491 41.95376499998745, -87.66903799997867 41.953924999970994, -87.66904899998285 41.95428999996699, -87.66874299998453 41.95429399998331, -87.66782499995624 41.9543060000087, -87.66751899999723 41.9543099999868, -87.66718399995784 41.95431399999949, -87.66679100003039 41.954318999986775, -87.66617900001958 41.954326999994244, -87.66584500001142 41.95433199997959, -87.66551799995953 41.95433599999768, -87.66454100003902 41.954349999976834, -87.66421499999196 41.9543549999717, -87.6642069999705 41.95399000002565, -87.6642040000364 41.95383100001683, -87.66418300000497 41.95305699999469, -87.66417899997418 41.95294300000901, -87.6641770000175 41.952896999978314, -87.66416900002824 41.95253299999764, -87.66415999996775 41.95222099998195, -87.6641550000406 41.95200900002041)))

I read the csv data into pandas dataframe, and when i load the data to bigquery using

    job_config = bigquery.LoadJobConfig(
    schema=[
        bigquery.SchemaField("geo_column", bigquery.enums.SqlTypeNames.GEOGRAPHY),
    ],
    write_disposition="WRITE_TRUNCATE",
)

job = client.load_table_from_dataframe(
    df_gps_data, table_id, job_config=job_config
)
job.result() 

Its inserted the data as POLYGON((*******)) into BigQuery not as MULTIPOLYGON.

So how i can insert the data as MULTIPOLYGON into BigQuery? Thanks in advance.

Questioner
Ashok
Viewed
0
rmesteves 2020-12-01 00:37:32

The problem is that you are discribing a MULTIPOLYGON with only one POLYGON inside which is basicaly a normal POLYGON.

If you define a MULTYPOLIGON as bellow, following this definition, you will have a MultiPolygon in BigQuery.

MULTIPOLYGON (((40 40, 20 45, 45 30, 40 40)),
((20 35, 10 30, 10 10, 30 5, 45 20, 20 35),
(30 20, 20 15, 20 25, 30 20)))