I should say GeoDjango supports a number of GIS implementations (not PostGIS, which is a specific implementation) :-) ...<div><br><br><div class="gmail_quote">On Mon, Jun 4, 2012 at 11:08 AM, Eric Floehr <span dir="ltr">&lt;<a href="mailto:eric@intellovations.com" target="_blank">eric@intellovations.com</a>&gt;</span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><br></div>Running as raw SQL will save memory (and possibly time) as you aren&#39;t loading each row from database to Python and back.  The drawback would be you would be tied to whatever GIS implementation you are using (PostGIS supports a number).  Here would be the equivalent PostGIS SQL to do this:<div>


<br></div><div>update &lt;Places DB table&gt; set point=ST_SetSRID(ST_Point(x/1000.0, y/1000.0), &lt;SRID&gt;) where x is not NULL and y is not NULL;</div><div><br></div><div>The default &lt;SRID&gt; in PostGIS is 4326, so that&#39;s likely what your point column will expect.</div>


<div><br></div><div>A couple of notes:</div><div><br></div><div>ST_Point, and most other PostGIS commands expect longitude,latitude form ... so in this case, x would be longitude and y latitude.</div><div><br></div><div>

Also, in your Python implementation, &quot;<span>if record.x and record.y&quot; will fail when x or y is 0, which are valid, not just None.  This has tripped me up in the past :-).  So better would be &quot;if record.x is not None and record.y is not None&quot;.</span></div>


<div><span><br></span></div><div><span>Cheers,</span></div><div><span>Eric</span></div><div class="HOEnZb"><div class="h5"><div><span><br></span></div><div><br></div><div><br><br><div class="gmail_quote">On Mon, Jun 4, 2012 at 10:39 AM, Kurtis Mullins <span dir="ltr">&lt;<a href="mailto:kurtis.mullins@gmail.com" target="_blank">kurtis.mullins@gmail.com</a>&gt;</span> wrote:<br>


<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hey,<div><br></div><div>It looks like you&#39;ve got the fat trimmed off this one about as much as you can. I&#39;d say filter out your results but even then you&#39;re still using every result. I&#39;d recommend modifying this to run as raw SQL and I&#39;m sure your memory usage will go down significantly. Pulling in this many records as Python Objects and conversely creating new Python objects on top of that (your Point objects) is most likely the cause of this memory usage.<div>


<div><br>
<br><div class="gmail_quote">On Mon, Jun 4, 2012 at 10:28 AM,  <span dir="ltr">&lt;<a href="mailto:jep200404@columbus.rr.com" target="_blank">jep200404@columbus.rr.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">



How can I reduce the memory usage in a Django management command?<br>
I have some Django code like follows in a management program:<br>
<br>
class Command(BaseCommand):<br>
...<br>
    def handle(self, *args, **options):<br>
        for record in Places.objects.all():<br>
            if record.x and record.y:<br>
                record.point = (<br>
                    Point(float(record.x)/1000.,<br>
                    float(record.y)/1000.))<br>
            else:<br>
                record.point = None<br>
            record.save()<br>
        django.db.connection.close()<br>
<br>
In the settings.py file I have:<br>
<br>
DEBUG = False<br>
<br>
Places has millions of rows.<br>
top reveals that the program is using 18.6 Gigabytes of memory.<br>
How can I reduce that memory usage?<br>
Am I neglecting to close or release something?<br>
<br>
The only dox I&#39;m finding about memory use related to query sets<br>
advise to use iterators instead of converting to a list.<br>
I&#39;m already following that advice, but I&#39;m not finding<br>
further guidance about memory use about record modification.<br>
<br>
Since DEBUG is False, I&#39;ve already heeding the following.<br>
<br>
   <a href="https://docs.djangoproject.com/en/dev/faq/models/#why-is-django-leaking-memory" target="_blank">https://docs.djangoproject.com/en/dev/faq/models/#why-is-django-leaking-memory</a><br>
<br>
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -<br>
<br>
I have found that the following might be nice,<br>
but doubt it addresses the memory issue.<br>
<br>
            record.save(update_fields=[&#39;point&#39;])<br>
<br>
_______________________________________________<br>
CentralOH mailing list<br>
<a href="mailto:CentralOH@python.org" target="_blank">CentralOH@python.org</a><br>
<a href="http://mail.python.org/mailman/listinfo/centraloh" target="_blank">http://mail.python.org/mailman/listinfo/centraloh</a><br>
</blockquote></div><br></div></div></div>
<br>_______________________________________________<br>
CentralOH mailing list<br>
<a href="mailto:CentralOH@python.org" target="_blank">CentralOH@python.org</a><br>
<a href="http://mail.python.org/mailman/listinfo/centraloh" target="_blank">http://mail.python.org/mailman/listinfo/centraloh</a><br>
<br></blockquote></div><br></div>
</div></div></blockquote></div><br></div>