<table cellspacing="0" cellpadding="0" border="0" ><tr><td valign="top" style="font: inherit;"><br>If you simply want to reduce the number of features to load in each iteration, why do you need to use a spatial predicate, you can determine the count of records (~130,000) then use:<br> select ... limit .... offset ....;<br><br>Iterate through until done. Your features will not be spatially grouped, but will be in manageable chunks.<br><br>If some level of spatial grouping is required, you could just add in <br>"order by ST_XMin(the_geom)" to get output grouped by X axis (longitude)<br><br><br><br>That aside, I think your ST_contains() has the arguments in reverse, so you are asking for all features that contain your polygon, not the other way around, and zero sounds like the correct answer.<br><br>http://postgis.refractions.net/documentation/manual-svn/ST_Contains.html<br><br>Also, note that any of your features that cross the boundary of a box will
 never be returned, as they are not contained by any single box.<br><br><br>HTH,<br><br>  Brent Wood<br><br><br>--- On <b>Tue, 12/7/10, Eric Ladner <i><eric.ladner@gmail.com></i></b> wrote:<br><blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px;"><br>From: Eric Ladner <eric.ladner@gmail.com><br>Subject: [postgis-users] New to postgis...<br>To: postgis-users@postgis.refractions.net<br>Date: Tuesday, December 7, 2010, 4:41 PM<br><br><div class="plainMail">I just started using postgis in conjunction with OpenStreetMap and<br>I've been having a heck of a time gettnig a query to work.<br><br>I'm fairly well versed in SQL in general (Oracle DBA for 10+ years)<br>but I'm new to the spatial stuff.   I've got a bunch of plot line data<br>downloaded from the state's GIS system loaded into a postgis database<br>and I was trying to slice it up into manageable chunks to upload
 to<br>OSM.  In the table, I've got almost 130,000 distinct objects and I can<br>view them with queries (like below... I shortened up the MULTIPOLYGON<br>list for brevity..)<br><br><br>     select gid, ST_AsText(the_geom) from<br>gis_schema.jksn_cnty_buidings where gid = 99;<br><br>     gid |    st_astext<br>    -----+-----------------<br>      99 | MULTIPOLYGON(((-88.7426828988773<br>30.40751849384,-88.7427319811994<br>30.4075187592759,....-88.7426828988773 30.40751849384)))<br><br>The theory goes like this:<br><br>Find the extents of the data (xmax, ymax, xmin, ymin - this part works great),<br><br>    select min(ST_XMin(the_geom)) as "min_x", max(ST_XMax(the_geom))<br>as "max_x" from gis_schema.jksn_cnty_buidings ;<br>    select min(ST_YMin(the_geom)) as "min_y", max(ST_YMax(the_geom))<br>as "max_y" from gis_schema.jksn_cnty_buidings ;<br><br>Then
 partition that space into 16 or 25 sub-areas with a Perl script<br>that generates individual queries for the sub quadrants..  I planned<br>on moving them to additional numbered tables (to avoid dupes when<br>objects overlap the bounding polygon) then to handle each table as a<br>separate upload.  The examples below are just selects, though, all of<br>which return zero rows.<br><br>    select * from gis_schema.jksn_cnty_buidings where<br>_ST_Contains(the_geom,'POLYGON ((-88.981 32.0393, -88.8616 32.0393,<br>-88.8616 32.4663, -88.981 32.4663, -88.981 32.0393))');<br>    select * from gis_schema.jksn_cnty_buidings where<br>_ST_Contains(the_geom,'POLYGON ((-88.8616 32.0393, -88.7422 32.0393,<br>-88.7422 32.4663, -88.8616 32.4663, -88.8616 32.0393))');<br><br>There are thousands of polygons all across the area, and I've hand<br>verified a couple.  The above two queries should return about 2300<br>records each, but every
 time I run it, it returns zero.<br><br>I've tried several variants like (including _ST and regular ST functions)<br><br>    select *<br>    from gis_schema.jksn_cnty_buidings<br>    where<br>      the_geom && 'POLYGON ((-88.5034 32.0393, -88.384 32.0393,<br>-88.384 32.4663, -88.5034 32.4663, -88.5034 32.0393))' and<br>       _ST_Contains(the_geom,'POLYGON ((-88.5034 32.0393, -88.384<br>32.0393, -88.384 32.4663, -88.5034 32.4663, -88.5034 32.0393))');<br><br>And even<br><br>    select gid, objectid from gis_schema.jksn_cnty_buidings where<br>ST_Within(the_geom,ST_AsText(ST_MakeEnvelope(-90, 30, -86, 30,<br>4269)));<br><br>An ideas where I'm messing up here?<br>-- <br>Eric Ladner<br>_______________________________________________<br>postgis-users mailing list<br><a ymailto="mailto:postgis-users@postgis.refractions.net"
 href="/mc/compose?to=postgis-users@postgis.refractions.net">postgis-users@postgis.refractions.net</a><br><a href="http://postgis.refractions.net/mailman/listinfo/postgis-users" target="_blank">http://postgis.refractions.net/mailman/listinfo/postgis-users</a><br></div></blockquote></td></tr></table>