"No support for this geometry type" error when creating PolyLines in Shape File

5580
2
03-23-2011 07:38 AM
GaryBroyd
New Contributor
Hi everybody,

I'm in the process of moving our VB6 code which integrates with ArcMap to .Net and have run into a problem trying to add some PolyLines into a shape file.  We use very similar code for adding points into a shape file but can't work out why it's coming up with the error:

No support for this geometry type

We are creating a Shape File and populating it with PolyLine features from a series of coordinates (these are used to symbolise a link between two other map items "Points" that exist in a separate layer)

Here is the basic code (some variables etc are defined elsewhere but it the basic ArcObjects interaction is there).  It throws the exception on the last line of code:

//Create a Shape file workspace factory
ESRI.ArcGIS.DataSourcesFile.ShapefileWorkspaceFactory shapefileWorkspaceFactory = CreateObject( "esriDataSourcesFile.ShapefileWorkspaceFactory" ) as ESRI.ArcGIS.DataSourcesFile.ShapefileWorkspaceFactory;
ESRI.ArcGIS.Geodatabase.IFeatureWorkspace featureWorkspace = shapefileWorkspaceFactory.OpenFromFile( System.IO.Path.GetDirectoryName( linksDataFilePath ), 0 ) as IFeatureWorkspace;

IWorkspace workspace = featureWorkspace as IWorkspace;

ESRI.ArcGIS.Geodatabase.IFields fields = new ESRI.ArcGIS.Geodatabase.Fields();
ESRI.ArcGIS.Geodatabase.IFieldsEdit fieldsEdit = fields as ESRI.ArcGIS.Geodatabase.IFieldsEdit;
IField shapeField = new ESRI.ArcGIS.Geodatabase.Field();
IFieldEdit shapeFieldEdit = shapeField as IFieldEdit;

shapeFieldEdit.Name_2 = "Shape";
shapeFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry;

IGeometryDef geometryDef = CreateObject( "esriGeoDatabase.GeometryDef" ) as IGeometryDef;
IGeometryDefEdit geometryDefEdit = geometryDef as IGeometryDefEdit;

geometryDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPolyline;

ISpatialReference spatialReference = CreateObject( "esriDataSourcesFile.UnknownCoordinateSystem" ) as ISpatialReference;
geometryDefEdit.SpatialReference_2 = spatialReference;

shapeFieldEdit.GeometryDef_2 = geometryDef;

fieldsEdit.AddField( shapeField );

IFeatureClass featureClass = featureWorkspace.CreateFeatureClass( filenameOnly, fields, null, null, esriFeatureType.esriFTSimple, shapeFieldEdit.Name, "" );


CreateFields( headerLine, featureClass );
ITable table = featureClass as ITable;
ICursor cursor = table.Insert( false );
IRowBuffer rowBuffer = table.CreateRowBuffer();
IFeature lineFeature = rowBuffer as IFeature;
IPoint startPoint = CreateObject( "esriGeometry.Point" ) as IPoint;
IPoint endPoint = CreateObject( "esriGeometry.Point" ) as IPoint;
ILine line = CreateObject( "esriGeometry.Line" ) as ILine;
IGeometryCollection polyLine = CreateObject( "esriGeometry.PolyLine" ) as IGeometryCollection;
ISegmentCollection path = CreateObject( "esriGeometry.Path" ) as ISegmentCollection;

//Coordinate variables (of type double) defined elsewhere
startPoint.PutCoords( x1, y1 );
endPoint.PutCoords( x2, y2 );
line.PutCoords( startPoint, endPoint );

object missing1 = Type.Missing;
object missing2 = Type.Missing;
path.AddSegment( (ISegment)line, ref missing1, ref missing2 );
polyLine.AddGeometry( (IGeometry)path, ref missing1, ref missing2 );

//Set the field values in
rowBuffer.set_Value( 3, mapId );
rowBuffer.set_Value( 4, mapColour );
rowBuffer.set_Value( 5, mapDirection );
rowBuffer.set_Value( 6, x1 );
rowBuffer.set_Value( 7, y1 );
rowBuffer.set_Value( 8, x2 );
rowBuffer.set_Value( 9, y2 );

cursor.InsertRow( rowBuffer );

//***************************************
//THROW THE EXCEPTION HERE
lineFeature.Shape = (IGeometry)path;
//***************************************
0 Kudos
2 Replies
NeilClemmons
Regular Contributor III
lineFeature.Shape = (IGeometry)path;

You're attempting to add a Path geometry to a Polyline shapefile.  A Path and a Polyline are not the same thing.  Add the Polyline you're creating instead of the Path.
0 Kudos
GaryBroyd
New Contributor
lineFeature.Shape = (IGeometry)path;

You're attempting to add a Path geometry to a Polyline shapefile.  A Path and a Polyline are not the same thing.  Add the Polyline you're creating instead of the Path.


Hi there Neil,

That's great it worked - another typo as a result of converting the code (and being rather new to all this ArcGIS stuff!!)

So to summarise the fix was to change

lineFeature.Shape = (IGeometry)path;


to

lineFeature.Shape = (IGeometry)polyLine;
0 Kudos