﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
9244	LayerMapping.save fails for large polygon record	Tyler Erickson	jbronn	"When trying to load a shapefile using LayerMapping, the save method fails when it encounters a large record.  I will attach a shapefile that causes this problem to the page.

Here is the error that is returned...
{{{
taericks@optiplexe:~/django_projects/django_nasa_fire_dss$ python manage.py shell
Python 2.5.2 (r252:60911, Jul 31 2008, 17:28:52) 
Type ""copyright"", ""credits"" or ""license"" for more information.

IPython 0.8.1 -- An enhanced Interactive Python.
?       -> Introduction to IPython's features.
%magic  -> Information about IPython's 'magic' % functions.
help    -> Python's own help system.
object? -> Details about 'object'. ?object also works, ?? prints more.

In [1]: import load_data
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc
Aborted
taericks@optiplexe:~/django_projects/django_nasa_fire_dss$ 
}}}


Here is the script for loading the data (load_data.py)
{{{ 
import os
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
from psycopg2 import IntegrityError
from django.contrib.gis.utils import mapping, LayerMapping, add_postgis_srs
from fccs.models import FccsPoints,FccsPolygons

fccs_polys = 'data/fccs/fccs_poly_orig_wgs84_problem.shp'

mapping2 = {'gridcode' : 'GRIDCODE',
            'area_km2' : 'AREA_KM2',
            'geometry' : 'POLYGON',
            }

layer2 = LayerMapping(FccsPolygons,fccs_polys,mapping2, transaction_mode='autocommit')
layer2.save(verbose=True, progress=True)
 }}}

Here is the model file (fccs/models.py)
{{{ 
from django.contrib.gis.db import models

class FccsPolygons(models.Model):
    
    gridcode = models.IntegerField(help_text=""FCCS code of the plygon region"",)
    area_km2 = models.IntegerField(help_text=""Area of the polygon in SQ kilometers"",)

    # GeoDjango specific Polygon Field and GeoManager
    geometry = models.MultiPolygonField(srid=4326)
    # GeoManager, a subclass that adds a rich set of geospatial queryset methods
    objects = models.GeoManager()

    class Meta:
        verbose_name_plural = ""FCCS Polygons""
}}}

"		closed	GIS	1.0		invalid	LayerMapping gdal		Unreviewed	0	0	0	0	0	0
