Dear Kevin & Jean<br><br>Thanks for the assistance.<br><br><div class="gmail_quote">2008/11/13 Kevin Neufeld <span dir="ltr"><<a href="mailto:kneufeld@refractions.net" target="_blank">kneufeld@refractions.net</a>></span><br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Unfortunately Jean, this won't work.  Your unique constraint on the geometry column is using the geometry equals operator (=), which compares the bounding boxes of the geometries, *not* the geometries themselves.<br>

<br>
I.E.<br>
postgis=# select 'LINESTRING(0 0, 1 1)'::geometry = 'LINESTRING(1 1, 0 0)'::geometry;<br>
 ?column?<br>
----------<br>
 t<br>
(1 row)<br>
<br>
<br>
postgis=# create temp table tmp (geom geometry);<br>
CREATE TABLE<br>
<br>
postgis=# alter table tmp add constraint unique_geom unique (geom);<br>
NOTICE:  ALTER TABLE / ADD UNIQUE will create implicit index "unique_geom" for table "tmp"<br>
ALTER TABLE<br>
<br>
postgis=# \d tmp<br>
     Table "pg_temp_2.tmp"<br>
 Column |   Type   | Modifiers<br>
--------+----------+-----------<br>
 geom   | geometry |<br>
Indexes:<br>
    "unique_geom" UNIQUE, btree (geom)<br>
<br>
postgis=# insert into tmp values ('LINESTRING(0 0, 1 1)'::geometry);<br>
INSERT 0 1<br>
<br>
postgis=# insert into tmp values ('LINESTRING(1 1, 0 0)'::geometry);<br>
ERROR:  duplicate key value violates unique constraint "unique_geom"<br>
<br>
<br>
Sindile ,<br>
An alternative way would be to load the data into PostGIS using the shape dump as usual.  If you have a distinct key (other than the gid which is added by shp2pgsql) on your features, you could create a new table, selecting from your postgis table using DISTINCT ON (my_distinct_feature_key).<br>


<a href="http://www.postgresql.org/docs/8.3/static/sql-select.html#SQL-DISTINCT" target="_blank">http://www.postgresql.org/docs/8.3/static/sql-select.html#SQL-DISTINCT</a><br>
<br>
Or, you could try:<br>
CREATE TABLE new_distinct_table AS<br>
SELECT att1, att2, geom::geometry<br>
FROM (<br>
  SELECT DISTINCT att1, att2, encode(geom, 'hex') as geom<br>
  FROM my_polygon_table ) AS foo<br>
<br>
Or, use Jean's method, but instead of the unique constraint on the geom, use a unique functional index using the geometry's hex string.<br>
<br>
postgis=# CREATE UNIQUE INDEX tmp_geom_unq ON tmp (encode(geom, 'hex'));<br>
CREATE INDEX<br>
<br>
postgis=# insert into tmp values ('LINESTRING(0 0, 1 1)'::geometry);<br>
INSERT 0 1<br>
<br>
postgis=# insert into tmp values ('LINESTRING(1 1, 0 0)'::geometry);<br>
INSERT 0 1<br>
<br>
postgis=# insert into tmp values ('LINESTRING(1 1, 0 0)'::geometry);<br>
ERROR:  duplicate key value violates unique constraint "tmp_geom_unq"<br>
<br>
postgis=# \d tmp<br>
     Table "pg_temp_2.tmp"<br>
 Column |   Type   | Modifiers<br>
--------+----------+-----------<br>
 geom   | geometry |<br>
Indexes:<br>
    "tmp_geom_unq" UNIQUE, btree (encode(geom::bytea, 'hex'::text))<br>
<br>
<br>
Remember though, that this is *not* a spatial geometry index, just a unique index on the hex string.<br>
<br>
Hope that helps,<br>
Cheers,<br><font color="#888888">
Kevin</font><div><div></div><div><br>
<br>
<br>
<br>
Jean David TECHER wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Example:<br>
<br>
dbname = routing_db<br>
<br>
table =wr<br>
<br>
1. Load only the table structure not the datas<br>
<br>
use -p option taken from shp2pgsql<br>
<br>
shp2pgsql -p wr.shp wr|psql routing_db<br>
<br>
2. Add a constraint on the_geom column<br>
<br>
psql routing_db<br>
<br>
ALTER TABLE wr ADD CONSTRAINT check_unique_the_geom unique(the_geom);<br>
<br>
3. Load your datas without 'BEGIN' and 'END'<br>
<br>
* Here use the -a option taken from shp2pgsql<br>
* use -I for index creation<br>
<br>
The idea is to use the INSERT command in order to rollbacking if the<br>
current feature is already in the table<br>
<br>
N.B: don't use -D option!<br>
<br>
shp2pgsql -aI wr.shp wr|grep -v ^BEGIN|grep -v ^END|psql routing_db<br>
<br>
<br>
Quoting Intengu Technologies <<a href="mailto:sindile.bidla@gmail.com" target="_blank">sindile.bidla@gmail.com</a>>:<br>
<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
I have a polygon shapefile that has duplicate features which I want to load<br>
into Postgis.  How can I ensure that each feature has only one record.<br>
<br>
-- <br>
Sindile Bidla<br>
<br>
</blockquote>
<br>
<br>
<br>
===================<br>
Jean David TECHER<br>
<a href="http://www.davidgis.fr" target="_blank">www.davidgis.fr</a><br>
06 60 46 85 05<br>
04 99 77 16 87<br>
===================<br>
<br>
_______________________________________________<br>
postgis-users mailing list<br>
<a href="mailto:postgis-users@postgis.refractions.net" target="_blank">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>
</blockquote>
_______________________________________________<br>
postgis-users mailing list<br>
<a href="mailto:postgis-users@postgis.refractions.net" target="_blank">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></div></blockquote></div><br><br clear="all"><br>-- <br>Sindile Bidla<br>