1

I am working on a project to convert a mass of GIS data in Shapefile format to GeoJSON. I am able to complete the conversion using ogr2ogr but I would like to be able to test the resultant GeoJSON against the originating Shapefile. Is there an equivalent of diff that would tell me if the geometries encoded in the two files are different?

1

It should be possible to do the comparison with ogrinfo and ogr2ogr from the command line. At least it seemed to work for me with a minimal test data that consists of two polygons in OpenJUMP JML format and two polygons in GeoJSON format. One polygon was same in the both layers so the expected result is that polygons with ID=1 return an empty difference while polygons with ID=2 return a polygon as the area of difference.

First thing to do is to merge the JML file and GeoJSON file into one datasource with two layers by writing a GDAL VRT file http://www.gdal.org/drv_vrt.html

<OGRVRTDataSource>
    <OGRVRTLayer name="first">
        <SrcDataSource>first.jml</SrcDataSource>
    </OGRVRTLayer>
    <OGRVRTLayer name="second">
        <SrcDataSource>second.json</SrcDataSource>
    </OGRVRTLayer>
</OGRVRTDataSource>

Then just use some ogrinfo magic with the SQLite dialect

ogrinfo -ro -dialect sqlite -sql "select first.id, 
ST_AsText(ST_SymDifference(first.geometry,second.geometry)) 
as difference from first,second where first.id=second.id"  two_layers.vrt
INFO: Open of `two_layers.vrt'
      using driver `OGR_VRT' successful.

Layer name: SELECT
Geometry: None
Feature Count: 2
Layer SRS WKT:
(unknown)
id: Integer (0.0)
difference: String (0.0)
OGRFeature(SELECT):0
  id (Integer) = 1
  difference (String) = (null)

OGRFeature(SELECT):1
  id (Integer) = 2
  difference (String) = POLYGON((380 520, 469 446, 572 547, 471 414, 380 520))

The method has some limitations because GDAL considers the data type of the result field from ST_SymDifference as a string and therefore it comes visible only after pushing it through ST_AsText which make it hard to utilize the result in further processing.

3

Bring them into QGIS, and run a difference between them.

Vector> Geoprocessing Tools> Difference

  • Sorry - should have clarified that I wanted to do it from the command line. – Jeffery Candiloro Jan 4 '18 at 3:13

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.