shapelib 写线对象

#include "shapefil.h"

void  WriteFeature(string path)
{
    //https://blog.csdn.net/feihongchen/article/details/105462156
    if (m_Roadvec.size() == 0)
     return;
   
    int roadnum = m_Roadvec.size();

    int n, nEntities, nShapeType;
    BOOL bSuccess = FALSE;
    double adfMin[4], adfMax[4];
   
    std::string shp_fn = path + "\NewRoad";
   
    SHPHandle hShp = SHPCreate(string(shp_fn + ".shp").c_str(), SHPT_ARC);
    DBFHandle hDbf = DBFCreate(string(shp_fn + ".dbf").c_str());
   
    DBFAddField(hDbf, "ysbh", FTInteger, 10, 0);
    DBFAddField(hDbf, "mc", FTString, 50, 0);
    DBFAddField(hDbf, "kd", FTDouble, 10, 3);
   
    //int record_idx = DBFGetRecordCount(hDbf);
   
    for (int i = 0;i < roadnum;i++)
    {
     JBroad tempRoad = m_Roadvec[i];
   
     int nVertices = tempRoad.m_vPoints.size();
   
     double* padfX = new double[nVertices];
     double* padfY = new double[nVertices];
     //double* padfZ = new double[nVertices];
   
     for (int j = 0; j < nVertices; ++j)
     {
      padfX[j] = tempRoad.m_vPoints[j].getX();
      padfY[j] = tempRoad.m_vPoints[j].getY();
     }
   
     //SHPObject* shpObject = SHPCreateObject(SHPT_ARCZ, -1, 0, NULL, NULL, nVertices, padfX, padfY, padfZ, NULL);
     SHPObject* shpObject = SHPCreateObject(SHPT_ARC, -1, 0, NULL, NULL, nVertices, padfX, padfY, NULL, NULL);
     SHPWriteObject(hShp, -1, shpObject);
     SHPDestroyObject(shpObject);
   
     delete[] padfX;
     delete[] padfY;
     //delete[] padfZ;
   
     //int field_idx = 0;
   
     DBFWriteIntegerAttribute(hDbf, i, 0, tempRoad.m_ElementCode);
     DBFWriteStringAttribute(hDbf, i, 1, tempRoad.m_RoadName.c_str());
     DBFWriteDoubleAttribute(hDbf, i, 2, tempRoad.m_RoadWidth);
    }
   
    DBFClose(hDbf);
    SHPClose(hShp);

}

原文地址:https://www.cnblogs.com/roea1/p/13910673.html