pihmLIBS/splitLineAtVertices.h

Go to the documentation of this file.
00001 #include <iostream>
00002 #include <iomanip>
00003 
00004 #include "shapefil.h"
00005 
00006 using namespace std;
00007 
00008 void splitLineAtVertices(const char* shpFileName, const char* dbfFileName, const char* newshpFileName, const char* newdbfFileName){
00009         SHPHandle shp = SHPOpen(shpFileName, "rb");
00010         DBFHandle dbf = DBFOpen(dbfFileName, "rb");
00011         //cout<<shpFileName<<"\n";
00012         SHPHandle newshp = SHPCreate(newshpFileName, SHPT_ARC);
00013         DBFHandle newdbf = DBFCreate(newdbfFileName);
00014 
00015         int fld = DBFAddField(newdbf, "ID", FTInteger, 5, 0);
00016 
00017         int recordCount = DBFGetRecordCount(dbf);
00018 
00019         double X[2], Y[2], Z[2];
00020         int k=0;
00021         for(int i=0; i<recordCount; i++){
00022                 SHPObject *obj = SHPReadObject(shp, i);
00023                 for(int j=0; j<obj->nVertices-1; j++){
00024                         X[0]=obj->padfX[j];     X[1]=obj->padfX[j+1];
00025                         Y[0]=obj->padfY[j]; Y[1]=obj->padfY[j+1];
00026                         Z[0]=0; Z[1]=0;
00027                         SHPObject *newobj = SHPCreateSimpleObject(SHPT_ARC, 2, X, Y, Z);
00028                         SHPWriteObject(newshp, -1, newobj);
00029                         DBFWriteIntegerAttribute(newdbf, k++, fld, i+1);
00030                 }       
00031         }
00032 
00033         SHPClose(shp);
00034         DBFClose(dbf);
00035         SHPClose(newshp);
00036         DBFClose(newdbf);
00037 }

Generated on Sun Aug 5 17:34:00 2007 for PIHMgis by  doxygen 1.5.2