Hello,
I in the process of writing a utility which creates ArcGIS Features in a geodatabase based on information coming in via an XML.
This XML contains geometries in GML 2.0-format which I wish to convert into Shapes on a Feature.
I looked around within the ArcGIS Pro Core API and couldn't find built-in functionality to import shapes from GML so i started using GDAL to convert the geometries from GML 2.0 to ESRI Shapefiles, as the geometryengine does have a function to create geometries from ESRI Shapefiles.
I am currently using the following C#-code to create the ESRI Shapefile using GDAL:
using (var g = OSGeo.OGR.Geometry.CreateFromGML(gmlElement.ToString()))
using (var esriDriver = Ogr.GetDriverByName("ESRI Shapefile"))
using (var esriDataSource = esriDriver.CreateDataSource(tempFile, new string[] {}))
using (var esriLayer = esriDataSource.CreateLayer("baseLayer", spatialReference, g.GetGeometryType(), new string[] {}))
using (var esriLayerDefinition = esriLayer.GetLayerDefn())
using (var feature = new Feature(esriLayerDefinition))
{
feature.SetGeometry(g);
esriLayer.CreateField(new FieldDefn("id", FieldType.OFTInteger), 0);
feature.SetField("id", 123);
var i = esriLayer.CreateFeature(feature);
}
var bytes = File.ReadAllBytes(tempFile);
I am then using the following code to import into a ESRI Geometry from the ESRI Shapefile byte-array created using GDAL:
var geometry = GeometryEngine.Instance.ImportFromEsriShape(EsriShapeImportFlags.esriShapeImportNoSwap, bytes, CreateSpatialReference(3006));
the ArcGIS Pro SDK does not seem to like this however as it seems to be unable to find any geometries within the provided ESRI Shapefile:
ArcGIS.Core.Geometry.GeometryObjectException: 'GeometryObjectException: A null geometry does not correspond to any Esri geometry type.'
Do you have any hints for me on what I might be doing wrong? Or know of a better way to go from a shape in GML 2.0 format to an ESRI Geometry using the Core & CoreHost APIs?