Re: Shapelib Digest, Vol 73, Issue 1

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Re: Shapelib Digest, Vol 73, Issue 1

Juan Antonio Pastor

You must write data in the DBF.

Use DBFAddField and: DBFWriteStringAttribute, DBFWriteIntegerAttribute... to write values into fields.

For example you can write the x and y values (double values):

DBFAddField(hDBF, "X", FTDouble, 15, 15);
DBFAddField(hDBF, "Y", FTDouble, 15, 15);

for(int i=0;i<3;i++) {
  DBFWriteDoubleAttribute(hDBF, i, 0,X[i]);
  DBFWriteDoubleAttribute(hDBF, i, 1,Y[i]);

Good luck!

2011/5/31 <[hidden email]>
Send Shapelib mailing list submissions to
       [hidden email]

To subscribe or unsubscribe via the World Wide Web, visit
or, via email, send a message with subject or body 'help' to
       [hidden email]

You can reach the person managing the list at
       [hidden email]

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Shapelib digest..."

Today's Topics:

  1. Point shp file is created with empty dbf. (Rakib Solaimani)


Message: 1
Date: Tue, 31 May 2011 01:03:30 +0600
From: Rakib Solaimani <[hidden email]>
Subject: [Shapelib] Point shp file is created with empty dbf.
To: [hidden email]
Message-ID: <[hidden email]>
Content-Type: text/plain; charset="iso-8859-1"


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

 #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",

    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...


Shapelib mailing list
[hidden email]

End of Shapelib Digest, Vol 73, Issue 1

Shapelib mailing list
[hidden email]