[Shapelib] Point shp file is created with empty dbf.
Vassilis Perantzakis
vaspervnp at yahoo.gr
Thu Jun 2 03:00:31 EST 2011
When you insert an object in a shape file, a new entry is made in the dbf
file. However the entry is empty. Shapefiles and dbf files should always
have the same number of records. The connections between shape and dbf is
one to one record.
Now, for the specific api, you should check these addresses:
<http://shapelib.maptools.org/shp_api.html>
http://shapelib.maptools.org/shp_api.html
<http://shapelib.maptools.org/dbf_api.html>
http://shapelib.maptools.org/dbf_api.html
If you need to add specific data to a shape, then, before creating the first
record you should use the DBFAddField function to create fields in the dbf
file that hold your data.
e.g.
int myDataStringPos,myDataIntPos;
hDBF = DBFCreate("T:\\shapefolder\\test.dbf");
myDataStringPos =DBFAddField(hDBF,"myDataString",FTString,20,0);
myDataIntPos =DBFAddField(hDBF,"myDataInt",FTInteger,4,0);
The, right after using SHPWriteObject you should use its result (position of
new record ) to enter the data in the dbf file.
e.g.
int aRec;
aRec= SHPWriteObject( hSHP, -1, psObject );
DBFWriteStringAttribute(hDBF,aRec, myDataStringPos,"someDataString");
DBFWriteIntegerAttribute(hDBF,aRec, myDataIntPos,25000);
Hope this helps,
Vassilis Perantzakis
From: shapelib-bounces at lists.maptools.org
[mailto:shapelib-bounces at lists.maptools.org] On Behalf Of Rakib Solaimani
Sent: Monday, May 30, 2011 10:04 PM
To: shapelib at lists.maptools.org
Subject: [Shapelib] Point shp file is created with empty dbf.
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/20110602/4ed79d4c/attachment.htm
More information about the Shapelib
mailing list