Hi<br><br>I can create shapefiles and they are valid when I work with ArcCatalog. But the shapefiles are empty. <br><br>Now I&#39;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 becomes valid for ArcCatalog. <br>
Then I create 2 arrays of 7 elements X[7] and Y[7], and give a valor 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 after &nbsp; SHPWriteObject( hSHP, -1, psObject ); to write it<br>
in my shapefile. <br><br>It&#39;s obviously that I&#39;m doing something wrong. <br>But I don&#39;t know what. <br><br>Can somebody help me or say me what I&#39;m doing wrong?<br><br>Thanks.<br><br><br>[CODE]<br>#include &lt;iostream&gt;<br>
#include &lt;cstdlib&gt;<br>#include &quot;shapefil.h&quot;<br>#include &quot;string.h&quot;<br><br><br>using namespace std;<br>int main()<br><br>{<br>&nbsp;&nbsp;&nbsp; SHPHandle&nbsp;&nbsp;&nbsp; hSHP;<br>&nbsp;&nbsp;&nbsp; DBFHandle&nbsp;&nbsp;&nbsp; hDBF;<br>&nbsp;&nbsp;&nbsp; int&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; nShapeType,&nbsp;&nbsp; nWidth = 3, vertexcount, *panParts, ShapeId, nParts; <br>
<br>&nbsp;&nbsp;&nbsp; string&nbsp; shape_name, Col1;<br>&nbsp;&nbsp;&nbsp; Col1= &quot;Column&quot;;<br>&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; SHPObject&nbsp;&nbsp;&nbsp; *psObject;<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; cout &lt;&lt; &quot;Name of the new Shapefile&quot; &lt;&lt; endl;<br>&nbsp;&nbsp;&nbsp; getline(cin,shape_name);<br>
<br>&nbsp;&nbsp;&nbsp; cout &lt;&lt; &quot;The shapefile is: &quot; &lt;&lt; shape_name &lt;&lt; endl;<br><br>&nbsp;&nbsp;&nbsp; //Here I define the type of shapefile, the 5 is for a polygon. <br>&nbsp;&nbsp;&nbsp; nShapeType=5;<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; hSHP = SHPCreate( shape_name.c_str(), nShapeType );<br>
&nbsp; <br>&nbsp;&nbsp;&nbsp; hDBF = DBFCreate( shape_name.c_str() );<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; cout &lt;&lt;&quot;The shape has &quot;&lt;&lt; DBFGetFieldCount( hDBF ) &lt;&lt;&quot; columns&quot; &lt;&lt; endl;<br>&nbsp;&nbsp; <br>&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp; DBFAddField( hDBF, Col1.c_str(), FTInteger,&nbsp;&nbsp; nWidth, 0 );<br>&nbsp;&nbsp;&nbsp; cout &lt;&lt;&quot;Now the shape has &quot; &lt;&lt; DBFGetFieldCount( hDBF ) &lt;&lt; &quot; columns&quot;;<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; //At this point the shape is valid for ArcView<br>
<br>&nbsp;&nbsp;&nbsp; //Here I define an array of seven elements and I&#39;ll give a coordinate for each element<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; double X[7], Y[7];<br>&nbsp;&nbsp;&nbsp; X[0] = 220764;<br>&nbsp;&nbsp;&nbsp; Y[0]= 2343777;<br>&nbsp;&nbsp;&nbsp; X[1] = 220610;<br>&nbsp;&nbsp;&nbsp; Y[1]= 2343627;<br>
&nbsp;&nbsp;&nbsp; X[2] = 220818;<br>&nbsp;&nbsp;&nbsp; Y[2]= 2343477;<br>&nbsp;&nbsp;&nbsp; X[3] = 221109;<br>&nbsp;&nbsp;&nbsp; Y[3]= 2343777;<br>&nbsp;&nbsp;&nbsp; X[4] = 230504;<br>&nbsp;&nbsp;&nbsp; Y[4]= 2343627;<br>&nbsp;&nbsp;&nbsp; X[5] = 221102;<br>&nbsp;&nbsp;&nbsp; Y[5]= 2343477;<br>&nbsp;&nbsp;&nbsp; X[6] = X[0]; <br>&nbsp;&nbsp;&nbsp; Y[6] = Y[0];<br>&nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; //I know the number of vertex is 7, six of my polygon and an extra <br>&nbsp;&nbsp;&nbsp; //vertex to close the polygon.<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; vertexcount = 7;<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; //I can&#39;t understand what is exactly the panParts variable. :(<br>
&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; panParts[0] = 1;<br>&nbsp;&nbsp;&nbsp; //What is nParts? For me my polygon has 1 part, an entire part. It is true?<br>&nbsp;&nbsp;&nbsp; nParts = 1;<br>&nbsp;&nbsp;&nbsp; //I give a shape id for this unique object. <br>&nbsp;&nbsp;&nbsp; ShapeId=1;<br>&nbsp;&nbsp;&nbsp; <br>//From the shp_api I took this line of code to create a feature/object<br>
//SHPCreateObject( nSHPType, iShape, nParts, panPartStart, 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&#39;t know what is panParts<br>
//panPartType is NULL because it isn&#39;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>&nbsp;&nbsp;&nbsp; psObject = SHPCreateObject(nShapeType, ShapeId, nParts, panParts, NULL, vertexcount, X, Y, NULL, NULL );<br>
&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; SHPWriteObject( hSHP, -1, psObject );<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; SHPDestroyObject( psObject );<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; DBFClose( hDBF );<br>&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; SHPClose( hSHP );<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; return 0;<br>}<br><br>[/CODE]<br><br>