[gdal-dev] OGR ExportToJson behavior & shapefile difference

Even Rouault even.rouault at mines-paris.org
Thu Apr 11 11:07:36 PDT 2013


Le jeudi 11 avril 2013 14:16:59, Rutger a écrit :
> Dear list,
> 
> I am trying to make a Python script which gives me the difference between
> two Shapefiles. With different i mean any change in attributes or geometry,
> but ignoring the FID. I have a working solution which i'll describe below.
> On the way i discovered some inconsistent behavior in the ExportToJson()
> function, perhaps a bug, im not sure.
> 
> My method exists of loading all features in a Python set() and then using
> new_set.difference(old_set) to get the difference.
> 
> I dump each feature with ExportToJson, convert it to a dict, pop-out the
> FID, and convert it back to json (because you cant add a dict in a set).
> So:
> 
> /tmpdct = json.loads(ft.ExportToJson())
> ftid = tmpdct.pop('id')
> old_set.add(json.dumps(tmpdct))/
> 
> This works well, but the strange thing is that the Json-code for the first
> feature (with FID=0) doesnt contain the 'id', all further features do. Is
> this behavior to be expected or should i file a ticket? I made a gist with
> some sample code replicating the issue:
> http://nbviewer.ipython.org/5362782 <http://nbviewer.ipython.org/5362782>

Fixed by r25899


More information about the gdal-dev mailing list