这篇教程C++ DBFClose函数代码示例写得很实用,希望能帮到您。
本文整理汇总了C++中DBFClose函数的典型用法代码示例。如果您正苦于以下问题:C++ DBFClose函数的具体用法?C++ DBFClose怎么用?C++ DBFClose使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。 在下文中一共展示了DBFClose函数的28个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。 示例1: parse void parse(const std::string& path, Visitor& visitor) const { SHPHandle shpFile = SHPOpen(path.c_str(), "rb"); if (shpFile == NULL) throw std::domain_error("Cannot open shp file."); int shapeType, entityCount; double adfMinBound[4], adfMaxBound[4]; SHPGetInfo(shpFile, &entityCount, &shapeType, adfMinBound, adfMaxBound); DBFHandle dbfFile = DBFOpen(path.c_str(), "rb"); if (dbfFile == NULL) throw std::domain_error("Cannot open dbf file."); if (DBFGetFieldCount(dbfFile) == 0) throw std::domain_error("There are no fields in dbf table."); if (entityCount != DBFGetRecordCount(dbfFile)) throw std::domain_error("dbf file has different entity count."); for (int k = 0; k < entityCount; k++) { SHPObject* shape = SHPReadObject(shpFile, k); if (shape == NULL) throw std::domain_error("Unable to read shape:" + to_string(k)); Tags tags = parseTags(dbfFile, k); visitShape(*shape, tags, visitor); SHPDestroyObject(shape); } DBFClose(dbfFile); SHPClose(shpFile); }
开发者ID:Euphe,项目名称:utymap,代码行数:35,
示例2: shapes_load_dbf// extract info from dbfvoidshapes_load_dbf(const char* filename, const char* column){ DBFHandle hDBF; hDBF = DBFOpen( filename, "rb" ); if( hDBF == NULL ) { fprintf(stderr, "DBFOpen(%s,/"r/") failed./n", filename ); return; } // INFO ABOUT DBF // int *panWidth; // int nWidth, nDecimals; // fprintf (stderr, "Info for %s/n", filename); // i = DBFGetFieldCount(hDBF); // fprintf (stderr, "%d Columns, %d Records in file/n",i,DBFGetRecordCount(hDBF)); // panWidth = (int *) malloc( DBFGetFieldCount( hDBF ) * sizeof(int) ); // for( int i = 0; i < DBFGetFieldCount(hDBF); i++ ) { // DBFFieldType eType; // char szTitle[256]; // eType = DBFGetFieldInfo( hDBF, i, szTitle, &nWidth, &nDecimals ); // fprintf(stderr, "%4d: %10s %c", i, szTitle, i%4 ? '|':'/n'); // } // fprintf(stderr, "/n"); // print names uint32_t fid = DBFGetFieldIndex(hDBF, column); for(uint32_t i = 0; i < DBFGetRecordCount(hDBF); i++ ) { char* name_long = (char *) DBFReadStringAttribute(hDBF, i, fid); fprintf(stderr, "%d: %s/n", i, name_long); } DBFClose( hDBF );}
开发者ID:peko,项目名称:tttm2,代码行数:36,
示例3: ShpLoaderDestroyvoidShpLoaderDestroy(SHPLOADERSTATE *state){ /* Destroy a state object created with ShpLoaderOpenShape */ if (state != NULL) { if (state->hSHPHandle) SHPClose(state->hSHPHandle); if (state->hDBFHandle) DBFClose(state->hDBFHandle); if (state->field_names) { int i; for (i = 0; i < state->num_fields; i++) free(state->field_names[i]); free(state->field_names); } if (state->types) free(state->types); if (state->widths) free(state->widths); if (state->precisions) free(state->precisions); if (state->col_names) free(state->col_names); /* Free the state itself */ free(state); }}
开发者ID:imincik,项目名称:pkg-postgis-1.5,代码行数:32,
示例4: CPLDebugOGRShapeLayer::~OGRShapeLayer(){ if( m_nFeaturesRead > 0 && poFeatureDefn != NULL ) { CPLDebug( "Shape", "%d features read on layer '%s'.", (int) m_nFeaturesRead, poFeatureDefn->GetName() ); } CPLFree( panMatchingFIDs ); panMatchingFIDs = NULL; CPLFree( pszFullName ); if( poFeatureDefn != NULL ) poFeatureDefn->Release(); if( poSRS != NULL ) poSRS->Release(); if( hDBF != NULL ) DBFClose( hDBF ); if( hSHP != NULL ) SHPClose( hSHP ); if( fpQIX != NULL ) VSIFClose( fpQIX );}
开发者ID:dlsyaim,项目名称:osgEarthX,代码行数:30,
示例5: SHPClosebool surfaceVectorField::CreateShape(){ char DataBaseID[64]=""; hSHP=SHPCreate(ShapeFileName.c_str(), SHPT_POINT); if(hSHP==NULL) return false; SHPClose( hSHP ); // Create the database. hDBF=DBFCreate(DataBaseName.c_str()); if(hDBF==NULL) return false; //sprintf(DataBaseID, "%s", "Xcoord"); //DBFAddField(hDBF, DataBaseID, FTDouble, 16, 6); //sprintf(DataBaseID, "%s", "Ycoord"); //DBFAddField(hDBF, DataBaseID, FTDouble, 16, 6); sprintf(DataBaseID, "%s", "Windspd"); DBFAddField(hDBF, DataBaseID, FTDouble, 16, 6 ); sprintf(DataBaseID, "%s", "Winddir"); DBFAddField(hDBF, DataBaseID, FTInteger, 8, 0); sprintf(DataBaseID, "%s", "AV_dir"); DBFAddField(hDBF, DataBaseID, FTInteger, 8, 0 ); sprintf(DataBaseID, "%s", "AM_dir"); DBFAddField(hDBF, DataBaseID, FTInteger, 8, 0 ); DBFClose(hDBF); return true;}
开发者ID:psuliuxf,项目名称:windninja,代码行数:29,
示例6: DBFCloneEmptyDBFHandle DBFCloneEmpty(DBFHandle psDBF, const char * pszFilename ) { DBFHandle newDBF; newDBF = DBFCreate ( pszFilename ); if ( newDBF == NULL ) return ( NULL ); newDBF->pszHeader = (char *) malloc ( 32 * psDBF->nFields ); memcpy ( newDBF->pszHeader, psDBF->pszHeader, 32 * psDBF->nFields ); newDBF->nFields = psDBF->nFields; newDBF->nRecordLength = psDBF->nRecordLength; newDBF->nHeaderLength = psDBF->nHeaderLength; newDBF->panFieldOffset = (int *) malloc ( sizeof(int) * psDBF->nFields ); memcpy ( newDBF->panFieldOffset, psDBF->panFieldOffset, sizeof(int) * psDBF->nFields ); newDBF->panFieldSize = (int *) malloc ( sizeof(int) * psDBF->nFields ); memcpy ( newDBF->panFieldSize, psDBF->panFieldSize, sizeof(int) * psDBF->nFields ); newDBF->panFieldDecimals = (int *) malloc ( sizeof(int) * psDBF->nFields ); memcpy ( newDBF->panFieldDecimals, psDBF->panFieldDecimals, sizeof(int) * psDBF->nFields ); newDBF->pachFieldType = (char *) malloc ( sizeof(int) * psDBF->nFields ); memcpy ( newDBF->pachFieldType, psDBF->pachFieldType, sizeof(int) * psDBF->nFields ); newDBF->bNoHeader = TRUE; newDBF->bUpdated = TRUE; DBFWriteHeader ( newDBF ); DBFClose ( newDBF ); newDBF = DBFOpen ( pszFilename, "rb+" ); return ( newDBF );}
开发者ID:bmfekete,项目名称:TauDEM,代码行数:33,
示例7: DBFOpenint CDbfFile::DBFAddRecord(CStringArray* psDBFFieldValList){ DBFHandle hDBF; int i; int iRecord; int iNumField; if (psDBFFieldValList == NULL) iNumField = 0; else iNumField = psDBFFieldValList->GetSize(); // Open/Create the database. hDBF = DBFOpen("r+b" ); if( hDBF == NULL ) { printf("DBFOpen failed: %s", _szDBFName); return 1; } // Do we have the correct number of arguments? if( DBFGetFieldCount( hDBF ) != iNumField ) { CString sMsg; sMsg.Format("Received %d field(s), but require %d field(s).",iNumField,DBFGetFieldCount(hDBF)); printf("%s/n",sMsg); int i, iWidth, iDecimals; char psName[257]; for (i=0; i<DBFGetFieldCount(hDBF); i++) { DBFGetFieldInfo(hDBF,i,psName,&iWidth,&iDecimals); sMsg.Format("%d of %d) FieldName: %s Width: %d Decimals: %d",i+1,DBFGetFieldCount(hDBF),psName,iWidth,iDecimals); printf("%s/n",sMsg); } return 1; } iRecord = DBFGetRecordCount( hDBF );/* -------------------------------------------------------------------- *//* Loop assigning the new field values. *//* -------------------------------------------------------------------- */ for( i = 0; i < DBFGetFieldCount(hDBF); i++ ) { if( DBFGetFieldInfo( hDBF, i, NULL, NULL, NULL ) == FTString ) DBFWriteStringAttribute(hDBF, iRecord, i, psDBFFieldValList->GetAt(i) ); else DBFWriteDoubleAttribute(hDBF, iRecord, i, atof(psDBFFieldValList->GetAt(i)) ); }/* -------------------------------------------------------------------- *//* Close and cleanup. *//* -------------------------------------------------------------------- */ DBFClose( hDBF ); return 0;}
开发者ID:giulange,项目名称:landmapr-cpp,代码行数:59,
示例8: dbf_file_exists/** * /brief Checks DBF file existance and validity * * /param dbf_file path and file name of DBF file * * /return Returns true if existing and valid * */bool dbf_file_exists(const char* dbf_file) { DBFHandle handle = DBFOpen(dbf_file, "rb"); if (handle == NULL) { return false; } DBFClose(handle); return true;}
开发者ID:knowname,项目名称:morituri,代码行数:16,
示例9: mainint main( int argc, char ** argv ){ DBFHandle hDBF; int i, iRecord;/* -------------------------------------------------------------------- *//* Display a usage message. *//* -------------------------------------------------------------------- */ if( argc < 3 ) { printf( "dbfadd xbase_file field_values/n" ); exit( 1 ); }/* -------------------------------------------------------------------- *//* Create the database. *//* -------------------------------------------------------------------- */ hDBF = DBFOpen( argv[1], "r+b" ); if( hDBF == NULL ) { printf( "DBFOpen(%s,/"rb+/") failed./n", argv[1] ); exit( 2 ); } /* -------------------------------------------------------------------- *//* Do we have the correct number of arguments? *//* -------------------------------------------------------------------- */ if( DBFGetFieldCount( hDBF ) != argc - 2 ) { printf( "Got %d fields, but require %d/n", argc - 2, DBFGetFieldCount( hDBF ) ); exit( 3 ); } iRecord = DBFGetRecordCount( hDBF );/* -------------------------------------------------------------------- *//* Loop assigning the new field values. *//* -------------------------------------------------------------------- */ for( i = 0; i < DBFGetFieldCount(hDBF); i++ ) { if( strcmp( argv[i+2], "" ) == 0 ) DBFWriteNULLAttribute(hDBF, iRecord, i ); else if( DBFGetFieldInfo( hDBF, i, NULL, NULL, NULL ) == FTString ) DBFWriteStringAttribute(hDBF, iRecord, i, argv[i+2] ); else DBFWriteDoubleAttribute(hDBF, iRecord, i, atof(argv[i+2]) ); }/* -------------------------------------------------------------------- *//* Close and cleanup. *//* -------------------------------------------------------------------- */ DBFClose( hDBF ); return( 0 );}
开发者ID:dranch,项目名称:Xastir,代码行数:58,
示例10: DBFClosevoid rspfShapeDatabase::close(){ if(isOpen()) { DBFClose(theHandle); theHandle = NULL; theRecordNumber = -1; }}
开发者ID:vapd-radi,项目名称:rspf_v2.0,代码行数:9,
示例11: close_baseline_shapevoid close_baseline_shape(DBFHandle dbase, SHPHandle shape){ // Close database DBFClose(dbase); dbase = NULL; // Close shapefile SHPClose(shape); shape = NULL;}
开发者ID:rudigens,项目名称:ASF_MapReady,代码行数:10,
示例12: close void close() { if (m_dbf_handle) { DBFClose(m_dbf_handle); m_dbf_handle = 0; } if (m_shp_handle) { SHPClose(m_shp_handle); m_shp_handle = 0; } }
开发者ID:MaZderMind,项目名称:osmium,代码行数:10,
示例13: CStringArrayint CDbfFile::AddDBF4(char* psDBFAttList,CString sDelimiter, int nSize)//used when strings separated by '/0'{ DBFHandle hDBF; int kk; CFileFind ShapeFile; CString sTmp; CStringArray *psDBFAtt; psDBFAtt = new CStringArray(); if (_bInit) { _bInit = false; ValidateDBF(); DBFSetColumn(&_psDBFAttList); } // Open/Create the database. hDBF = DBFOpen("r+b" ); if( hDBF == NULL ) { printf("DBFOpen failed: %s/n", _szDBFName); return 1; } int nStrStart = 0; for (kk = 0; kk < nSize; kk++) { psDBFAtt->RemoveAll(); sTmp = ""; while(psDBFAttList[nStrStart]!='/0') { sTmp = sTmp + psDBFAttList[nStrStart++]; } nStrStart++; while (sTmp.Find(sDelimiter) != -1) { psDBFAtt->Add(sTmp.Left(sTmp.Find(sDelimiter))); sTmp.Delete(0, (sTmp.Find(sDelimiter) + 1)); } if (!sTmp.IsEmpty()) psDBFAtt->Add(sTmp); DBFAddRecord(hDBF, psDBFAtt); } psDBFAtt->RemoveAll();/* -------------------------------------------------------------------- *//* Close and cleanup. *//* -------------------------------------------------------------------- */ DBFClose( hDBF ); delete(psDBFAtt); return 0;}
开发者ID:giulange,项目名称:landmapr-cpp,代码行数:55,
示例14: Java_org_maptools_shapelib_android_util_TestUtils_updateShapefilejboolean Java_org_maptools_shapelib_android_util_TestUtils_updateShapefile(JNIEnv * env, jclass clazz, jstring file, jobject listObject) { // open an existing shapefile and dbf (e.g. /sdcard/foo/bar) const char *fileStr = (*env)->GetStringUTFChars(env, file, 0); SHPHandle hSHP = SHPOpen(fileStr, "rb+"); DBFHandle hDBF = DBFOpen(fileStr, "rb+"); (*env)->ReleaseStringUTFChars(env, file, fileStr); process(env, hSHP, hDBF, file, listObject); SHPClose(hSHP); DBFClose(hDBF);}
开发者ID:jessisena,项目名称:shapelib-android-demo,代码行数:13,
示例15: Java_org_maptools_shapelib_android_util_TestUtils_createShapefilejboolean Java_org_maptools_shapelib_android_util_TestUtils_createShapefile(JNIEnv * env, jclass clazz, jstring file, jobject listObject) { // create a shapefile and dbf (e.g. /sdcard/foo/bar) const char *fileStr = (*env)->GetStringUTFChars(env, file, 0); SHPHandle hSHP = SHPCreate(fileStr, SHPT_POINT); DBFHandle hDBF = DBFCreate(fileStr); // define the shapefile attributes DBFAddField(hDBF, "name", FTString, 25, 0); DBFAddField(hDBF, "height", FTDouble, 8, 8); DBFAddField(hDBF, "apples", FTInteger, 1, 0); process(env, hSHP, hDBF, file, listObject); SHPClose(hSHP); DBFClose(hDBF);}
开发者ID:jessisena,项目名称:shapelib-android-demo,代码行数:17,
示例16: display_infostatic int display_info(const char * fpath, const struct stat * sb, int tflag, struct FTW * ftwbuf){ if (fpath[ftwbuf->base] == '.') return 0; if (strcmp(fpath + strlen(fpath) - 4, ".dbf") != 0) return 0; char file[400]; strncpy(file, fpath + strlen(data_path), 400); file[strlen(file)-4] = 0; DBFHandle dbf = DBFOpen(fpath, "rb"); SHPHandle shp = SHPOpen(fpath, "rb"); general_count++; char * formatc = mg_get_var(dconn, "format"); int json = 0; if (formatc != NULL && strcmp(formatc, "json") == 0) json = 1; free(formatc); if (json) { mg_printf(dconn, "%s/n {", ((general_count==1) ? "" : ",")); mg_printf(dconn, "/"file/":/"%s/"", file); if (dbf) mg_printf(dconn, ", /"dbfRecords/":%d", dbf->nRecords); if (dbf) mg_printf(dconn, ", /"dbfFields/":%d", dbf->nFields); mg_printf(dconn, ", /"image 0/": /"/image?file=%s&id=0/"", file); mg_printf(dconn, ", /"full image/": /"/image?file=%s/"", file); mg_printf(dconn, "}"); } else { mg_printf(dconn, "<tr>"); mg_printf(dconn, "<td>%s</td>", file); if (dbf) mg_printf(dconn, "<td><a href='/shapefiles/fields?file=%s'>fields</a></td>", file); if (shp) mg_printf(dconn, "<td><a href='/shapefiles/png?file=%s'>image</a></td>/n", file); mg_printf(dconn, "</tr>"); } if (shp) SHPClose(shp); if (dbf) DBFClose(dbf); return 0; // To tell nftw() to continue}
开发者ID:kbranigan,项目名称:tubes,代码行数:46,
示例17: ShpLoaderDestroyvoidShpLoaderDestroy(SHPLOADERSTATE *state){ /* Destroy a state object created with ShpLoaderOpenShape */ int i; if (state != NULL) { if (state->hSHPHandle) SHPClose(state->hSHPHandle); if (state->hDBFHandle) DBFClose(state->hDBFHandle); if (state->field_names) { for (i = 0; i < state->num_fields; i++) free(state->field_names[i]); free(state->field_names); } if (state->pgfieldtypes) { for (i = 0; i < state->num_fields; i++) free(state->pgfieldtypes[i]); free(state->pgfieldtypes); } if (state->types) free(state->types); if (state->widths) free(state->widths); if (state->precisions) free(state->precisions); if (state->col_names) free(state->col_names); /* Free any column map fieldnames if specified */ colmap_clean(&state->column_map); /* Free the state itself */ free(state); }}
开发者ID:nextgis-borsch,项目名称:postgis,代码行数:41,
示例18: shapefiles_fieldsvoid shapefiles_fields(struct mg_connection *conn, const struct mg_request_info *ri, void *data){ char * file = mg_get_var(conn, "file"); if (file == NULL) { mg_printf(conn, "You need to specify a file."); return; } char filename[100]; sprintf(filename, "/work/data/%s", file); DBFHandle dbf = DBFOpen(filename, "rb"); if (dbf == NULL) { mg_printf(conn, "DBFOpen error (%s)/n", filename); return; } int nRecordCount = DBFGetRecordCount(dbf); int nFieldCount = DBFGetFieldCount(dbf); mg_printf(conn, "{/n"); mg_printf(conn, " /"file/": /"%s/",/n", file); mg_printf(conn, " /"num_records/": /"%d/",/n", nRecordCount); mg_printf(conn, " /"fields/": {/n"); for (int i = 0 ; i < nFieldCount ; i++) { char pszFieldName[12]; int pnWidth; int pnDecimals; char type_names[5][20] = {"string", "integer", "double", "logical", "invalid"}; DBFFieldType ft = DBFGetFieldInfo(dbf, i, pszFieldName, &pnWidth, &pnDecimals); mg_printf(conn, " /"%d/": {/n", i); mg_printf(conn, " /"name/":/"%s/",/n", pszFieldName); if (pnWidth != 0) mg_printf(conn, " /"width/":/"%d/",/n", pnWidth); if (pnDecimals != 0) mg_printf(conn, " /"decimals/":/"%d/",/n", pnDecimals); mg_printf(conn, " /"type/":/"%s/"/n", type_names[ft]); mg_printf(conn, " }%s/n", (i==nFieldCount-1)?"":","); } mg_printf(conn, " }/n"); mg_printf(conn, "}/n"); if (dbf != NULL) DBFClose(dbf); free(file);}
开发者ID:kbranigan,项目名称:tubes,代码行数:38,
示例19: isshapeint isshape(char *inFile){ char *ext = findExt(inFile); if (ext && strcmp_case(ext,".shp")!=0) { return FALSE; } char *dbaseFile, *basename; int isShape = 0; int nEntities, pointType; DBFHandle dbase; SHPHandle shape; dbaseFile = (char *)MALLOC(sizeof(char)*(strlen(inFile)+5)); basename = get_basename(inFile); sprintf(dbaseFile, "%s.dbf", basename); dbase = DBFOpen(dbaseFile, "r+b"); shape = SHPOpen(inFile, "r+b"); if (dbase != NULL && shape != NULL) { SHPGetInfo(shape, &nEntities, &pointType, NULL, NULL); if (nEntities >= 1 && (pointType == SHPT_POLYGON || pointType == SHPT_POINT || pointType == SHPT_ARC || pointType == SHPT_MULTIPOINT ) ) { isShape = 1; } } if (shape) SHPClose(shape); if (dbase) DBFClose(dbase); FREE(basename); FREE(dbaseFile); return isShape;}
开发者ID:DavinSimmons,项目名称:ASF_MapReady,代码行数:37,
示例20: shape_load_namesstrings_vshape_load_names(const char* filename, const char* colname) { DBFHandle hDBF; strings_v col; kv_init(col); hDBF = DBFOpen( filename, "rb" ); if( hDBF == NULL ) { fprintf(stderr, "DBFOpen(%s,/"r/") failed./n", filename ); return col; } uint32_t fid = DBFGetFieldIndex(hDBF, colname); for(uint32_t i = 0; i < DBFGetRecordCount(hDBF); i++ ) { char* str = (char *) DBFReadStringAttribute(hDBF, i, fid); if(str != NULL) kv_push(char*, col, strdup(str)); else kv_push(char*, col, NULL); } DBFClose( hDBF ); return col;}
开发者ID:peko,项目名称:tttm2,代码行数:24,
示例21: mainint main( int argc, char ** argv ){ SHPHandle old_SHP, new_SHP; DBFHandle old_DBF, new_DBF; int nShapeType, nEntities, nVertices, nParts, *panParts, i, iPart; double *padVertices, adBounds[4]; const char *pszPlus; DBFFieldType idfld_type; int idfld, nflds; char kv[257] = ""; char idfldName[120] = ""; char fldName[120] = ""; char shpFileName[120] = ""; char dbfFileName[120] = ""; char *DBFRow = NULL; int Cpan[2] = { 0,0 }; int byRing = 1; PT oCentrd, ringCentrd; SHPObject *psCShape, *cent_pt; double oArea = 0.0, oLen = 0.0; if( argc < 2 ) { printf( "shpdata shp_file /n" ); exit( 1 ); } old_SHP = SHPOpen (argv[1], "rb" ); old_DBF = DBFOpen (argv[1], "rb"); if( old_SHP == NULL || old_DBF == NULL ) { printf( "Unable to open old files:%s/n", argv[1] ); exit( 1 ); } SHPGetInfo( old_SHP, &nEntities, &nShapeType, NULL, NULL ); for( i = 0; i < nEntities; i++ ) { int res ; psCShape = SHPReadObject( old_SHP, i ); if ( byRing == 1 ) { int ring, prevStart, ringDir; double ringArea; prevStart = psCShape->nVertices; for ( ring = (psCShape->nParts - 1); ring >= 0; ring-- ) { SHPObject *psO; int j, numVtx, rStart; rStart = psCShape->panPartStart[ring]; if ( ring == (psCShape->nParts -1) ) { numVtx = psCShape->nVertices - rStart; } else { numVtx = psCShape->panPartStart[ring+1] - rStart; } printf ("(shpdata) Ring(%d) (%d for %d) /n", ring, rStart, numVtx); psO = SHPClone ( psCShape, ring, ring + 1 ); ringDir = SHPRingDir_2d ( psO, 0 ); ringArea = RingArea_2d (psO->nVertices,(double*) psO->padfX, (double*) psO->padfY); RingCentroid_2d ( psO->nVertices, (double*) psO->padfX, (double*) psO->padfY, &ringCentrd, &ringArea); printf ("(shpdata) Ring %d, %f Area %d dir /n", ring, ringArea, ringDir ); SHPDestroyObject ( psO ); printf ("(shpdata) End Ring /n"); } /* (ring) [0,nParts */ } /* by ring */ oArea = SHPArea_2d ( psCShape ); oLen = SHPLength_2d ( psCShape ); oCentrd = SHPCentrd_2d ( psCShape ); printf ("(shpdata) Part (%d) %f Area %f length, C (%f,%f)/n", i, oArea, oLen, oCentrd.x, oCentrd.y ); } SHPClose( old_SHP ); DBFClose( old_DBF ); printf ("/n");}
开发者ID:AliceWang,项目名称:census_utils,代码行数:90,
示例22: main//.........这里部分代码省略......... else sprintf( szFormat, "%%%ds ", panWidth[i] ); printf( szFormat, szTitle ); } printf( "/n" );/* -------------------------------------------------------------------- *//* Read all the records *//* -------------------------------------------------------------------- */ for( iRecord = 0; iRecord < DBFGetRecordCount(hDBF); iRecord++ ) { if( bMultiLine ) printf( "Record: %d/n", iRecord ); for( i = 0; i < DBFGetFieldCount(hDBF); i++ ) { DBFFieldType eType; eType = DBFGetFieldInfo( hDBF, i, szTitle, &nWidth, &nDecimals ); if( bMultiLine ) { printf( "%s: ", szTitle ); } /* -------------------------------------------------------------------- *//* Print the record according to the type and formatting *//* information implicit in the DBF field description. *//* -------------------------------------------------------------------- */ if( !bRaw ) { if( DBFIsAttributeNULL( hDBF, iRecord, i ) ) { if( eType == FTString ) sprintf( szFormat, "%%-%ds", nWidth ); else sprintf( szFormat, "%%%ds", nWidth ); printf( szFormat, "(NULL)" ); } else { switch( eType ) { case FTString: sprintf( szFormat, "%%-%ds", nWidth ); printf( szFormat, DBFReadStringAttribute( hDBF, iRecord, i ) ); break; case FTInteger: sprintf( szFormat, "%%%dd", nWidth ); printf( szFormat, DBFReadIntegerAttribute( hDBF, iRecord, i ) ); break; case FTDouble: sprintf( szFormat, "%%%d.%dlf", nWidth, nDecimals ); printf( szFormat, DBFReadDoubleAttribute( hDBF, iRecord, i ) ); break; default: break; } } }/* -------------------------------------------------------------------- *//* Just dump in raw form (as formatted in the file). *//* -------------------------------------------------------------------- */ else { sprintf( szFormat, "%%-%ds", nWidth ); printf( szFormat, DBFReadStringAttribute( hDBF, iRecord, i ) ); }/* -------------------------------------------------------------------- *//* Write out any extra spaces required to pad out the field *//* width. *//* -------------------------------------------------------------------- */ if( !bMultiLine ) { sprintf( szFormat, "%%%ds", panWidth[i] - nWidth + 1 ); printf( szFormat, "" ); } if( bMultiLine ) printf( "/n" ); fflush( stdout ); } printf( "/n" ); } DBFClose( hDBF ); return( 0 );}
开发者ID:AliceWang,项目名称:census_utils,代码行数:101,
示例23: CPLError//.........这里部分代码省略........./* -------------------------------------------------------------------- *//* Copy over all records that are not deleted. *//* -------------------------------------------------------------------- */ int iDestShape = 0; int iNextDeletedShape = 0; for( iShape = 0; iShape < nTotalShapeCount && eErr == OGRERR_NONE; iShape++ ) { if( panRecordsToDelete[iNextDeletedShape] == iShape ) iNextDeletedShape++; else { void *pTuple = (void *) DBFReadTuple( hDBF, iShape ); if( pTuple == NULL ) eErr = OGRERR_FAILURE; else if( !DBFWriteTuple( hNewDBF, iDestShape++, pTuple ) ) eErr = OGRERR_FAILURE; } } if( eErr != OGRERR_NONE ) { CPLFree( panRecordsToDelete ); VSIUnlink( oTempFile ); return eErr; }/* -------------------------------------------------------------------- *//* Cleanup the old .dbf and rename the new one. *//* -------------------------------------------------------------------- */ DBFClose( hDBF ); DBFClose( hNewDBF ); hDBF = hNewDBF = NULL; VSIUnlink( osDBFName ); if( VSIRename( oTempFile, osDBFName ) != 0 ) { CPLDebug( "Shape", "Can not rename DBF file: %s", VSIStrerror( errno ) ); CPLFree( panRecordsToDelete ); return OGRERR_FAILURE; } /* -------------------------------------------------------------------- *//* Now create a shapefile matching the old one. *//* -------------------------------------------------------------------- */ if( hSHP != NULL ) { SHPHandle hNewSHP = NULL; if (osSHPName.size() == 0 || osSHXName.size() == 0) { /* Should not happen, really */ CPLFree( panRecordsToDelete ); return OGRERR_FAILURE; } oTempFile = CPLFormFilename(osDirname, osBasename, NULL); oTempFile += "_packed.shp"; hNewSHP = SHPCreate( oTempFile, hSHP->nShapeType ); if( hNewSHP == NULL ) {
开发者ID:dlsyaim,项目名称:osgEarthX,代码行数:67,
示例24: main//.........这里部分代码省略......... { char pszFieldName[12]; int pnWidth; int pnDecimals; DBFFieldType ft = DBFGetFieldInfo(d, i, pszFieldName, &pnWidth, &pnDecimals); switch (ft) { case FTString: fprintf(fp, ", %s VARCHAR(%d)", pszFieldName, pnWidth); break; case FTInteger: fprintf(fp, ", %s INT", pszFieldName); break; case FTDouble: fprintf(fp, ", %s FLOAT(15,10)", pszFieldName); break; case FTLogical: break; case FTInvalid: break; } }*/ fprintf(fp, " <Document>/n"); int i; for (i = 0 ; i < nRecordCount ; i++) { fprintf(fp, " <Placemark>/n"); fprintf(fp, " <name>%s</name>/n", (char *)DBFReadStringAttribute(d, i, 2)); fprintf(fp, " <Polygon>/n"); fprintf(fp, " <extrude>1</extrude>/n"); fprintf(fp, " <altitudeMode>relativeToGround</altitudeMode>/n"); fprintf(fp, " <outerBoundaryIs>/n"); fprintf(fp, " <LinearRing>/n"); fprintf(fp, " <coordinates>/n"); SHPObject *psShape = SHPReadObject(h, i); int j, iPart; for (j = 0, iPart = 1; j < psShape->nVertices; j++) { fprintf(fp, "%f,%f,100/n", psShape->padfX[j], psShape->padfY[j]); } fprintf(fp, " </coordinates>/n"); fprintf(fp, " </LinearRing>/n"); fprintf(fp, " </outerBoundaryIs>/n"); fprintf(fp, " </Polygon>/n"); fprintf(fp, " </Placemark>/n"); } fprintf(fp, " </Document>/n"); /*int nShapeType; int nEntities; const char *pszPlus; double adfMinBound[4], adfMaxBound[4]; SHPGetInfo(h, &nEntities, &nShapeType, adfMinBound, adfMaxBound); printf("SHP has %d entities/n", nEntities); for (i = 0; i < nEntities; i++) { SHPObject *psShape = SHPReadObject(h, i); //fprintf(fp, "INSERT INTO edges (id) VALUES (%d);/n", i+1); int j, iPart; for (j = 0, iPart = 1; j < psShape->nVertices; j++) { const char *pszPartType = ""; if (j == 0 && psShape->nParts > 0) pszPartType = SHPPartTypeName(psShape->panPartType[0]); if (iPart < psShape->nParts && psShape->panPartStart[iPart] == j) { pszPartType = SHPPartTypeName(psShape->panPartType[iPart]); iPart++; pszPlus = "+"; } else pszPlus = " "; //if (j%500==0) // fprintf(fp, "%sINSERT INTO vertexes (edge_id, x, y) VALUES (", (j!=0 ? ");/n": "")); //else // fprintf(fp, "),("); //fprintf(fp, "%d, %f, %f", i+1, psShape->padfX[j], psShape->padfY[j]); } //fprintf(fp, ");/n"); SHPDestroyObject(psShape); }*/ fprintf(fp, "</kml>/n"); printf("all done/n"); fclose(fp); if (h != NULL) SHPClose(h); if (d != NULL) DBFClose(d);}
开发者ID:PereiraM,项目名称:shapefile_converter,代码行数:101,
示例25: WritePointShapefile//.........这里部分代码省略........./* -------------------------------------------------------------------- *//* Fetch a reference to the indexed Pointgon reader. *//* -------------------------------------------------------------------- */ poPointReader = (SDTSPointReader *) poTransfer->GetLayerIndexedReader( poTransfer->FindLayer( pszMODN ) ); if( poPointReader == NULL ) { fprintf( stderr, "Failed to open %s./n", poTransfer->GetCATD()->GetModuleFilePath( pszMODN ) ); return; } poPointReader->Rewind();/* -------------------------------------------------------------------- *//* Create the Shapefile. *//* -------------------------------------------------------------------- */ SHPHandle hSHP; hSHP = SHPCreate( pszShapefile, SHPT_POINT ); if( hSHP == NULL ) { fprintf( stderr, "Unable to create shapefile `%s'/n", pszShapefile ); return; }/* -------------------------------------------------------------------- *//* Create the database file, and our basic set of attributes. *//* -------------------------------------------------------------------- */ DBFHandle hDBF; int nAreaField, nSDTSRecordField; char szDBFFilename[1024]; sprintf( szDBFFilename, "%s.dbf", pszShapefile ); hDBF = DBFCreate( szDBFFilename ); if( hDBF == NULL ) { fprintf( stderr, "Unable to create shapefile .dbf for `%s'/n", pszShapefile ); return; } nSDTSRecordField = DBFAddField( hDBF, "SDTSRecId", FTInteger, 8, 0 ); nAreaField = DBFAddField( hDBF, "AreaId", FTString, 12, 0 ); char **papszModRefs = poPointReader->ScanModuleReferences(); AddPrimaryAttrToDBFSchema( hDBF, poTransfer, papszModRefs ); CSLDestroy( papszModRefs );/* ==================================================================== *//* Process all the line features in the module. *//* ==================================================================== */ SDTSRawPoint *poRawPoint; while( (poRawPoint = poPointReader->GetNextPoint()) != NULL ) { int iShape; /* -------------------------------------------------------------------- *//* Write out a shape with the vertices. *//* -------------------------------------------------------------------- */ SHPObject *psShape; psShape = SHPCreateSimpleObject( SHPT_POINT, 1, &(poRawPoint->dfX), &(poRawPoint->dfY), &(poRawPoint->dfZ) ); iShape = SHPWriteObject( hSHP, -1, psShape ); SHPDestroyObject( psShape );/* -------------------------------------------------------------------- *//* Write out the attributes. *//* -------------------------------------------------------------------- */ char szID[13]; DBFWriteIntegerAttribute( hDBF, iShape, nSDTSRecordField, poRawPoint->oModId.nRecord ); sprintf( szID, "%s:%ld", poRawPoint->oAreaId.szModule, poRawPoint->oAreaId.nRecord ); DBFWriteStringAttribute( hDBF, iShape, nAreaField, szID ); WritePrimaryAttrToDBF( hDBF, iShape, poTransfer, poRawPoint ); if( !poPointReader->IsIndexed() ) delete poRawPoint; }/* -------------------------------------------------------------------- *//* Close, and cleanup. *//* -------------------------------------------------------------------- */ DBFClose( hDBF ); SHPClose( hSHP );}
开发者ID:AbdelghaniDr,项目名称:mirror,代码行数:101,
示例26: QgsDebugMsgvoid Builder::print_shpObjects(){ QgsDebugMsg( QString( "Number of primitives: %1" ).arg( shpObjects.size() ) ); QgsDebugMsg( QString( "Number of text fields: %1" ).arg( textObjects.size() ) ); QgsDebugMsg( QString( "Number of inserts fields: %1" ).arg( insertObjects.size() ) ); SHPHandle hSHP; if ( fname.endsWith( ".shp", Qt::CaseInsensitive ) ) { QString fn( fname.mid( fname.length() - 4 ) ); outputdbf = fn + ".dbf"; outputshp = fn + ".shp"; outputtdbf = fn + "_texts.dbf"; outputtshp = fn + "_texts.shp"; outputidbf = fn + "_inserts.dbf"; outputishp = fn + "_inserts.shp"; } else { outputdbf = outputtdbf = outputidbf = fname + ".dbf"; outputshp = outputtshp = outputishp = fname + ".shp"; } DBFHandle dbffile = DBFCreate( outputdbf.toUtf8() ); DBFAddField( dbffile, "myid", FTInteger, 10, 0 ); hSHP = SHPCreate( outputshp.toUtf8(), shapefileType ); QgsDebugMsg( "Writing to main shp file..." ); for ( int i = 0; i < shpObjects.size(); i++ ) { SHPWriteObject( hSHP, -1, shpObjects[i] ); SHPDestroyObject( shpObjects[i] ); DBFWriteIntegerAttribute( dbffile, i, 0, i ); } SHPClose( hSHP ); DBFClose( dbffile ); QgsDebugMsg( "Done!" ); if ( !textObjects.isEmpty() ) { SHPHandle thSHP; DBFHandle Tdbffile = DBFCreate( outputtdbf.toUtf8() ); thSHP = SHPCreate( outputtshp.toUtf8(), SHPT_POINT ); DBFAddField( Tdbffile, "tipx", FTDouble, 20, 10 ); DBFAddField( Tdbffile, "tipy", FTDouble, 20, 10 ); DBFAddField( Tdbffile, "tipz", FTDouble, 20, 10 ); DBFAddField( Tdbffile, "tapx", FTDouble, 20, 10 ); DBFAddField( Tdbffile, "tapy", FTDouble, 20, 10 ); DBFAddField( Tdbffile, "tapz", FTDouble, 20, 10 ); DBFAddField( Tdbffile, "height", FTDouble, 20, 10 ); DBFAddField( Tdbffile, "scale", FTDouble, 20, 10 ); DBFAddField( Tdbffile, "flags", FTInteger, 10, 0 ); DBFAddField( Tdbffile, "hjust", FTInteger, 10, 0 ); DBFAddField( Tdbffile, "vjust", FTInteger, 10, 0 ); DBFAddField( Tdbffile, "text", FTString, 50, 0 ); DBFAddField( Tdbffile, "style", FTString, 50, 0 ); DBFAddField( Tdbffile, "angle", FTDouble, 20, 10 ); QgsDebugMsg( "Writing Texts' shp File..." ); for ( int i = 0; i < textObjects.size(); i++ ) { SHPObject *psObject; double x = textObjects[i].ipx; double y = textObjects[i].ipy; double z = textObjects[i].ipz; psObject = SHPCreateObject( SHPT_POINT, i, 0, NULL, NULL, 1, &x, &y, &z, NULL ); SHPWriteObject( thSHP, -1, psObject ); DBFWriteDoubleAttribute( Tdbffile, i, 0, textObjects[i].ipx ); DBFWriteDoubleAttribute( Tdbffile, i, 1, textObjects[i].ipy ); DBFWriteDoubleAttribute( Tdbffile, i, 2, textObjects[i].ipz ); DBFWriteDoubleAttribute( Tdbffile, i, 3, textObjects[i].apx ); DBFWriteDoubleAttribute( Tdbffile, i, 4, textObjects[i].apy ); DBFWriteDoubleAttribute( Tdbffile, i, 5, textObjects[i].apz ); DBFWriteDoubleAttribute( Tdbffile, i, 6, textObjects[i].height ); DBFWriteDoubleAttribute( Tdbffile, i, 7, textObjects[i].xScaleFactor ); DBFWriteIntegerAttribute( Tdbffile, i, 8, textObjects[i].textGenerationFlags ); DBFWriteIntegerAttribute( Tdbffile, i, 9, textObjects[i].hJustification ); DBFWriteIntegerAttribute( Tdbffile, i, 10, textObjects[i].vJustification ); DBFWriteStringAttribute( Tdbffile, i, 11, textObjects[i].text.c_str() ); DBFWriteStringAttribute( Tdbffile, i, 12, textObjects[i].style.c_str() ); DBFWriteDoubleAttribute( Tdbffile, i, 13, textObjects[i].angle ); SHPDestroyObject( psObject ); }//.........这里部分代码省略.........
开发者ID:stevenmizuno,项目名称:QGIS,代码行数:101,
示例27: WriteAttributeDBFstatic void WriteAttributeDBF( const char * pszShapefile, SDTSTransfer * poTransfer, const char * pszMODN ){ SDTSAttrReader *poAttrReader;/* -------------------------------------------------------------------- *//* Fetch a reference to the indexed Pointgon reader. *//* -------------------------------------------------------------------- */ poAttrReader = (SDTSAttrReader *) poTransfer->GetLayerIndexedReader( poTransfer->FindLayer( pszMODN ) ); if( poAttrReader == NULL ) { fprintf( stderr, "Failed to open %s./n", poTransfer->GetCATD()->GetModuleFilePath( pszMODN ) ); return; } poAttrReader->Rewind();/* -------------------------------------------------------------------- *//* Create the database file, and our basic set of attributes. *//* -------------------------------------------------------------------- */ DBFHandle hDBF; char szDBFFilename[1024]; sprintf( szDBFFilename, "%s.dbf", pszShapefile ); hDBF = DBFCreate( szDBFFilename ); if( hDBF == NULL ) { fprintf( stderr, "Unable to create shapefile .dbf for `%s'/n", pszShapefile ); return; } DBFAddField( hDBF, "SDTSRecId", FTInteger, 8, 0 );/* -------------------------------------------------------------------- *//* Prepare the schema. *//* -------------------------------------------------------------------- */ char **papszMODNList = CSLAddString( NULL, pszMODN ); AddPrimaryAttrToDBFSchema( hDBF, poTransfer, papszMODNList ); CSLDestroy( papszMODNList ); /* ==================================================================== *//* Process all the records in the module. *//* ==================================================================== */ SDTSAttrRecord *poRecord; int iRecord = 0; while((poRecord = (SDTSAttrRecord*)poAttrReader->GetNextFeature()) != NULL) { DBFWriteIntegerAttribute( hDBF, iRecord, 0, poRecord->oModId.nRecord ); WriteAttrRecordToDBF( hDBF, iRecord, poTransfer, poRecord->poATTR ); if( !poAttrReader->IsIndexed() ) delete poRecord; iRecord++; }/* -------------------------------------------------------------------- *//* Close, and cleanup. *//* -------------------------------------------------------------------- */ DBFClose( hDBF );}
开发者ID:AbdelghaniDr,项目名称:mirror,代码行数:73,
示例28: WritePolygonShapefile//.........这里部分代码省略........./* -------------------------------------------------------------------- *//* Fetch a reference to the indexed polygon reader. *//* -------------------------------------------------------------------- */ poPolyReader = (SDTSPolygonReader *) poTransfer->GetLayerIndexedReader( poTransfer->FindLayer( pszMODN ) ); if( poPolyReader == NULL ) { fprintf( stderr, "Failed to open %s./n", poTransfer->GetCATD()->GetModuleFilePath( pszMODN ) ); return; }/* -------------------------------------------------------------------- *//* Assemble polygon geometries from all the line layers. *//* -------------------------------------------------------------------- */ poPolyReader->AssembleRings( poTransfer, poTransfer->FindLayer(pszMODN) ); /* -------------------------------------------------------------------- *//* Create the Shapefile. *//* -------------------------------------------------------------------- */ SHPHandle hSHP; hSHP = SHPCreate( pszShapefile, SHPT_POLYGON ); if( hSHP == NULL ) { fprintf( stderr, "Unable to create shapefile `%s'/n", pszShapefile ); return; }/* -------------------------------------------------------------------- *//* Create the database file, and our basic set of attributes. *//* -------------------------------------------------------------------- */ DBFHandle hDBF; int nSDTSRecordField; char szDBFFilename[1024]; sprintf( szDBFFilename, "%s.dbf", pszShapefile ); hDBF = DBFCreate( szDBFFilename ); if( hDBF == NULL ) { fprintf( stderr, "Unable to create shapefile .dbf for `%s'/n", pszShapefile ); return; } nSDTSRecordField = DBFAddField( hDBF, "SDTSRecId", FTInteger, 8, 0 ); char **papszModRefs = poPolyReader->ScanModuleReferences(); AddPrimaryAttrToDBFSchema( hDBF, poTransfer, papszModRefs ); CSLDestroy( papszModRefs );/* ==================================================================== *//* Process all the polygon features in the module. *//* ==================================================================== */ SDTSRawPolygon *poRawPoly; poPolyReader->Rewind(); while( (poRawPoly = (SDTSRawPolygon *) poPolyReader->GetNextFeature()) != NULL ) { int iShape;/* -------------------------------------------------------------------- *//* Write out a shape with the vertices. *//* -------------------------------------------------------------------- */ SHPObject *psShape; psShape = SHPCreateObject( SHPT_POLYGON, -1, poRawPoly->nRings, poRawPoly->panRingStart, NULL, poRawPoly->nVertices, poRawPoly->padfX, poRawPoly->padfY, poRawPoly->padfZ, NULL ); iShape = SHPWriteObject( hSHP, -1, psShape ); SHPDestroyObject( psShape );/* -------------------------------------------------------------------- *//* Write out the attributes. *//* -------------------------------------------------------------------- */ DBFWriteIntegerAttribute( hDBF, iShape, nSDTSRecordField, poRawPoly->oModId.nRecord ); WritePrimaryAttrToDBF( hDBF, iShape, poTransfer, poRawPoly ); if( !poPolyReader->IsIndexed() ) delete poRawPoly; }/* -------------------------------------------------------------------- *//* Close, and cleanup. *//* -------------------------------------------------------------------- */ DBFClose( hDBF ); SHPClose( hSHP );}
开发者ID:AbdelghaniDr,项目名称:mirror,代码行数:101,
注:本文中的DBFClose函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 C++ DBFETCH函数代码示例 C++ DBDeleteContactSetting函数代码示例 |