title: Error encountered checking Geometry returned from GEOS C function "GEOSGeom_createLinearRing_r"
body: <p>Trying to generate a polygon field for my region and cities for geotagging.
  Idea is to save the coordinates separately from Gmaps. Then use them to generate a region polygon. 
  For regions like NCR in India, you have multiple cities like Delhi, Noida. Gurgaon etc. So these cities form the subset of the polygon.</p>
  
  <p>So you create a polygon and save with every city, then make a multipolygon to save at a regional level.</p>
  
  <p>Encountered this error. Please help</p>
  
  <pre><code>from Geography.models import Region,City
  from django.contrib.gis.geos import Polygon,MultiPolygon
  
  coordinates={
      'JAL':{
      "type": "FeatureCollection",
  
      "features": [
          { "type": "Feature", "properties": { "Name": "jalandhar", "Description": "" }, "geometry": { "type": "Polygon", "coordinates": [ [ [ 75.510571, 31.384717, 0.0 ], [ 75.515237, 31.270770, 0.0 ], [ 75.683574,31.264225, 0.0 ], [ 75.672656,31.390200, 0.0 ] ] ] } }
          ]
      }
      }
  def add_polygons():
      r = Region.objects.last()
      city_coordinates = coordinates[r.name]['features']
      polygon=None
      for cx in city_coordinates:
          coo_list_ = cx['geometry']['coordinates'][0]
          coo_list =[[item[0],item[1]] for item in coo_list_]
          name = cx['properties']['Name']
          city=City.objects.filter(name__iexact=name).first()
          p = Polygon(coo_list)
          if city:
              city.poly=p
              city.save()
          if polygon:
              polygon=polygon.union(p)
          else: polygon=MultiPolygon(p)
      r.poly=Polygon(polygon.shell)
      r.save()
  
  
  add_polygons()
  </code></pre>
  
  <p>This is the error I get. Something about create linear ring function. I tried to go through the library itself but to no avail.</p>
  
  <pre><code>GEOSExceptionTraceback (most recent call last)
  &lt;ipython-input-5-81f3fb947f4f&gt; in &lt;module&gt;()
       36 }
       37 
  ---&gt; 38 add_polygons()
  
  &lt;ipython-input-5-81f3fb947f4f&gt; in add_polygons()
       11         name = cx['properties']['Name']
       12         city=City.objects.filter(name__iexact=name).first()
  ---&gt; 13         p = Polygon(coo_list)
       14         if city:
       15             city.poly=p
  
  /home/ubuntu/.virtualenvs/C24Aegis/local/lib/python2.7/site-packages/django/contrib/gis/geos/polygon.pyc in __init__(self, *args, **kwargs)
       46                 n_holes = len(init_holes)
       47 
  ---&gt; 48         polygon = self._create_polygon(n_holes + 1, (ext_ring,) + init_holes)
       49         super(Polygon, self).__init__(polygon, **kwargs)
       50 
  
  /home/ubuntu/.virtualenvs/C24Aegis/local/lib/python2.7/site-packages/django/contrib/gis/geos/polygon.pyc in _create_polygon(self, length, items)
       79                 rings.append(r)
       80             else:
  ---&gt; 81                 rings.append(self._construct_ring(r))
       82 
       83         shell = self._clone(rings.pop(0))
  
  /home/ubuntu/.virtualenvs/C24Aegis/local/lib/python2.7/site-packages/django/contrib/gis/geos/polygon.pyc in _construct_ring(self, param, msg)
      106             return param
      107         try:
  --&gt; 108             ring = LinearRing(param)
      109             return ring
      110         except TypeError:
  
  /home/ubuntu/.virtualenvs/C24Aegis/local/lib/python2.7/site-packages/django/contrib/gis/geos/linestring.pyc in __init__(self, *args, **kwargs)
       74         # Calling the base geometry initialization with the returned pointer
       75         #  from the function.
  ---&gt; 76         super(LineString, self).__init__(self._init_func(cs.ptr), srid=srid)
       77 
       78     def __iter__(self):
  
  /home/ubuntu/.virtualenvs/C24Aegis/local/lib/python2.7/site-packages/django/contrib/gis/geos/prototypes/threadsafe.pyc in __call__(self, *args)
       54             # Call the threaded GEOS routine with pointer of the context handle
       55             # as the first argument.
  ---&gt; 56             return self.cfunc(self.thread_context.handle.ptr, *args)
       57         else:
       58             return self.cfunc(*args)
  
  /home/ubuntu/.virtualenvs/C24Aegis/local/lib/python2.7/site-packages/django/contrib/gis/geos/prototypes/errcheck.pyc in check_geom(result, func, cargs)
       31     "Error checking on routines that return Geometries."
       32     if not result:
  ---&gt; 33         raise GEOSException('Error encountered checking Geometry returned from GEOS C function "%s".' % func.__name__)
       34     return result
       35 
  
  GEOSException: Error encountered checking Geometry returned from GEOS C function "GEOSGeom_createLinearRing_r".
  </code></pre>