<br>Hi Tom<br><br>Well, I'm working with Dev-C++<br>I compile and run the code, and the compiler creates a myprogram.exe file. <br><br>When I work with myprogram.exe from the command line <br>I can give a name of the new file. The program creates the shapefile, adds a column in the dbf file. <br>
And after it returns the number of columns in the dbf. <br>Then the programm crashes and windows sends the message: <br>"myprogram.exe has encountered a problem and needs to close."<br><br>and I suposse the problem is in my code. <br>
<br>Well, Thanks for your attention. <br><br><br><br><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 kind of<br>
error it is?<br><br><br><br><div><span class="gmail_quote">2008/2/18, <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. 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>
Subject: [Shapelib] Adding a polygon to a shapefile<br>To: <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>
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 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. Then it<br>becomes valid for ArcCatalog.<br>Then I create 2 arrays of 7 elements X[7] and Y[7], and give a 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 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, 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 ) <<" columns" << endl;<br><br><br><br> DBFAddField( hDBF, Col1.c_str(), FTInteger, nWidth, 0 );<br> cout <<"Now the shape has " << DBFGetFieldCount( hDBF ) << " 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 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 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, 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, 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: <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>><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>Message-ID: <<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, 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 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 ) <<" columns" <<<br>> endl;<br>><br>><br>><br>> DBFAddField( hDBF, Col1.c_str(), FTInteger, nWidth, 0 );<br>
> cout <<"Now the shape has " << DBFGetFieldCount( hDBF ) << " 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 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 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 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, 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>> 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>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>><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>
Message-ID: <<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 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 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 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>>> 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, 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 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, 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>
>> 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>> 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 3<br>***************************************<br></blockquote></div><br>