<br>Hi Tom<br><br>I'm in home. <br><br>I already compiled your version of the code, but there is not good results. <br>A shapefile is generated, but I can't read it with ArcCatalog.<br><br>Ah, do you have an IDE to write the code, I know this because I saw your header  #include "stdafx.h".<br>
<br>Do you have Visual C++?<br><br>Or wich IDE?<br><br>I have Dev-C`++<br><br>Thanks. <br><br><br><br><div><span class="gmail_quote">2008/2/20, <a href="mailto:shapelib-request@lists.maptools.org">shapelib-request@lists.maptools.org</a> <<a href="mailto:shapelib-request@lists.maptools.org">shapelib-request@lists.maptools.org</a>>:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Send Shapelib mailing list submissions to<br>        <a href="mailto:shapelib@lists.maptools.org">shapelib@lists.maptools.org</a><br> <br> To subscribe or unsubscribe via the World Wide Web, visit<br>        <a href="http://lists.maptools.org/mailman/listinfo/shapelib">http://lists.maptools.org/mailman/listinfo/shapelib</a><br>
 or, via email, send a message with subject or body 'help' to<br>        <a href="mailto:shapelib-request@lists.maptools.org">shapelib-request@lists.maptools.org</a><br> <br> You can reach the person managing the list at<br>
        <a href="mailto:shapelib-owner@lists.maptools.org">shapelib-owner@lists.maptools.org</a><br> <br> When replying, please edit your Subject line so it is more specific<br> than "Re: Contents of Shapelib digest..."<br>
 <br> <br> Today's Topics:<br> <br>   1. Re: Re: Adding a polygon to a shapefile (Tom Kazimiers)<br> <br> <br> ----------------------------------------------------------------------<br> <br> Message: 1<br> Date: Wed, 20 Feb 2008 11:03:23 +0100<br>
 From: Tom Kazimiers <<a href="mailto:2voodoo@gmx.de">2voodoo@gmx.de</a>><br> Subject: Re: [Shapelib] Re: Adding a polygon to a shapefile<br> To: Shapelib Development <<a href="mailto:shapelib@lists.maptools.org">shapelib@lists.maptools.org</a>><br>
 Message-ID: <<a href="mailto:47BBFAEA.8060004@gmx.de">47BBFAEA.8060004@gmx.de</a>><br> Content-Type: text/plain; charset=ISO-8859-1; format=flowed<br> <br> Joaquin,<br> <br> if I make the following to changes to your code it works for me:<br>
 1. include the C++ version of string (insteat of "string.h" include<br> <string>)<br> Without this getline could not be found for me.<br> 2. Vertices is not initialized - like said before, make sure everything<br>
 is set up correctly - If you put "Vertices = 7;" in everything is ok.<br> <br> In particular my version of you code is:<br> <br> [CODE]<br> #include "stdafx.h"<br> #include <iostream><br> #include <cstdlib><br>
 #include "shapefil.h"<br> #include <string><br> <br> using namespace std;<br> <br> int _tmain(int argc, _TCHAR* argv[])<br> {<br>    SHPHandle    hSHP;<br>    DBFHandle    hDBF;<br>    int        nShapeType, Vertices;<br>
    string  shape_name, Col1;<br>    SHPObject    *psObject;<br> <br>    double X[7], Y[7], X1, Y1;<br> <br>    X[0] = 220764;<br>    Y[0]= 2343777;<br>    X[1] = 220610;<br>    Y[1]= 2343627;<br>    X[2] = 220818;<br>    Y[2]= 2343477;<br>
    X[3] = 221109;<br>    Y[3]= 2343777;<br>    X[4] = 230504;<br>    Y[4]= 2343627;<br>    X[5] = 221102;<br>    Y[5]= 2343477;<br>    X[6] = X[0];<br>    Y[6] = Y[0];<br> <br>    X1 = 220764;<br>    Y1 = 2343777;<br> <br>
     cout << "Name of the new Shapefile" << endl;<br>    getline(cin,shape_name);<br> <br>    cout << "The shapefile is: " << shape_name << endl;<br> <br>    nShapeType = 5;<br>
    Vertices = 7;<br> <br> <br>    hSHP = SHPCreate( shape_name.c_str(),nShapeType);<br> <br>    hDBF = DBFCreate( shape_name.c_str());<br> <br>    psObject = SHPCreateSimpleObject( nShapeType, Vertices, X, Y, NULL);<br>    SHPWriteObject( hSHP, -1, psObject );<br>
 <br> <br>    DBFClose( hDBF );<br>    SHPClose( hSHP );<br> <br> <br> <br>    return 0;<br> }<br> [/CODE]<br> <br> <br> Cheers,<br> Tom<br> <br> Joaquin Perez Valera schrieb:<br> > Hi<br> ><br> > I've been trying with CreateSimpleObject but i have not good results.<br>
 ><br> > I wrote the simple code:<br> ><br> > [CODE]<br> > #include <iostream><br> > #include <cstdlib><br> > #include "shapefil.h"<br> > #include "string.h"<br> ><br>
 ><br> > using namespace std;<br> > int main()<br> ><br> > {<br> >     SHPHandle    hSHP;<br> >     DBFHandle    hDBF;<br> >     int        nShapeType, Vertices;<br> >     string  shape_name, Col1;<br>
 >     SHPObject    *psObject;<br> ><br> >     double X[7], Y[7], X1, Y1;<br> ><br> >     X[0] = 220764;<br> >     Y[0]= 2343777;<br> >     X[1] = 220610;<br> >     Y[1]= 2343627;<br> >     X[2] = 220818;<br>
 >     Y[2]= 2343477;<br> >     X[3] = 221109;<br> >     Y[3]= 2343777;<br> >     X[4] = 230504;<br> >     Y[4]= 2343627;<br> >     X[5] = 221102;<br> >     Y[5]= 2343477;<br> >     X[6] = X[0];<br>
 >     Y[6] = Y[0];<br> ><br> >     X1 = 220764;<br> >     Y1 = 2343777;<br> ><br> >      cout << "Name of the new Shapefile" << endl;<br> >     getline(cin,shape_name);<br> ><br>
 >     cout << "The shapefile is: " << shape_name << endl;<br> ><br> >     nShapeType = 5;<br> ><br> ><br> ><br> >     hSHP = SHPCreate( shape_name.c_str(),nShapeType);<br>
 ><br> >     hDBF = DBFCreate( shape_name.c_str());<br> ><br> >     psObject = SHPCreateSimpleObject( nShapeType, Vertices, X, Y, NULL);<br> >     SHPWriteObject( hSHP, -1, psObject );<br> ><br> ><br>
 >     DBFClose( hDBF );<br> >     SHPClose( hSHP );<br> ><br> ><br> ><br> >     return 0;<br> > }<br> > [/CODE]<br> ><br> > And when I runs it I have the same message error and the shapefile is<br>
 > corrupt when I want to open it with ArcCatalog.<br> ><br> > Well<br> ><br> > See you and thanks.<br> ><br> ><br> ><br> > 2008/2/18, <a href="mailto:shapelib-request@lists.maptools.org">shapelib-request@lists.maptools.org</a><br>
 > <mailto:<a href="mailto:shapelib-request@lists.maptools.org">shapelib-request@lists.maptools.org</a>><br> > <<a href="mailto:shapelib-request@lists.maptools.org">shapelib-request@lists.maptools.org</a><br>
 > <mailto:<a href="mailto:shapelib-request@lists.maptools.org">shapelib-request@lists.maptools.org</a>>>:<br> ><br> >     Send Shapelib mailing list submissions to<br> >             <a href="mailto:shapelib@lists.maptools.org">shapelib@lists.maptools.org</a><br>
 >     <mailto:<a href="mailto:shapelib@lists.maptools.org">shapelib@lists.maptools.org</a>><br> ><br> >     To subscribe or unsubscribe via the World Wide Web, visit<br> >             <a href="http://lists.maptools.org/mailman/listinfo/shapelib">http://lists.maptools.org/mailman/listinfo/shapelib</a><br>
 >     or, via email, send a message with subject or body 'help' to<br> >             <a href="mailto:shapelib-request@lists.maptools.org">shapelib-request@lists.maptools.org</a><br> >     <mailto:<a href="mailto:shapelib-request@lists.maptools.org">shapelib-request@lists.maptools.org</a>><br>
 ><br> >     You can reach the person managing the list at<br> >             <a href="mailto:shapelib-owner@lists.maptools.org">shapelib-owner@lists.maptools.org</a><br> >     <mailto:<a href="mailto:shapelib-owner@lists.maptools.org">shapelib-owner@lists.maptools.org</a>><br>
 ><br> >     When replying, please edit your Subject line so it is more specific<br> >     than "Re: Contents of Shapelib digest..."<br> ><br> ><br> >     Today's Topics:<br> ><br> >        1. Adding a polygon to a shapefile (Joaquin Perez Valera)<br>
 >        2. Re: Adding a polygon to a shapefile (Tom Kazimiers)<br> >        3. Re: Adding a polygon to a shapefile (Tom Kazimiers)<br> ><br> ><br> >     ----------------------------------------------------------------------<br>
 ><br> >     Message: 1<br> >     Date: Sun, 17 Feb 2008 16:30:21 -0600<br> >     From: "Joaquin Perez Valera" <<a href="mailto:joaquinperezvalera@gmail.com">joaquinperezvalera@gmail.com</a><br> >     <mailto:<a href="mailto:joaquinperezvalera@gmail.com">joaquinperezvalera@gmail.com</a>>><br>
 >     Subject: [Shapelib] Adding a polygon to a shapefile<br> >     To: <a href="mailto:shapelib@lists.maptools.org">shapelib@lists.maptools.org</a> <mailto:<a href="mailto:shapelib@lists.maptools.org">shapelib@lists.maptools.org</a>><br>
 >     Message-ID:<br> >             <<a href="mailto:79a4e0710802171430y7dbad9c0p34780e668e3546ff@mail.gmail.com">79a4e0710802171430y7dbad9c0p34780e668e3546ff@mail.gmail.com</a><br> >     <mailto:<a href="mailto:79a4e0710802171430y7dbad9c0p34780e668e3546ff@mail.gmail.com">79a4e0710802171430y7dbad9c0p34780e668e3546ff@mail.gmail.com</a>>><br>
 >     Content-Type: text/plain; charset="iso-8859-1"<br> ><br> >     Hi<br> ><br> >     I can create shapefiles and they are valid when I work with<br> >     ArcCatalog. But<br> >     the shapefiles are empty.<br>
 ><br> >     Now I'm trying to add objects to my shapefile. I want to add polygons.<br> ><br> >     First I create a shapefile and a dbf file with an a simple column.<br> >     Then it<br> >     becomes valid for ArcCatalog.<br>
 >     Then I create 2 arrays of 7 elements X[7] and Y[7], and give a<br> >     valor to each<br> >     element. Seven elements because<br> >     I want to draw a polygon of six vertices.<br> ><br> >     After it I use psObject = SHPCreateObject to create my polygon and<br>
 >     after<br> >     SHPWriteObject( hSHP, -1, psObject ); to write it<br> >     in my shapefile.<br> ><br> >     It's obviously that I'm doing something wrong.<br> >     But I don't know what.<br>
 ><br> >     Can somebody help me or say me what I'm doing wrong?<br> ><br> >     Thanks.<br> ><br> ><br> >     [CODE]<br> >     #include <iostream><br> >     #include <cstdlib><br>
 >     #include "shapefil.h"<br> >     #include "string.h"<br> ><br> ><br> >     using namespace std;<br> >     int main()<br> ><br> >     {<br> >         SHPHandle    hSHP;<br>
 >         DBFHandle    hDBF;<br> >         int        nShapeType,   nWidth = 3, vertexcount, *panParts,<br> >     ShapeId,<br> >     nParts;<br> ><br> >         string  shape_name, Col1;<br> >         Col1= "Column";<br>
 ><br> >         SHPObject    *psObject;<br> ><br> ><br> >         cout << "Name of the new Shapefile" << endl;<br> >         getline(cin,shape_name);<br> ><br> >         cout << "The shapefile is: " << shape_name << endl;<br>
 ><br> >         //Here I define the type of shapefile, the 5 is for a polygon.<br> >         nShapeType=5;<br> ><br> ><br> >         hSHP = SHPCreate( shape_name.c_str(), nShapeType );<br> ><br> >         hDBF = DBFCreate( shape_name.c_str() );<br>
 ><br> ><br> >         cout <<"The shape has "<< DBFGetFieldCount( hDBF ) <<"<br> >     columns" << endl;<br> ><br> ><br> ><br> >         DBFAddField( hDBF, Col1.c_str(), FTInteger,   nWidth, 0 );<br>
 >         cout <<"Now the shape has " << DBFGetFieldCount( hDBF ) << "<br> >     columns";<br> ><br> >         //At this point the shape is valid for ArcView<br> ><br>
 >         //Here I define an array of seven elements and I'll give a<br> >     coordinate<br> >     for each element<br> ><br> >         double X[7], Y[7];<br> >         X[0] = 220764;<br> >         Y[0]= 2343777;<br>
 >         X[1] = 220610;<br> >         Y[1]= 2343627;<br> >         X[2] = 220818;<br> >         Y[2]= 2343477;<br> >         X[3] = 221109;<br> >         Y[3]= 2343777;<br> >         X[4] = 230504;<br>
 >         Y[4]= 2343627;<br> >         X[5] = 221102;<br> >         Y[5]= 2343477;<br> >         X[6] = X[0];<br> >         Y[6] = Y[0];<br> ><br> ><br> >         //I know the number of vertex is 7, six of my polygon and an extra<br>
 >         //vertex to close the polygon.<br> ><br> >         vertexcount = 7;<br> ><br> >         //I can't understand what is exactly the panParts variable. :(<br> ><br> >         panParts[0] = 1;<br>
 >         //What is nParts? For me my polygon has 1 part, an entire<br> >     part. It is<br> >     true?<br> >         nParts = 1;<br> >         //I give a shape id for this unique object.<br> >         ShapeId=1;<br>
 ><br> >     //From the shp_api I took this line of code to create a feature/object<br> >     //SHPCreateObject( nSHPType, iShape, nParts, panPartStart,<br> >     panPartType,int<br> >     nVertices, *padfX, * padfY, *padfZ, *padfM );<br>
 >     //I have the nShapeType;<br> >     //I give the ShapeId<br> >     //I give the nParts<br> >     //I don't know what is panParts<br> >     //panPartType is NULL because it isn't a multipatch file<br>
 >     //I know the numer of vertex<br> >     //I now the number of vertex I have two arrays of coordinates.<br> >     //padfZ and padfM are NULL, zero.<br> ><br> >         psObject = SHPCreateObject(nShapeType, ShapeId, nParts,<br>
 >     panParts, NULL,<br> >     vertexcount, X, Y, NULL, NULL );<br> ><br> >         SHPWriteObject( hSHP, -1, psObject );<br> ><br> >         SHPDestroyObject( psObject );<br> ><br> >         DBFClose( hDBF );<br>
 ><br> >         SHPClose( hSHP );<br> ><br> ><br> >         return 0;<br> >     }<br> ><br> >     [/CODE]<br> >     -------------- next part --------------<br> >     An HTML attachment was scrubbed...<br>
 >     URL:<br> >     <a href="http://lists.maptools.org/pipermail/shapelib/attachments/20080217/88536964/attachment-0001.html">http://lists.maptools.org/pipermail/shapelib/attachments/20080217/88536964/attachment-0001.html</a><br>
 ><br> >     ------------------------------<br> ><br> >     Message: 2<br> >     Date: Mon, 18 Feb 2008 00:34:51 +0100<br> >     From: Tom Kazimiers <<a href="mailto:2voodoo@gmx.de">2voodoo@gmx.de</a> <mailto:<a href="mailto:2voodoo@gmx.de">2voodoo@gmx.de</a>>><br>
 >     Subject: Re: [Shapelib] Adding a polygon to a shapefile<br> >     To: Shapelib Development <<a href="mailto:shapelib@lists.maptools.org">shapelib@lists.maptools.org</a><br> >     <mailto:<a href="mailto:shapelib@lists.maptools.org">shapelib@lists.maptools.org</a>>><br>
 >     Message-ID: <<a href="mailto:47B8C49B.3080801@gmx.de">47B8C49B.3080801@gmx.de</a> <mailto:<a href="mailto:47B8C49B.3080801@gmx.de">47B8C49B.3080801@gmx.de</a>>><br> >     Content-Type: text/plain; charset=ISO-8859-1; format=flowed<br>
 ><br> >     Hi Joaquin,<br> ><br> >     as fas as I understood you can not make this call:<br> >     psObject = SHPCreateObject(nShapeType, ShapeId, nParts, panParts,<br> >     NULL,<br> >     vertexcount, X, Y, NULL, NULL );<br>
 ><br> >     have you checked if osObject is null afterwards? Please try it.<br> >     Could it be that the first and the last vertex of a polygon need to be<br> >     the same? In your code they are different.<br>
 >     For my writing I use: SHPCreateSimpleObject which implys some NULLs of<br> >     yours - maybe you could try this, too.<br> ><br> >     bye,<br> >     Tom<br> ><br> ><br> >     Joaquin Perez Valera schrieb:<br>
 >     > Hi<br> >     ><br> >     > I can create shapefiles and they are valid when I work with<br> >     > ArcCatalog. But the shapefiles are empty.<br> >     ><br> >     > Now I'm trying to add objects to my shapefile. I want to add<br>
 >     polygons.<br> >     ><br> >     > First I create a shapefile and a dbf file with an a simple column.<br> >     > Then it becomes valid for ArcCatalog.<br> >     > Then I create 2 arrays of 7 elements X[7] and Y[7], and give a valor<br>
 >     > to each element. Seven elements because<br> >     > I want to draw a polygon of six vertices.<br> >     ><br> >     > After it I use psObject = SHPCreateObject to create my polygon and<br>
 >     > after   SHPWriteObject( hSHP, -1, psObject ); to write it<br> >     > in my shapefile.<br> >     ><br> >     > It's obviously that I'm doing something wrong.<br> >     > But I don't know what.<br>
 >     ><br> >     > Can somebody help me or say me what I'm doing wrong?<br> >     ><br> >     > Thanks.<br> >     ><br> >     ><br> >     > [CODE]<br> >     > #include <iostream><br>
 >     > #include <cstdlib><br> >     > #include "shapefil.h"<br> >     > #include "string.h"<br> >     ><br> >     ><br> >     > using namespace std;<br> >     > int main()<br>
 >     ><br> >     > {<br> >     >     SHPHandle    hSHP;<br> >     >     DBFHandle    hDBF;<br> >     >     int        nShapeType,   nWidth = 3, vertexcount, *panParts,<br> >     > ShapeId, nParts;<br>
 >     ><br> >     >     string  shape_name, Col1;<br> >     >     Col1= "Column";<br> >     ><br> >     >     SHPObject    *psObject;<br> >     ><br> >     ><br> >     >     cout << "Name of the new Shapefile" << endl;<br>
 >     >     getline(cin,shape_name);<br> >     ><br> >     >     cout << "The shapefile is: " << shape_name << endl;<br> >     ><br> >     >     //Here I define the type of shapefile, the 5 is for a polygon.<br>
 >     >     nShapeType=5;<br> >     ><br> >     ><br> >     >     hSHP = SHPCreate( shape_name.c_str(), nShapeType );<br> >     ><br> >     >     hDBF = DBFCreate( shape_name.c_str() );<br>
 >     ><br> >     ><br> >     >     cout <<"The shape has "<< DBFGetFieldCount( hDBF ) <<"<br> >     columns" <<<br> >     > endl;<br> >     ><br>
 >     ><br> >     ><br> >     >     DBFAddField( hDBF, Col1.c_str(), FTInteger,   nWidth, 0 );<br> >     >     cout <<"Now the shape has " << DBFGetFieldCount( hDBF ) << "<br>
 >     columns";<br> >     ><br> >     >     //At this point the shape is valid for ArcView<br> >     ><br> >     >     //Here I define an array of seven elements and I'll give a<br> >     > coordinate for each element<br>
 >     ><br> >     >     double X[7], Y[7];<br> >     >     X[0] = 220764;<br> >     >     Y[0]= 2343777;<br> >     >     X[1] = 220610;<br> >     >     Y[1]= 2343627;<br> >     >     X[2] = 220818;<br>
 >     >     Y[2]= 2343477;<br> >     >     X[3] = 221109;<br> >     >     Y[3]= 2343777;<br> >     >     X[4] = 230504;<br> >     >     Y[4]= 2343627;<br> >     >     X[5] = 221102;<br>
 >     >     Y[5]= 2343477;<br> >     >     X[6] = X[0];<br> >     >     Y[6] = Y[0];<br> >     ><br> >     ><br> >     >     //I know the number of vertex is 7, six of my polygon and an<br>
 >     extra<br> >     >     //vertex to close the polygon.<br> >     ><br> >     >     vertexcount = 7;<br> >     ><br> >     >     //I can't understand what is exactly the panParts variable. :(<br>
 >     ><br> >     >     panParts[0] = 1;<br> >     >     //What is nParts? For me my polygon has 1 part, an entire<br> >     part. It<br> >     > is true?<br> >     >     nParts = 1;<br> >     >     //I give a shape id for this unique object.<br>
 >     >     ShapeId=1;<br> >     ><br> >     > //From the shp_api I took this line of code to create a<br> >     feature/object<br> >     > //SHPCreateObject( nSHPType, iShape, nParts, panPartStart,<br>
 >     > panPartType,int nVertices, *padfX, * padfY, *padfZ, *padfM );<br> >     > //I have the nShapeType;<br> >     > //I give the ShapeId<br> >     > //I give the nParts<br> >     > //I don't know what is panParts<br>
 >     > //panPartType is NULL because it isn't a multipatch file<br> >     > //I know the numer of vertex<br> >     > //I now the number of vertex I have two arrays of coordinates.<br> >     > //padfZ and padfM are NULL, zero.<br>
 >     ><br> >     >     psObject = SHPCreateObject(nShapeType, ShapeId, nParts,<br> >     panParts,<br> >     > NULL, vertexcount, X, Y, NULL, NULL );<br> >     ><br> >     >     SHPWriteObject( hSHP, -1, psObject );<br>
 >     ><br> >     >     SHPDestroyObject( psObject );<br> >     ><br> >     >     DBFClose( hDBF );<br> >     ><br> >     >     SHPClose( hSHP );<br> >     ><br> >     ><br>
 >     >     return 0;<br> >     > }<br> >     ><br> >     > [/CODE]<br> >     ><br> >     ><br> >     ------------------------------------------------------------------------<br> >     ><br>
 >     > _______________________________________________<br> >     > Shapelib mailing list<br> >     > <a href="mailto:Shapelib@lists.maptools.org">Shapelib@lists.maptools.org</a> <mailto:<a href="mailto:Shapelib@lists.maptools.org">Shapelib@lists.maptools.org</a>><br>
 >     > <a href="http://lists.maptools.org/mailman/listinfo/shapelib">http://lists.maptools.org/mailman/listinfo/shapelib</a><br> >     ><br> ><br> ><br> ><br> >     ------------------------------<br>
 ><br> >     Message: 3<br> >     Date: Mon, 18 Feb 2008 00:43:00 +0100<br> >     From: Tom Kazimiers <<a href="mailto:2voodoo@gmx.de">2voodoo@gmx.de</a> <mailto:<a href="mailto:2voodoo@gmx.de">2voodoo@gmx.de</a>>><br>
 >     Subject: Re: [Shapelib] Adding a polygon to a shapefile<br> >     To: Shapelib Development <<a href="mailto:shapelib@lists.maptools.org">shapelib@lists.maptools.org</a><br> >     <mailto:<a href="mailto:shapelib@lists.maptools.org">shapelib@lists.maptools.org</a>>><br>
 >     Message-ID: <<a href="mailto:47B8C684.5040701@gmx.de">47B8C684.5040701@gmx.de</a> <mailto:<a href="mailto:47B8C684.5040701@gmx.de">47B8C684.5040701@gmx.de</a>>><br> >     Content-Type: text/plain; charset=ISO-8859-1; format=flowed<br>
 ><br> >     Joaquin,<br> ><br> >     sorry - I missed that you actually do have first and last elements the<br> >     same of your vertex arrays :)<br> >     But could you please write down where the error appears and what<br>
 >     kind of<br> >     error it is?<br> ><br> >     cheers,<br> >     Tom<br> ><br> >     Tom Kazimiers schrieb:<br> >     > Hi Joaquin,<br> >     ><br> >     > as fas as I understood you can not make this call:<br>
 >     > psObject = SHPCreateObject(nShapeType, ShapeId, nParts, panParts,<br> >     > NULL, vertexcount, X, Y, NULL, NULL );<br> >     ><br> >     > have you checked if osObject is null afterwards? Please try it.<br>
 >     > Could it be that the first and the last vertex of a polygon need<br> >     to be<br> >     > the same? In your code they are different.<br> >     > For my writing I use: SHPCreateSimpleObject which implys some<br>
 >     NULLs of<br> >     > yours - maybe you could try this, too.<br> >     ><br> >     > bye,<br> >     > Tom<br> >     ><br> >     ><br> >     > Joaquin Perez Valera schrieb:<br>
 >     >> Hi<br> >     >><br> >     >> I can create shapefiles and they are valid when I work with<br> >     >> ArcCatalog. But the shapefiles are empty.<br> >     >><br> >     >> Now I'm trying to add objects to my shapefile. I want to add<br>
 >     polygons.<br> >     >><br> >     >> First I create a shapefile and a dbf file with an a simple column.<br> >     >> Then it becomes valid for ArcCatalog.<br> >     >> Then I create 2 arrays of 7 elements X[7] and Y[7], and give a<br>
 >     valor<br> >     >> to each element. Seven elements because<br> >     >> I want to draw a polygon of six vertices.<br> >     >><br> >     >> After it I use psObject = SHPCreateObject to create my polygon and<br>
 >     >> after   SHPWriteObject( hSHP, -1, psObject ); to write it<br> >     >> in my shapefile.<br> >     >><br> >     >> It's obviously that I'm doing something wrong.<br> >     >> But I don't know what.<br>
 >     >><br> >     >> Can somebody help me or say me what I'm doing wrong?<br> >     >><br> >     >> Thanks.<br> >     >><br> >     >><br> >     >> [CODE]<br>
 >     >> #include <iostream><br> >     >> #include <cstdlib><br> >     >> #include "shapefil.h"<br> >     >> #include "string.h"<br> >     >><br>
 >     >><br> >     >> using namespace std;<br> >     >> int main()<br> >     >><br> >     >> {<br> >     >>     SHPHandle    hSHP;<br> >     >>     DBFHandle    hDBF;<br>
 >     >>     int        nShapeType,   nWidth = 3, vertexcount, *panParts,<br> >     >> ShapeId, nParts;<br> >     >><br> >     >>     string  shape_name, Col1;<br> >     >>     Col1= "Column";<br>
 >     >>       SHPObject    *psObject;<br> >     >>          cout << "Name of the new Shapefile" << endl;<br> >     >>     getline(cin,shape_name);<br> >     >><br>
 >     >>     cout << "The shapefile is: " << shape_name << endl;<br> >     >><br> >     >>     //Here I define the type of shapefile, the 5 is for a polygon.<br> >     >>     nShapeType=5;<br>
 >     >>           hSHP = SHPCreate( shape_name.c_str(), nShapeType );<br> >     >><br> >     >>     hDBF = DBFCreate( shape_name.c_str() );<br> >     >>                  cout <<"The shape has "<< DBFGetFieldCount( hDBF )<br>
 >     >> <<" columns" << endl;<br> >     >>            DBFAddField( hDBF, Col1.c_str(), FTInteger,<br> >     nWidth, 0 );<br> >     >>     cout <<"Now the shape has " << DBFGetFieldCount( hDBF ) << "<br>
 >     >> columns";<br> >     >>        //At this point the shape is valid for ArcView<br> >     >><br> >     >>     //Here I define an array of seven elements and I'll give a<br>
 >     >> coordinate for each element<br> >     >>        double X[7], Y[7];<br> >     >>     X[0] = 220764;<br> >     >>     Y[0]= 2343777;<br> >     >>     X[1] = 220610;<br>
 >     >>     Y[1]= 2343627;<br> >     >>     X[2] = 220818;<br> >     >>     Y[2]= 2343477;<br> >     >>     X[3] = 221109;<br> >     >>     Y[3]= 2343777;<br> >     >>     X[4] = 230504;<br>
 >     >>     Y[4]= 2343627;<br> >     >>     X[5] = 221102;<br> >     >>     Y[5]= 2343477;<br> >     >>     X[6] = X[0];<br> >     >>     Y[6] = Y[0];<br> >     >>           //I know the number of vertex is 7, six of my polygon and<br>
 >     >> an extra<br> >     >>     //vertex to close the polygon.<br> >     >>        vertexcount = 7;<br> >     >>        //I can't understand what is exactly the panParts<br> >     variable. :(<br>
 >     >>        panParts[0] = 1;<br> >     >>     //What is nParts? For me my polygon has 1 part, an entire part.<br> >     >> It is true?<br> >     >>     nParts = 1;<br> >     >>     //I give a shape id for this unique object.<br>
 >     >>     ShapeId=1;<br> >     >>    //From the shp_api I took this line of code to create a<br> >     >> feature/object<br> >     >> //SHPCreateObject( nSHPType, iShape, nParts, panPartStart,<br>
 >     >> panPartType,int nVertices, *padfX, * padfY, *padfZ, *padfM );<br> >     >> //I have the nShapeType;<br> >     >> //I give the ShapeId<br> >     >> //I give the nParts<br> >     >> //I don't know what is panParts<br>
 >     >> //panPartType is NULL because it isn't a multipatch file<br> >     >> //I know the numer of vertex<br> >     >> //I now the number of vertex I have two arrays of coordinates.<br> >     >> //padfZ and padfM are NULL, zero.<br>
 >     >><br> >     >>     psObject = SHPCreateObject(nShapeType, ShapeId, nParts,<br> >     panParts,<br> >     >> NULL, vertexcount, X, Y, NULL, NULL );<br> >     >>        SHPWriteObject( hSHP, -1, psObject );<br>
 >     >>        SHPDestroyObject( psObject );<br> >     >>        DBFClose( hDBF );<br> >     >>       SHPClose( hSHP );<br> >     >>               return 0;<br> >     >> }<br>
 >     >><br> >     >> [/CODE]<br> >     >><br> >     >><br> >     ------------------------------------------------------------------------<br> >     >><br> >     >> _______________________________________________<br>
 >     >> Shapelib mailing list<br> >     >> <a href="mailto:Shapelib@lists.maptools.org">Shapelib@lists.maptools.org</a> <mailto:<a href="mailto:Shapelib@lists.maptools.org">Shapelib@lists.maptools.org</a>><br>
 >     >> <a href="http://lists.maptools.org/mailman/listinfo/shapelib">http://lists.maptools.org/mailman/listinfo/shapelib</a><br> >     >><br> >     ><br> >     > _______________________________________________<br>
 >     > Shapelib mailing list<br> >     > <a href="mailto:Shapelib@lists.maptools.org">Shapelib@lists.maptools.org</a> <mailto:<a href="mailto:Shapelib@lists.maptools.org">Shapelib@lists.maptools.org</a>><br>
 >     > <a href="http://lists.maptools.org/mailman/listinfo/shapelib">http://lists.maptools.org/mailman/listinfo/shapelib</a><br> >     ><br> ><br> ><br> ><br> >     ------------------------------<br>
 ><br> >     _______________________________________________<br> >     Shapelib mailing list<br> >     <a href="mailto:Shapelib@lists.maptools.org">Shapelib@lists.maptools.org</a> <mailto:<a href="mailto:Shapelib@lists.maptools.org">Shapelib@lists.maptools.org</a>><br>
 >     <a href="http://lists.maptools.org/mailman/listinfo/shapelib">http://lists.maptools.org/mailman/listinfo/shapelib</a><br> ><br> ><br> >     End of Shapelib Digest, Vol 46, Issue 3<br> >     ***************************************<br>
 ><br> ><br> > ------------------------------------------------------------------------<br> ><br> > _______________________________________________<br> > Shapelib mailing list<br> > <a href="mailto:Shapelib@lists.maptools.org">Shapelib@lists.maptools.org</a><br>
 > <a href="http://lists.maptools.org/mailman/listinfo/shapelib">http://lists.maptools.org/mailman/listinfo/shapelib</a><br> ><br> <br> <br> <br> ------------------------------<br> <br> _______________________________________________<br>
 Shapelib mailing list<br> <a href="mailto:Shapelib@lists.maptools.org">Shapelib@lists.maptools.org</a><br> <a href="http://lists.maptools.org/mailman/listinfo/shapelib">http://lists.maptools.org/mailman/listinfo/shapelib</a><br>
 <br> <br> End of Shapelib Digest, Vol 46, Issue 7<br> ***************************************<br> </blockquote></div><br>