0

I have two shapefiles that I am merging/combining. However, this produces more than 4,000 duplicate records. I need to have only unique records. Is this possible with OGRINFO or OGR2OGR? I've tried Select DISTINCT but it only lets me do select statement on one column/field. I can get a list of unique records but I need to create new shapefil.

1

There should be no problem in using many attributes in DISTINCT query at least with the SQLite SQL dialect. Test with ogrinfo:

ogrinfo -dialect sqlite -sql "select distinct geometry, attribute_1, attribute_2 from my_shapefile" my_shapefile.shp
  • This works for ogrinfo, but not ogr2ogr as the questioner requires. – gregmacfarlane Jun 14 '18 at 16:11
  • Works for me with ogr2ogr and gives the same result - as many features written into output file than what gets selected with ogrinfo. – user30184 Jun 14 '18 at 16:50
0

I'm trying to do the same thing, I see in the OGR SQL documentation,

The result of a SELECT with a DISTINCT keyword is a layer with one column (named the same as the field operated on), and one feature per distinct value. Geometries are discarded.

Why they made this choice boggles my mind. But I can confirm that

ogr2ogr -dialect -sqlite -sql "select distinct LINK_ID from layer" out.shp layer.shp

Returns only the out.dbf file, which contains the unique LINK_ID values.

  • SQLite dialect does not select geometry field automatically. Have you tried select distinct geometry, LINK_ID from layer? BTW. it does not help to read the OGR SQL manual if you use the SQLite SQL, read gdal.org/ogr_sql_sqlite.html instead. I have not tried conversion with ogr2ogr myself so you can be right, please tell if it works or not with explicitly selected geometry. – user30184 Jun 14 '18 at 16:25
  • @gregmacfarlanane, have you made a test with select geometry,link_id or do you want me to build a test set? – user30184 Jun 16 '18 at 11:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.