3

In the ArcObjects developer SDK, I found that the IExternalSerializerGdb2 interface of the JSONSerializerGdb class supports writing to GeoJSON.

ArcGIS Developer Help (ESRI.ArcGIS.Geodatabase)

IExternalSerializerGdb2.WriteRecordSetEx2 Method

Writes feature recordset for both JSON and GeoJSON format and returns number of records serialized.

I tried this:

var jsonWriter = new JSONWriterClass();
jsonWriter.WriteToString();

var jsonSerializer = new JSONSerializerGdbClass();
jsonSerializer.InitSerializer(jsonWriter, null);

var recordset = new RecordSetClass();
recordset.SetSourceTable((ITable)featureclass, null);

var sr = ((IGeoDataset)featureclass).SpatialReference;

int count;
((IExternalSerializerGdb2)jsonSerializer).WriteRecordSetEx2(null, recordset, null, sr, out count);

But it only seems to write the (ArcGIS) JSON format.

How do I generate GeoJSON?

  • Did you try using the JSONConverterGdb class instead of the JSONWriterClass? – Kirk Kuykendall Jul 20 '16 at 17:21
  • I did now, but jsonConverterGdb.WriteRecordSet(jsonWriter, null, null, null, recordset, null, true); gives me the same (ArcGIS) JSON – Berend Jul 21 '16 at 7:30
2

I know I'm a little late to the party, but for anyone else who may be looking for a way to do this out of the box with ArcObjects see the following:

var jsonWriter = new JSONWriterClass();
jsonWriter.WriteToString();

// Create a property set to specify format to be GeoJSON
IPropertySet props = new PropertySetClass();
props.SetProperty("Format", "GeoJSON");

var jsonSerializer = new JSONSerializerGdbClass();
jsonSerializer.InitSerializer(jsonWriter, props);

var recordset = new RecordSetClass();
recordset.SetSourceTable((ITable)featureclass, null);

var sr = ((IGeoDataset)featureclass).SpatialReference;

int count;
((IExternalSerializerGdb2)jsonSerializer).WriteRecordSetEx2(null, recordset, null, sr, out count);

var geoJson = System.Text.Encoding.UTF8.GetString(jsonWriter.GetStringBuffer());
  • Thanks! I have no idea what I needed this for, but I tried your code and it works. – Berend Dec 21 '17 at 8:00

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.