[Shapelib] Point shp file is created with empty dbf.

Rakib Solaimani rakib114 at gmail.com
Mon May 30 14:03:30 EST 2011


Hi,

I am new to shapelib. I want to create a simple shp file. I want to draw
point on specific latitude and longitude. I tried to execute the following
code which I found by google research.
I successfully create the shp file and viewed it by ShapeViewer but I found
my dbf file empty. I am wondering if data in dbf file is created while
creating new shp file or should it be created
manually? If so how can I link shp and dbf file. Basically I want to apply
some rule on dbf file. Can anyone help me please. Here I attach my sample
code.


 #include "stdafx.h"
 #include <iostream
 #include <cstdlib
 #include "shapefil.h"
 #include <string

 using namespace std;

 int _tmain(int argc, _TCHAR* argv[])
 {
     SHPHandle    hSHP;
     DBFHandle    hDBF;
     int        nShapeType, Vertices;
     string  shape_name, Col1;
     SHPObject    *psObject;

     double X[3], Y[3];

     X[0] = -130;
     Y[0]= 54;

     X[1] = -120;
     Y[1]= 30;

     X[2] = -100;
     Y[2]= 10;

     nShapeType = MultiPoint;
     Vertices = 3;


     hSHP = SHPCreate( "T:\\shapefolder\\test.shp",
nShapeType);

     hDBF = DBFCreate(T:\\shapefolder\\test.dbf);

     psObject = SHPCreateSimpleObject( nShapeType, Vertices, X, Y, NULL);
     SHPWriteObject( hSHP, -1, psObject );


     DBFClose( hDBF );
     SHPClose( hSHP );



     return 0;
 }
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.maptools.org/pipermail/shapelib/attachments/20110531/669da739/attachment.htm 


More information about the Shapelib mailing list