title: Building a GeoJSON with Python
body: <p>I want to generate dynamically a geoJSON with a variable number of polygons. Example for 2 polygons:</p>
  
  <pre><code>{
      "type": "FeatureCollection", 
      "features": [
        {"geometry": {
            "type": "GeometryCollection", 
            "geometries": [
                {
                    "type": "Polygon", 
                    "coordinates": 
                        [[11.0878902207, 45.1602390564],
                         [0.8251953125, 41.0986328125], 
                         [7.63671875, 48.96484375], 
                         [15.01953125, 48.1298828125]]
                }, 
                {
                    "type": "Polygon", 
                    "coordinates": 
                        [[11.0878902207, 45.1602390564], 
                         [14.931640625, 40.9228515625], 
                         [11.0878902207, 45.1602390564]]
                }
            ]
        }, 
        "type": "Feature", 
        "properties": {}}
      ]
  }
  </code></pre>
  
  <p>I have a function which gives me the list of coordinates for each polygon, so I can create a list of polygons, so I am able to build the geoJSON iterating it with a for loop.</p>
  
  <p>The problem is that I don't see how to do it easily (I thought for example in returning the list as a string, but building the geoJSON as a string looks like a bad idea).</p>
  
  <p>I have been suggested this very pythonic idea:</p>
  
  <pre><code>geo_json = [ {"type": "Feature",,
                "geometry": {
                    "type": "Point",
                    "coordinates": [lon, lat] }}
                for lon, lat in zip(ListOfLong,ListOfLat) ] 
  </code></pre>
  
  <p>But since I am adding a variable number of Polygons instead of a list of points, this solutions does not seem suitable. Or at least I don't know how to adapt it.</p>
  
  <p>I could build it as a string, but I'd like to do it in a smarter way. Any idea?</p>