For gdal,c++ development environment testing.
#include <iostream>#include"gdal_priv.h"#include"Ogrsf_frmts.h"#include"Ogr_geometry.h"#pragmaComment (lib, "C:\\warmerda\\bld\\lib\\gdal_i.lib")using namespacestd;voidCreateshapefile () {Const Char*pszdrivername ="ESRI shapefiles"; Ogrsfdriver*Podriver; Ogrregisterall (); Podriver= Ogrsfdriverregistrar::getregistrar ()Getdriverbyname (pszdrivername); if(Podriver = =NULL) {printf ("%s driver not available.\n", Pszdrivername); Exit (1 ); } Ogrdatasource*PoDS; PoDS= Podriver->createdatasource ("point_out.shp", NULL); if(PoDS = =NULL) {printf ("Creation of output file failed.\n" ); Exit (1 ); } Ogrlayer*Polayer; Polayer= Pods->createlayer ("Point_out", NULL, wkbpoint, NULL); if(Polayer = =NULL) {printf ("Layer Creation failed.\n" ); Exit (1 ); } ogrfielddefn Ofield ("Name", oftstring); Ofield.setwidth ( +); if(Polayer->createfield (&ofield)! =Ogrerr_none) {printf ("Creating Name Field failed.\n" ); Exit (1 ); } Doublex, y; Charszname[ -]; while( !feof (stdin)&& fscanf (stdin,"%lf,%lf,%32s", &x, &y, szName) = =3) {ogrfeature*pofeature; Pofeature=NewOgrfeature (polayer->Getlayerdefn ()); Pofeature->setfield ("Name", SzName); Ogrpoint pt; Pt.setx (x); Pt.sety (y); Pofeature->setgeometry (&PT); if(Polayer->createfeature (pofeature)! =Ogrerr_none) {printf ("Failed to create feature in shapefile.\n" ); Exit (1 ); } ogrfeature::D estroyfeature (pofeature); } Ogrdatasource::D estroydatasource (PoDS);}intMain () {//Createshapefile (); //cout<< "Create success" <<endl; Const Char*pszdrivername="ESRI shapefiles"; Ogrsfdriver*Podriver; Ogrregisterall (); Podriver=ogrsfdriverregistrar::getregistrar ()Getdriverbyname (pszdrivername); if(podriver==NULL) {cout<<"Registration Failed"<<Endl; } Ogrdatasource*PoDS; PoDS=podriver->createdatasource ("point_out.shp", NULL); if(pods==NULL) {cout<<"Create drive failed! "<<Endl; } Ogrlayer*Polayer; Polayer=pods->createlayer ("Point_out", Null,wkbpoint,null); if(polayer==NULL) {cout<<"failed to create layer"<<Endl; } ogrfielddefn Ofield ("Name", oftstring); Ofield.setwidth ( A); if(Polayer->createfield (&ofield)! =Ogrerr_none) {cout<<"failed to add field! "<<Endl; } //The following loop reads the point information in the "X,y,name" format from stdin. Doublex=0, y= -; Charszname[ -]; for(intA=0; a!=Ten;++a) {x+=A; Y+=A; Ogrfeature*pofeature; Pofeature=NewOgrfeature (polayer->Getlayerdefn ()); Pofeature->setfield ("Name", SzName); Ogrpoint pt; Pt.setx (x); Pt.sety (y); Pofeature->setgeometry (&PT); if(Polayer->createfeature (pofeature)! =Ogrerr_none) {cout<<"failed to create feature"<<Endl; } //ogrfeature::D estroyfeature (*pofeature);//Create a feature. Ogrlayer::createfeature () only re-replicates a feature, so the feature object needs to be cleared after the operation is completed } //finally releases the Datasoure resource and refreshes all the write operationsOgrdatasource::D estroydatasource (PoDS); cout<<"The file was created successfully! "<<Endl; return 0;}
GDAl C + + Create shp