title: Python: Cannot convert json with geometry collections to shapefile OGR2OGR: a way to explode those features?
body: <p>I finally found a way to convert JSON (GEOJSON formated) file to a shapefile using ogr2ogr. However I am encountering a new problem.</p>
  <p>You <strong>see some of the features in my JSON file</strong> are actually a geometry collection, and this collection can either be a polygon or multipolygon by type. I am posting some examples here below:. But the main point is OGR2OGR cannot connvert these so how do I &quot;explode&quot; them in the right types without losing data?</p>
  <p>Code I use to save:</p>
  <pre><code>import requests
  import flask
  import json
  import os
  import time
  from datetime import timedelta
  from datetime import datetime
  from datetime import date
  import pandas as pd
  import shutil
  import zipfile
  import smtplib, ssl
  from tqdm import tqdm
  from time import sleep
  from osgeo import ogr
  from osgeo import gdal
  import ogr2ogr
  import geopandas
  import fiona
  
  def convert_json_to_shapefile(fc_file):
     total_start_time = start_time_measure()
     start_time = start_time_measure(
     'opening geojson file')
     export_folder = os.path.join(&quot;exported_data&quot;,&quot;geographic_information&quot;,&quot;details&quot;,&quot;Shapefile&quot;)
     shapefile = os.path.join(export_folder + &quot;geographic_information_details&quot;+&quot;.shp&quot;)
     ogr2ogr.main([&quot;-f&quot;, &quot;ESRI Shapefile&quot;, export_folder , fc_file])
  </code></pre>
  <p>This is example of a normal feature:</p>
  <pre><code>&quot;type&quot;: &quot;Feature&quot;,
              &quot;geometry&quot;: {
                  &quot;coordinates&quot;: [
                      [
                          [
                              148162.37,
                              199935.45
                          ],
                          [
                              148128.19,
                              199917.9
                          ],
                          [
                              148120.8,
                              199915.13
                          ],
                          [
                              148114.79,
                              199916.51
                          ],
                          [
                              148112.94,
                              199918.36
                          ],
                          [
                              148100.01,
                              199910.51
                          ],
                          [
                              148099.55,
                              199904.96
                          ],
                          [
                              148097.7,
                              199902.19
                          ],
                          [
                              148092.16,
                              199899.88
                          ],
                          [
                              148088.46,
                              199897.11
                          ],
                          [
                              148087.54,
                              199899.42
                          ],
                          [
                              148056.59,
                              199890.64
                          ],
                          [
                              148057.51,
                              199887.41
                          ],
                          [
                              148036.73,
                              199891.11
                          ],
                          [
                              148030.72,
                              199892.95
                          ],
                          [
                              148027.03,
                              199894.8
                          ],
                          [
                              148025.18,
                              199897.11
                          ],
                          [
                              148021.48,
                              199894.8
                          ],
                          [
                              148023.33,
                              199892.03
                          ],
                          [
                              148044.12,
                              199887.41
                          ],
                          [
                              148061.21,
                              199885.1
                          ],
                          [
                              148099.09,
                              199896.65
                          ],
                          [
                              148128.19,
                              199914.66
                          ],
                          [
                              148151.74,
                              199924.83
                          ],
                          [
                              148164.68,
                              199930.83
                          ],
                          [
                              148162.37,
                              199935.45
                          ]
                      ]
                  ],
                  &quot;type&quot;: &quot;Polygon&quot;,
                  &quot;crs&quot;: {
                      &quot;type&quot;: &quot;name&quot;,
                      &quot;properties&quot;: {
                          &quot;name&quot;: &quot;urn:ogc:def:crs:EPSG::31370&quot;
                      }
                  }
              },
              &quot;properties&quot;: {
                  &quot;gipodId&quot;: 4108418,
                  &quot;StartDateTime&quot;: &quot;1899-12-31T07:00:00&quot;,
                  &quot;EndDateTime&quot;: &quot;2018-11-22T17:00:00&quot;,
                  &quot;sper_date_time&quot;: &quot;2023-11-22T17:00:00&quot;,
                  &quot;state&quot;: &quot;Concreet gepland&quot;,
                  &quot;type&quot;: &quot;wegeniswerken (her)aanleg&quot;,
                  &quot;owner&quot;: &quot;Gemeente Niel&quot;,
                  &quot;reference&quot;: &quot;NIE-0000000081&quot;,
                  &quot;location&quot;: {
                      &quot;cities&quot;: [
                          &quot;Niel&quot;
                      ],
                      &quot;coordinate&quot;: {
                          &quot;coordinates&quot;: [
                              148108.39039977788,
                              199907.735
                          ],
                          &quot;type&quot;: &quot;Point&quot;,
                          &quot;crs&quot;: {
                              &quot;type&quot;: &quot;name&quot;,
                              &quot;properties&quot;: {
                                  &quot;name&quot;: &quot;urn:ogc:def:crs:EPSG::31370&quot;
                              }
                          }
                      }
                  }
              }
          },
  </code></pre>
  <p>And here is the example of a geometry collection as:</p>
  <pre><code>&quot;type&quot;: &quot;Feature&quot;,
              &quot;geometry&quot;: {
                  &quot;geometries&quot;: [
                      {
                          &quot;coordinates&quot;: [
                              [
                                  [Made empty because of charc limit
                                  ]
                              ],
                              [ Made empty because of charcter limit                                                    ]
                              ]
                          ]
                      ],
                      &quot;type&quot;: &quot;MultiPolygon&quot;,
                      &quot;crs&quot;: null
                  }
              ],
              &quot;type&quot;: &quot;GeometryCollection&quot;,
              &quot;crs&quot;: {
                  &quot;type&quot;: &quot;name&quot;,
                  &quot;properties&quot;: {
                      &quot;name&quot;: &quot;urn:ogc:def:crs:EPSG::31370&quot;
                  }
              }
          },
  </code></pre>
  <p>As an example for a example of a not multi Polygon:</p>
  <pre><code>                &quot;type&quot;: &quot;Polygon&quot;,
                  &quot;crs&quot;: null
              }
          ],
          &quot;type&quot;: &quot;GeometryCollection&quot;,
          &quot;crs&quot;: {
              &quot;type&quot;: &quot;name&quot;,
              &quot;properties&quot;: {
                  &quot;name&quot;: &quot;urn:ogc:def:crs:EPSG::31370&quot;
              }
          }
  </code></pre>