00001 #include <iostream>
00002
00003 #include "generateShape.h"
00004 #include "shapefil.h"
00005
00006 using namespace std;
00007
00008 void generateShape(QString shpFileName, double *avgVal, int NUM_FEATURES, int TYPE, const char *fStr)
00009 {
00010 int runFlag = 1;
00011
00012 QString dbfFileName(shpFileName);
00013 dbfFileName.truncate(dbfFileName.length()-3);
00014 dbfFileName.append("dbf");
00015
00016 SHPHandle shp = SHPOpen(qPrintable(shpFileName), "rb");
00017 DBFHandle dbf = DBFOpen(qPrintable(dbfFileName), "rb");
00018 SHPObject *obj;
00019
00020 int SHP_TYPE[1], Entities[1];
00021 SHPGetInfo(shp, Entities, SHP_TYPE, NULL, NULL);
00022
00023 SHPHandle newshp = SHPCreate("tempShape.shp", SHP_TYPE[0]);
00024 DBFHandle newdbf = DBFCreate("tempShape.dbf");
00025
00026 if(NUM_FEATURES != *Entities){
00027 qWarning("Number of Features doesnot match that in the shape file\n");
00028 runFlag = 0;
00029 }
00030
00031 if(runFlag == 1){
00032 double *x, *y, *z;
00033 x = (double *)malloc(TYPE*sizeof(double));
00034 y = (double *)malloc(TYPE*sizeof(double));
00035 z = (double *)malloc(TYPE*sizeof(double));
00036 cout<<fStr<<"\n";
00037 int valFld = DBFAddField(newdbf, fStr, FTDouble, 10, 8);
00038 int idFld = DBFAddField(newdbf, "ID", FTInteger, 10, 0);
00039
00040 for(int i=0; i<NUM_FEATURES; i++){
00041 obj = SHPReadObject(shp, i);
00042 SHPWriteObject(newshp, -1, obj);
00043
00044 DBFWriteIntegerAttribute(newdbf, i, idFld, i+1);
00045 DBFWriteDoubleAttribute(newdbf, i, valFld, avgVal[i]);
00046 }
00047 }
00048 SHPClose(shp); SHPClose(newshp);
00049 DBFClose(dbf); DBFClose(newdbf);
00050 }