I downloaded the data provided here as KML, exported to ESRI Shapefile format, checked it on QGIS and everything looked fine.

Upon trying to use the layermapping utility of Geodjango I am getting the error

GEOS_ERROR: IllegalArgumentException: Points of LinearRing do not form a closed linestring

Failed to save the feature (id: 0) into the model with the keyword arguments:
{'altitudemo': u'', 'extrude': -1, 'runner_ups': u'AAP', 'draworder': 0, 'p_name': u'NORTH EAST DELHI', 'votes': u'49262.00', 'runner_up_field': u'32.50', 'candidate': u'MOHAN SINGH BISHT', 'winner': u'Bharatiya Janata Party', 'tessellate': -1, 'vote_field': u'34.66', 'geom': u'MULTIPOLYGON (((77.248008 28.711174,77.251014 28.72256,77.247374 28.733358,77.245499 28.736973,77.243332 28.738912,77.23678 28.740053,77.227544 28.748189,77.221174 28.757834,77.218515 28.766839,77.218009 28.773173,77.218207 28.776626,77.22166 28.775307,77.226249 28.774572,77.231378 28.775763,77.23772 28.775777,77.235239 28.771893,77.230353 28.769839,77.233999 28.766292,77.234218 28.766079,77.242392 28.76065,77.242917 28.759898,77.251563 28.747505,77.259406 28.745651,77.261968 28.745844,77.26676 28.741124,77.265621 28.733862,77.2675 28.731486,77.270002 28.728323,77.270182 28.728237,77.27376 28.726525,77.280104 28.727693,77.284836 28.726613,77.290597 28.722847,77.293376 28.719749,77.287849 28.714193,77.28379 28.709277,77.28154 28.707232,77.279965 28.707642,77.279149 28.708071,77.2787 28.709253,77.277884 28.709682,77.276563 28.709187,77.275708 28.707539,77.274719 28.703963,77.27533 28.698065,77.276238 28.696696,77.27954 28.696382,77.279897 28.694005,77.278186 28.693838,77.274373 28.694234,77.246156 28.700983,77.245719 28.701041)))', 'begin': None, 'parliament': u'2', 'assembly': u'70.00', 'runner_up': u'Aam Aadmi Party', 'timestamp': None, 'assembly_1': u'KARAWAL NAGAR', 'winners': u'BJP', 'visibility': -1, 'end': None, 'icon': u''}

It looks fine on Google FT and map, as well as QGIS. I am nnot sure if this error occured during exporting to shapefile, but I've tried different sources and the error persists.

  • Don't have enough reputation to add "layermapping" tag, thought it might be appropriate to the quesiton. – kuch nahi Apr 23 '14 at 17:44

The reason you get this error is because the polygons in the source file you indicated are not "closed". A valid polygon or multipolygon must have identical start and endpoints. The polygon in your example above looks like this:

MULTIPOLYGON (((77.248008 28.711174, ... ,77.245719 28.701041)))

Where it should loo like this

MULTIPOLYGON (((77.248008 28.711174, ... ,77.245719 28.701041, 77.248008 28.711174)))

Such that the first point is identical to the last one, i.e. the polygon is closed. If this is not the case, the geometry is not valid and geodjango does not accept it as input.

So you have to repair the geometry, and I am not sure if QGis can repair geometries. You could do this by hand, adding the endpoints to each geometry in your file (if its not too big). Or if you have postgis you could try to use the ST_MakeValid function.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.