[Shapelib] Adding new shape to shapefile

Brian Peschel brianp at occinc.com
Thu Jun 5 10:56:01 PDT 2008


Why are you taking the return from DBFCreate and SHPCreate and assigning 
them to an IntPtr? Looking at the header:

DBFHandle SHPAPI_CALL DBFCreate( const char * pszDBFFile );
SHPHandle SHPAPI_CALL SHPCreate( const char * pszShapeFile, int 
nShapeType );

Or does this have something to do with C# (I seem to recall something 
about C# or .NET or something). I do an open like this:
DBFHandle dbfHandle;

if ((dbfHandle = DBFCreate(dbfName.c_str())) == NULL)
return false;

SHPHandle shpOut;
if ((shpOut = SHPCreate(outfile.c_str(), SHPT_ARC)) == NULL)
return false;

For what it is worth.....

Brian
> > My code : 
> >
> > //création du dbf
> > IntPtr ptrDBFCreate = shpFile.DBFCreate(@"\SD-MMCard\TestParcelle\test");
> >
> > //création du shapefile
> > IntPtr ptrSHPCreate = shpFile.SHPCreate(@"\SD-MMCard\TestParcelle\test",
> > ShapeFile.ShapeFile.ShapeType.Point);
> >
> > //nouvelle colonne dans le dbf
> > shpFile.DBFAddField(ptrDBFCreate, @"\SD-MMCard\TestParcelle\test",
> > ShapeFile.ShapeFile.DBFFieldType.FTString, 255, 0);
> >
> > //écriture de la valeur liée au futur shape
> > shpFile.DBFWriteStringAttribute(ptrDBFCreate,
> > shpFile.DBFGetRecordCount(ptrDBFCreate), 0, "to");
> >
> > //création du point
> > double[] x = new double[1];
> > double[] y = new double[1];
> > double[] z = new double[1];
> > x[0] = 803606;
> > y[0] = 803606;
> > z[0] = 0;
> >
> > IntPtr psObject =
> > shpFile.SHPCreateSimpleObject(ShapeFile.ShapeFile.ShapeType.Point, 1, x, y,
> > z);
> >
> > //écriture du point dans le shape
> > shpFile.SHPWriteObject(ptrSHPCreate, -1, psObject);
> >
> > //fermeture du dbf et du shapefile
> > shpFile.SHPClose(ptrSHPCreate);
> > shpFile.DBFClose(ptrDBFCreate);
> >   
>   



More information about the Shapelib mailing list