[postgis-users] Trouble with returning MultiPolygon on psql query

Joseph Spenner joseph85750 at yahoo.com
Wed Sep 9 12:10:05 PDT 2015


Hello, I have a file (source.json) containing 25 GeoJSON polygons with weather alerts, which I imported into postgres using the following command:
$ ogr2ogr -f "PostgreSQL" PG:"dbname=weatherzones user=postgres" "source.json" -nln polys

Here's how it looks in Postgres:
polytest=# \d polys;
                                       Table "public.polys"
    Column    |          Type           |                        Modifiers                        
--------------+-------------------------+---------------------------------------------------------
 ogc_fid      | integer                 | not null default nextval('polys_ogc_fid_seq'::regclass)
 wkb_geometry | geometry(Geometry,4326) | 
 warnings     | character varying       | 
Indexes:
    "polys_pk" PRIMARY KEY, btree (ogc_fid)
    "polys_geom_idx" gist (wkb_geometry)

polytest=# 

I can see it stored all of them:
polytest=# select count(*) from polys;
 count 
-------
    25
(1 row)

polytest=# 
However, when I try to use a ST_Intersects(ST_PointFromText('POINT(), I can't seem to get lines with MultiPolygons to return rows.  The regular Polygons seem to work fine, though.
For example, I have the following MultiPolygon in my table from Nevada: 
http://microflush.org/json/24.json
Using a validator site, such as http://geojsonlint.com/ , I can copy/paste that JSON into the interface and it looks like 2 adjacent shapes making up the MultiPolygon.
If I grab points from the upper section of the polygon, using something like http://itouchmap.com/latlong.html, I get rows returned:polytest=# select warnings from polys where ST_Intersects(ST_PointFromText('POINT( -114.543457 39.336281 )', 4326), wkb_geometry) limit 2; 
polytest=# select warnings from polys where ST_Intersects(ST_PointFromText('POINT( -115.658569 39.500297 )', 4326), wkb_geometry) limit 2; 

But if I use a point from the lower Polygon section of that MultiPolygon, I get zero:

polytest=# select warnings from polys where ST_Intersects(ST_PointFromText('POINT( -115.977173 38.548667 )', 4326), wkb_geometry) limit 2; 



Another example from Florida (a little more difficult to see, but same issue):http://microflush.org/json/06.json
polytest=# select warnings from polys where ST_Intersects(ST_PointFromText('POINT( -81.988228 27.034561 )', 4326), wkb_geometry) limit 2;

warnings 
----------
(0 rows)

The above point (-81.988228 27.034561) would spacially exist in this MultiPolygon.

However, in this example, it will only return rows if I pick a point inside the little polygon which shows up focused to the south of the much larger polygon (when you use the geojsonlin.com site to plot the whole thing).  For example, this point:
polytest=# select warnings from polys where ST_Intersects(ST_PointFromText('POINT( -81.9878 27.034 )', 4326), wkb_geometry) limit 2;(1 row)
So, it would seem the select statements which should return Multipolygons are not returning for all Polygons contained in the MultiPolygon.
Is there something I'm doing incorrectly with my queries?
Any help would be great.
Thank you!
Joseph Spenner


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20150909/7634b083/attachment.html>


More information about the postgis-users mailing list