2

I'm using a modified version of pyris to get IRIS codes from France. I have a PostgreSQL/PostGIS database based on a shapefile.

My problem is, when I query the result for a coordinate, I get more than one result. That should not. An IRIS code should be unique for one result.

For example:

SELECT
iris ,nom_com ,depcom ,nom_iris ,dcomiris ,typ_iris 
FROM geoiris 
WHERE geom && st_makepoint(4.808744, 45.980649);



iris |     nom_com     | depcom |    nom_iris     | dcomiris  | typ_iris 
------+-----------------+--------+-----------------+-----------+----------
 0000 | ARS-SUR-FORMANS | 01021  | ARS-SUR-FORMANS | 010210000 | Z
 0000 | MISERIEUX       | 01250  | MISERIEUX       | 012500000 | Z
 0000 | SAINTE-EUPHEMIE | 01353  | SAINTE-EUPHEMIE | 013530000 | Z
(3 rows)

The second result is right, but the two others not. The others are areas next to the right one.

Is there something wrong with my query?

I'm using PostgreSQL 9.3 and shp2pgsql for the shapefile.

closed as off-topic by John Powell, whyzar, Mapperz Mar 29 '17 at 15:35

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This problem cannot or can no longer be reproduced. Changes to the system or to the asker's circumstances may have rendered the question obsolete, or the question does not include a procedure to enable potential answerers to reproduce the same symptoms. Such questions are off-topic as they are unlikely to help future readers, but editing them to include more details can lead to re-opening." – John Powell, whyzar, Mapperz
If this question can be reworded to fit the rules in the help center, please edit the question.

  • Projection of your IRIS geometries? – alphabetasoup Mar 28 '17 at 23:33
  • 1
    The "&&" operator is an envelope query. If you plot the point, you'll see it fits in all three shapes' envelopes. – Vince Mar 29 '17 at 0:28
  • Use ST_Intersects instead of && for accurate result. – user30184 Mar 29 '17 at 4:11
  • Thanks all of u, @user30184 answer helped me, now it works: "SELECT iris,nom_com,depcom,nom_iris,dcomiris,typ_iris FROM geoiris WHERE ST_Intersects(geom,ST_SetSRID(st_makepoint(%f, %f), 4326))" – kampfkeks18 Mar 29 '17 at 7:13
  • FYI using && is not wrong but it has a bit different purpose. && selects candidate features fast by utilizing spatial index. For speed and accurate results use && AND ST_Intersects. – user30184 Mar 29 '17 at 19:52

Browse other questions tagged or ask your own question.