title: Convert linestring to polygon of geojson file in Geopandas
body: <p>I have the following CAD file in <code>dxf</code> format which display in <code>autocad</code> looking like:
  <a href="https://i.stack.imgur.com/bjnib.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/bjnib.png" alt="enter image description here"></a></p>
  
  <p>I convert it to <code>geojson</code> format file named <code>test.geojson</code> with GDAL org2org but all in <code>type: LineString</code></p>
  
  <pre><code>{
  "type": "FeatureCollection",
  "name": "entities",
  "features": [
  { "type": "Feature", "properties": { "Layer": "0" }, "geometry": { "type": "LineString", "coordinates": [ [ 30.0, 0.0 ], [ 30.0, 9.0 ] ] } },
  { "type": "Feature", "properties": { "Layer": "0" }, "geometry": { "type": "LineString", "coordinates": [ [ 16.0, 47.0 ], [ 16.0, 34.0 ] ] } },
  { "type": "Feature", "properties": { "Layer": "0" }, "geometry": { "type": "LineString", "coordinates": [ [ 16.0, 13.0 ], [ 16.0, 0.0 ] ] } },
  { "type": "Feature", "properties": { "Layer": "0" }, "geometry": { "type": "LineString", "coordinates": [ [ 0.0, 31.0 ], [ 9.0, 31.0 ] ] } },
  { "type": "Feature", "properties": { "Layer": "0" }, "geometry": { "type": "LineString", "coordinates": [ [ 30.0, 31.0 ], [ 39.0, 31.0 ] ] } },
  { "type": "Feature", "properties": { "Layer": "0" }, "geometry": { "type": "LineString", "coordinates": [ [ 0.0, 23.0 ], [ 9.0, 23.0 ] ] } },
  { "type": "Feature", "properties": { "Layer": "0" }, "geometry": { "type": "LineString", "coordinates": [ [ 30.0, 23.0 ], [ 39.0, 23.0 ] ] } },
  { "type": "Feature", "properties": { "Layer": "0" }, "geometry": { "type": "LineString", "coordinates": [ [ 0.0, 16.0 ], [ 9.0, 16.0 ] ] } },
  { "type": "Feature", "properties": { "Layer": "0" }, "geometry": { "type": "LineString", "coordinates": [ [ 30.0, 16.0 ], [ 39.0, 16.0 ] ] } },
  { "type": "Feature", "properties": { "Layer": "0" }, "geometry": { "type": "LineString", "coordinates": [ [ 0.0, 0.0 ], [ 39.0, 0.0 ], [ 39.0, 47.0 ], [ 0.0, 47.0 ], [ 0.0, 0.0 ] ] } },
  { "type": "Feature", "properties": { "Layer": "0" }, "geometry": { "type": "LineString", "coordinates": [ [ 9.0, 38.0 ], [ 11.0, 38.0 ], [ 11.0, 34.0 ], [ 28.0, 34.0 ], [ 28.0, 38.0 ], [ 30.0, 38.0 ], [ 30.0, 9.0 ], [ 28.0, 9.0 ], [ 28.0, 13.0 ], [ 11.0, 13.0 ], [ 11.0, 9.0 ], [ 9.0, 9.0 ], [ 9.0, 38.0 ] ] } },
  { "type": "Feature", "properties": { "Layer": "0" }, "geometry": { "type": "LineString", "coordinates": [ [ 11.0, 32.0 ], [ 17.0, 32.0 ], [ 17.0, 15.0 ], [ 11.0, 15.0 ], [ 11.0, 32.0 ] ] } },
  { "type": "Feature", "properties": { "Layer": "0" }, "geometry": { "type": "LineString", "coordinates": [ [ 20.0, 32.0 ], [ 28.0, 32.0 ], [ 28.0, 15.0 ], [ 20.0, 15.0 ], [ 20.0, 32.0 ] ] } }
  ]
  }
  </code></pre>
  
  <p>I want to convert it to <code>type: polygon</code> with display as follow image showing:
  <a href="https://i.stack.imgur.com/igchF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/igchF.png" alt="enter image description here"></a></p>
  
  <p>How can I do that in Geopandas? Thanks.</p>
  
  <p>BTW, I read <code>test.geojson</code> file, it looks like:</p>
  
  <pre><code>import geopandas as gpd
  df = gpd.read_file("test.geojson")
  df.head(5)
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>  Layer               SubClasses EntityHandle                                           geometry
  0     0  AcDbEntity:AcDbPolyline          106  LINESTRING (30.35270412013777 0.79246615687498...
  1     0  AcDbEntity:AcDbPolyline          107  LINESTRING (16.16520412013776 47.1049661568749...
  2     0  AcDbEntity:AcDbPolyline          108  LINESTRING (16.16520412013776 13.4799661568749...
  3     0  AcDbEntity:AcDbPolyline          109  LINESTRING (0.665204120137787 31.2924661568749...
  4     0  AcDbEntity:AcDbPolyline          10A  LINESTRING (30.35270412013777 31.2924661568749...
  </code></pre>