[Shapelib] Creating Point shapefiles
Ajay
ajayprasad at cc.usu.edu
Tue Sep 6 20:08:41 PDT 2005
Greetings all,
I was trying to create a point shapefile from a text file with X and Y
values. I don't know how to go about with that. I tried to make it, but it
is not working. If anyone can help me out with this, that will be really
helpful.
Thanks a lot
Below is the code which I tried
int texttoshape(char* txtfile,char* shpfile)
{
FILE *fp;
char header[9];
fp=fopen(txtfile,"r");
char lbl[2];
float x,y,z,ts;
int sp,i=0;
shapefile *shfile;
shape *shp;
api_point pnt;
shfile=new shapefile();
shfile->create(shpfile,1);
fscanf(fp,"%s %s %s %s %s %s",header,header,header,header,header,header);
while (!feof(fp))
{
fscanf(fp,"%s %f %f %f %f %i",lbl,&x,&y,&z,&ts,&sp);
pnt.setX(x);
pnt.setY(y);
shp=new shape();
shp->insertPoint(pnt,i);
shfile->insertShape(shp,i);
i++;
}
shfile->save(shpfile);
shfile->close(shpfile);
return 0;
}
ajay
More information about the Shapelib
mailing list