00001 #include <iostream>
00002 #include <iomanip>
00003
00004 #include "shapefil.h"
00005
00006 using namespace std;
00007
00008
00009 void mergeFeatures(const char** shpFileNames, const char** dbfFileNames, int fileCount, const char *newshpFileName, const char *newdbfFileName){
00010
00011
00012 int recordCount;
00013 SHPObject *obj;
00014
00015 SHPHandle newshp = SHPCreate(newshpFileName, SHPT_ARC);
00016 DBFHandle newdbf = DBFCreate(newdbfFileName);
00017
00018 int fld = DBFAddField(newdbf, "ID", FTInteger, 5, 0);
00019
00020 int k=0;
00021 for(int i=0; i<fileCount; i++){
00022 std::cout<<"\n-->"<<shpFileNames[i];
00023 SHPHandle shp = SHPOpen(shpFileNames[i], "rb");
00024 DBFHandle dbf = DBFOpen(dbfFileNames[i], "rb");
00025
00026 recordCount = DBFGetRecordCount(dbf);
00027
00028 for(int j=0; j<recordCount; j++){
00029 obj = SHPReadObject(shp, j);
00030 SHPWriteObject(newshp, -1, obj);
00031 DBFWriteIntegerAttribute(newdbf, k++, fld, j+1);
00032 }
00033
00034 SHPClose(shp);
00035 DBFClose(dbf);
00036 }
00037
00038 SHPClose(newshp);
00039 DBFClose(newdbf);
00040 }