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'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   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, 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 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 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 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, 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>