/* postgis.gdal_datapath */ static void rtpg_assignHookGDALDataPath(const char *newpath, void *extra) { POSTGIS_RT_DEBUGF(4, "newpath = %s", newpath); POSTGIS_RT_DEBUGF(4, "gdaldatapath = %s", gdal_datapath); /* clear finder cache */ CPLFinderClean(); /* clear cached OSR */ OSRCleanup(); /* set GDAL_DATA */ CPLSetConfigOption("GDAL_DATA", newpath); POSTGIS_RT_DEBUGF(4, "GDAL_DATA = %s", CPLGetConfigOption("GDAL_DATA", "")); }
int main( int nArgc, char ** papszArgv ) { NITFFile *psFile; int iSegment, iFile; char szTemp[100]; int bDisplayTRE = FALSE; int bExtractSHP = FALSE, bExtractSHPInMem = FALSE; if( nArgc < 2 ) { printf( "Usage: nitfdump [-tre] [-extractshp | -extractshpinmem] <nitf_filename>*\n" ); exit( 1 ); } for( iFile = 1; iFile < nArgc; iFile++ ) { if ( EQUAL(papszArgv[iFile], "-tre") ) bDisplayTRE = TRUE; else if ( EQUAL(papszArgv[iFile], "-extractshp") ) bExtractSHP = TRUE; else if ( EQUAL(papszArgv[iFile], "-extractshpinmem") ) { bExtractSHP = TRUE; bExtractSHPInMem = TRUE; } } /* ==================================================================== */ /* Loop over all files. */ /* ==================================================================== */ for( iFile = 1; iFile < nArgc; iFile++ ) { int bHasFoundLocationTable = FALSE; if ( EQUAL(papszArgv[iFile], "-tre") ) continue; if ( EQUAL(papszArgv[iFile], "-extractshp") ) continue; if ( EQUAL(papszArgv[iFile], "-extractshpinmem") ) continue; /* -------------------------------------------------------------------- */ /* Open the file. */ /* -------------------------------------------------------------------- */ psFile = NITFOpen( papszArgv[iFile], FALSE ); if( psFile == NULL ) exit( 2 ); printf( "Dump for %s\n", papszArgv[iFile] ); /* -------------------------------------------------------------------- */ /* Dump first TRE list. */ /* -------------------------------------------------------------------- */ if( psFile->pachTRE != NULL ) { int nTREBytes = psFile->nTREBytes; const char *pszTREData = psFile->pachTRE; printf( "File TREs:" ); while( nTREBytes > 10 ) { int nThisTRESize = atoi(NITFGetField(szTemp, pszTREData, 6, 5 )); if (nThisTRESize < 0 || nThisTRESize > nTREBytes - 11) { NITFGetField(szTemp, pszTREData, 0, 6 ); printf(" Invalid size (%d) for TRE %s", nThisTRESize, szTemp); break; } printf( " %6.6s(%d)", pszTREData, nThisTRESize ); pszTREData += nThisTRESize + 11; nTREBytes -= (nThisTRESize + 11); } printf( "\n" ); if (bDisplayTRE) { nTREBytes = psFile->nTREBytes; pszTREData = psFile->pachTRE; while( nTREBytes > 10 ) { char *pszEscaped; int nThisTRESize = atoi(NITFGetField(szTemp, pszTREData, 6, 5 )); if (nThisTRESize < 0 || nThisTRESize > nTREBytes - 11) { break; } pszEscaped = CPLEscapeString( pszTREData + 11, nThisTRESize, CPLES_BackslashQuotable ); printf( "TRE '%6.6s' : %s\n", pszTREData, pszEscaped); CPLFree(pszEscaped); pszTREData += nThisTRESize + 11; nTREBytes -= (nThisTRESize + 11); } } } /* -------------------------------------------------------------------- */ /* Dump Metadata */ /* -------------------------------------------------------------------- */ DumpMetadata( "File Metadata:", " ", psFile->papszMetadata ); /* -------------------------------------------------------------------- */ /* Dump general info about segments. */ /* -------------------------------------------------------------------- */ NITFCollectAttachments( psFile ); NITFReconcileAttachments( psFile ); for( iSegment = 0; iSegment < psFile->nSegmentCount; iSegment++ ) { NITFSegmentInfo *psSegInfo = psFile->pasSegmentInfo + iSegment; printf( "Segment %d (Type=%s):\n", iSegment + 1, psSegInfo->szSegmentType ); printf( " HeaderStart=" CPL_FRMT_GUIB ", HeaderSize=%u, DataStart=" CPL_FRMT_GUIB ", DataSize=" CPL_FRMT_GUIB "\n", psSegInfo->nSegmentHeaderStart, psSegInfo->nSegmentHeaderSize, psSegInfo->nSegmentStart, psSegInfo->nSegmentSize ); printf( " DLVL=%d, ALVL=%d, LOC=C%d,R%d, CCS=C%d,R%d\n", psSegInfo->nDLVL, psSegInfo->nALVL, psSegInfo->nLOC_C, psSegInfo->nLOC_R, psSegInfo->nCCS_C, psSegInfo->nCCS_R ); printf( "\n" ); } /* -------------------------------------------------------------------- */ /* Report details of images. */ /* -------------------------------------------------------------------- */ for( iSegment = 0; iSegment < psFile->nSegmentCount; iSegment++ ) { NITFSegmentInfo *psSegInfo = psFile->pasSegmentInfo + iSegment; NITFImage *psImage; NITFRPC00BInfo sRPCInfo; int iBand; char **papszMD; if( !EQUAL(psSegInfo->szSegmentType,"IM") ) continue; psImage = NITFImageAccess( psFile, iSegment ); if( psImage == NULL ) { printf( "NITFAccessImage(%d) failed!\n", iSegment ); continue; } printf( "Image Segment %d, %dPx%dLx%dB x %dbits:\n", iSegment + 1, psImage->nCols, psImage->nRows, psImage->nBands, psImage->nBitsPerSample ); printf( " PVTYPE=%s, IREP=%s, ICAT=%s, IMODE=%c, IC=%s, COMRAT=%s, ICORDS=%c\n", psImage->szPVType, psImage->szIREP, psImage->szICAT, psImage->chIMODE, psImage->szIC, psImage->szCOMRAT, psImage->chICORDS ); if( psImage->chICORDS != ' ' ) { printf( " UL=(%.15g,%.15g), UR=(%.15g,%.15g) Center=%d\n LL=(%.15g,%.15g), LR=(%.15g,%.15g)\n", psImage->dfULX, psImage->dfULY, psImage->dfURX, psImage->dfURY, psImage->bIsBoxCenterOfPixel, psImage->dfLLX, psImage->dfLLY, psImage->dfLRX, psImage->dfLRY ); } printf( " IDLVL=%d, IALVL=%d, ILOC R=%d,C=%d, IMAG=%s\n", psImage->nIDLVL, psImage->nIALVL, psImage->nILOCRow, psImage->nILOCColumn, psImage->szIMAG ); printf( " %d x %d blocks of size %d x %d\n", psImage->nBlocksPerRow, psImage->nBlocksPerColumn, psImage->nBlockWidth, psImage->nBlockHeight ); if( psImage->pachTRE != NULL ) { int nTREBytes = psImage->nTREBytes; const char *pszTREData = psImage->pachTRE; printf( " Image TREs:" ); while( nTREBytes > 10 ) { int nThisTRESize = atoi(NITFGetField(szTemp, pszTREData, 6, 5 )); if (nThisTRESize < 0 || nThisTRESize > nTREBytes - 11) { NITFGetField(szTemp, pszTREData, 0, 6 ); printf(" Invalid size (%d) for TRE %s", nThisTRESize, szTemp); break; } printf( " %6.6s(%d)", pszTREData, nThisTRESize ); pszTREData += nThisTRESize + 11; nTREBytes -= (nThisTRESize + 11); } printf( "\n" ); if (bDisplayTRE) { nTREBytes = psImage->nTREBytes; pszTREData = psImage->pachTRE; while( nTREBytes > 10 ) { char *pszEscaped; int nThisTRESize = atoi(NITFGetField(szTemp, pszTREData, 6, 5 )); if (nThisTRESize < 0 || nThisTRESize > nTREBytes - 11) { break; } pszEscaped = CPLEscapeString( pszTREData + 11, nThisTRESize, CPLES_BackslashQuotable ); printf( " TRE '%6.6s' : %s\n", pszTREData, pszEscaped); CPLFree(pszEscaped); pszTREData += nThisTRESize + 11; nTREBytes -= (nThisTRESize + 11); } } } /* Report info from location table, if found. */ if( psImage->nLocCount > 0 ) { int i; bHasFoundLocationTable = TRUE; printf( " Location Table\n" ); for( i = 0; i < psImage->nLocCount; i++ ) { printf( " LocName=%s, LocId=%d, Offset=%d, Size=%d\n", GetLocationNameFromId(psImage->pasLocations[i].nLocId), psImage->pasLocations[i].nLocId, psImage->pasLocations[i].nLocOffset, psImage->pasLocations[i].nLocSize ); } printf( "\n" ); } if( strlen(psImage->pszComments) > 0 ) printf( " Comments:\n%s\n", psImage->pszComments ); for( iBand = 0; iBand < psImage->nBands; iBand++ ) { NITFBandInfo *psBandInfo = psImage->pasBandInfo + iBand; printf( " Band %d: IREPBAND=%s, ISUBCAT=%s, %d LUT entries.\n", iBand + 1, psBandInfo->szIREPBAND, psBandInfo->szISUBCAT, psBandInfo->nSignificantLUTEntries ); } if( NITFReadRPC00B( psImage, &sRPCInfo ) ) { DumpRPC( psImage, &sRPCInfo ); } papszMD = NITFReadUSE00A( psImage ); if( papszMD != NULL ) { DumpMetadata( " USE00A TRE:", " ", papszMD ); CSLDestroy( papszMD ); } papszMD = NITFReadBLOCKA( psImage ); if( papszMD != NULL ) { DumpMetadata( " BLOCKA TRE:", " ", papszMD ); CSLDestroy( papszMD ); } papszMD = NITFReadSTDIDC( psImage ); if( papszMD != NULL ) { DumpMetadata( " STDIDC TRE:", " ", papszMD ); CSLDestroy( papszMD ); } DumpMetadata( " Image Metadata:", " ", psImage->papszMetadata ); printf("\n"); } /* ==================================================================== */ /* Report details of graphic segments. */ /* ==================================================================== */ for( iSegment = 0; iSegment < psFile->nSegmentCount; iSegment++ ) { NITFSegmentInfo *psSegInfo = psFile->pasSegmentInfo + iSegment; char achSubheader[298]; int nSTYPEOffset; if( !EQUAL(psSegInfo->szSegmentType,"GR") && !EQUAL(psSegInfo->szSegmentType,"SY") ) continue; /* -------------------------------------------------------------------- */ /* Load the graphic subheader. */ /* -------------------------------------------------------------------- */ if( VSIFSeekL( psFile->fp, psSegInfo->nSegmentHeaderStart, SEEK_SET ) != 0 || VSIFReadL( achSubheader, 1, sizeof(achSubheader), psFile->fp ) < 258 ) { CPLError( CE_Warning, CPLE_FileIO, "Failed to read graphic subheader at " CPL_FRMT_GUIB ".", psSegInfo->nSegmentHeaderStart ); continue; } // NITF 2.0. (also works for NITF 2.1) nSTYPEOffset = 200; if( STARTS_WITH_CI(achSubheader+193, "999998") ) nSTYPEOffset += 40; /* -------------------------------------------------------------------- */ /* Report some standard info. */ /* -------------------------------------------------------------------- */ printf( "Graphic Segment %d, type=%2.2s, sfmt=%c, sid=%10.10s\n", iSegment + 1, achSubheader + 0, achSubheader[nSTYPEOffset], achSubheader + 2 ); printf( " sname=%20.20s\n", achSubheader + 12 ); printf("\n"); } /* ==================================================================== */ /* Report details of text segments. */ /* ==================================================================== */ for( iSegment = 0; iSegment < psFile->nSegmentCount; iSegment++ ) { char *pabyHeaderData; char *pabyTextData; NITFSegmentInfo *psSegment = psFile->pasSegmentInfo + iSegment; if( !EQUAL(psSegment->szSegmentType,"TX") ) continue; printf( "Text Segment %d\n", iSegment + 1); /* -------------------------------------------------------------------- */ /* Load the text header */ /* -------------------------------------------------------------------- */ /* Allocate one extra byte for the NULL terminating character */ pabyHeaderData = (char *) CPLCalloc(1, (size_t) psSegment->nSegmentHeaderSize + 1); if (VSIFSeekL(psFile->fp, psSegment->nSegmentHeaderStart, SEEK_SET) != 0 || VSIFReadL(pabyHeaderData, 1, (size_t) psSegment->nSegmentHeaderSize, psFile->fp) != psSegment->nSegmentHeaderSize) { CPLError( CE_Warning, CPLE_FileIO, "Failed to read %d bytes of text header data at " CPL_FRMT_GUIB ".", psSegment->nSegmentHeaderSize, psSegment->nSegmentHeaderStart); CPLFree(pabyHeaderData); continue; } printf(" Header : %s\n", pabyHeaderData); CPLFree(pabyHeaderData); /* -------------------------------------------------------------------- */ /* Load the raw TEXT data itself. */ /* -------------------------------------------------------------------- */ /* Allocate one extra byte for the NULL terminating character */ pabyTextData = (char *) CPLCalloc(1,(size_t)psSegment->nSegmentSize+1); if( VSIFSeekL( psFile->fp, psSegment->nSegmentStart, SEEK_SET ) != 0 || VSIFReadL( pabyTextData, 1, (size_t)psSegment->nSegmentSize, psFile->fp ) != psSegment->nSegmentSize ) { CPLError( CE_Warning, CPLE_FileIO, "Failed to read " CPL_FRMT_GUIB " bytes of text data at " CPL_FRMT_GUIB ".", psSegment->nSegmentSize, psSegment->nSegmentStart ); CPLFree( pabyTextData ); continue; } printf(" Data : %s\n", pabyTextData); printf("\n"); CPLFree( pabyTextData ); } /* -------------------------------------------------------------------- */ /* Report details of DES. */ /* -------------------------------------------------------------------- */ for( iSegment = 0; iSegment < psFile->nSegmentCount; iSegment++ ) { NITFSegmentInfo *psSegInfo = psFile->pasSegmentInfo + iSegment; NITFDES *psDES; int nOffset = 0; char szTREName[7]; int nThisTRESize; int nRPFDESOffset = -1; if( !EQUAL(psSegInfo->szSegmentType,"DE") ) continue; psDES = NITFDESAccess( psFile, iSegment ); if( psDES == NULL ) { printf( "NITFDESAccess(%d) failed!\n", iSegment ); continue; } printf( "DE Segment %d:\n", iSegment + 1 ); printf( " Segment TREs:" ); nOffset = 0; while (NITFDESGetTRE( psDES, nOffset, szTREName, NULL, &nThisTRESize)) { printf( " %6.6s(%d)", szTREName, nThisTRESize ); if (strcmp(szTREName, "RPFDES") == 0) nRPFDESOffset = nOffset + 11; nOffset += 11 + nThisTRESize; } printf( "\n" ); if (bDisplayTRE) { char* pabyTREData = NULL; nOffset = 0; while (NITFDESGetTRE( psDES, nOffset, szTREName, &pabyTREData, &nThisTRESize)) { char* pszEscaped = CPLEscapeString( pabyTREData, nThisTRESize, CPLES_BackslashQuotable ); printf( " TRE '%6.6s' : %s\n", szTREName, pszEscaped); CPLFree(pszEscaped); nOffset += 11 + nThisTRESize; NITFDESFreeTREData(pabyTREData); } } /* Report info from location table, if found. */ if( !bHasFoundLocationTable && nRPFDESOffset >= 0 ) { int i; int nLocCount = 0; NITFLocation* pasLocations; VSIFSeekL(psFile->fp, psSegInfo->nSegmentStart + nRPFDESOffset, SEEK_SET); pasLocations = NITFReadRPFLocationTable(psFile->fp, &nLocCount); if (pasLocations) { printf( " Location Table\n" ); for( i = 0; i < nLocCount; i++ ) { printf( " LocName=%s, LocId=%d, Offset=%d, Size=%d\n", GetLocationNameFromId(pasLocations[i].nLocId), pasLocations[i].nLocId, pasLocations[i].nLocOffset, pasLocations[i].nLocSize ); } CPLFree(pasLocations); printf( "\n" ); } } DumpMetadata( " DES Metadata:", " ", psDES->papszMetadata ); if ( bExtractSHP && CSLFetchNameValue(psDES->papszMetadata, "NITF_SHAPE_USE") != NULL ) { char szFilename[32]; char szRadix[32]; if (bExtractSHPInMem) snprintf(szRadix, sizeof(szRadix), "/vsimem/nitf_segment_%d", iSegment + 1); else snprintf(szRadix, sizeof(szRadix), "nitf_segment_%d", iSegment + 1); if (NITFDESExtractShapefile(psDES, szRadix)) { OGRDataSourceH hDS; OGRRegisterAll(); snprintf(szFilename, sizeof(szFilename), "%s.SHP", szRadix); hDS = OGROpen(szFilename, FALSE, NULL); if (hDS) { int nGeom = 0; OGRLayerH hLayer = OGR_DS_GetLayer(hDS, 0); if (hLayer) { OGRFeatureH hFeat; printf("\n"); while ( (hFeat = OGR_L_GetNextFeature(hLayer)) != NULL ) { OGRGeometryH hGeom = OGR_F_GetGeometryRef(hFeat); if (hGeom) { char* pszWKT = NULL; OGR_G_ExportToWkt(hGeom, &pszWKT); if (pszWKT) printf(" Geometry %d : %s\n", nGeom ++, pszWKT); CPLFree(pszWKT); } OGR_F_Destroy(hFeat); } } OGR_DS_Destroy(hDS); } } if (bExtractSHPInMem) { snprintf(szFilename, sizeof(szFilename), "%s.SHP", szRadix); VSIUnlink(szFilename); snprintf(szFilename, sizeof(szFilename), "%s.SHX", szRadix); VSIUnlink(szFilename); snprintf(szFilename, sizeof(szFilename), "%s.DBF", szRadix); VSIUnlink(szFilename); } } } /* -------------------------------------------------------------------- */ /* Close. */ /* -------------------------------------------------------------------- */ NITFClose( psFile ); } CPLFinderClean(); CPLCleanupTLS(); VSICleanupFileManager(); OGRCleanupAll(); exit( 0 ); }
int main( int nArgc, char ** papszArgv ) { OGRSpatialReference oSRS; int i; int bReportXML = FALSE; /* -------------------------------------------------------------------- */ /* Processing command line arguments. */ /* -------------------------------------------------------------------- */ nArgc = OGRGeneralCmdLineProcessor( nArgc, &papszArgv, 0 ); if( nArgc < 2 ) Usage(); for( i = 1; i < nArgc; i++ ) { if( EQUAL(papszArgv[i],"-xml") ) bReportXML = TRUE; else if( EQUAL(papszArgv[i],"-t") && i < nArgc - 4 ) { OGRSpatialReference oSourceSRS, oTargetSRS; OGRCoordinateTransformation *poCT; double x, y, z_orig, z; int nArgsUsed = 4; if( oSourceSRS.SetFromUserInput(papszArgv[i+1]) != OGRERR_NONE ) { CPLError( CE_Failure, CPLE_AppDefined, "SetFromUserInput(%s) failed.", papszArgv[i+1] ); continue; } if( oTargetSRS.SetFromUserInput(papszArgv[i+2]) != OGRERR_NONE ) { CPLError( CE_Failure, CPLE_AppDefined, "SetFromUserInput(%s) failed.", papszArgv[i+2] ); continue; } poCT = OGRCreateCoordinateTransformation( &oSourceSRS, &oTargetSRS ); x = CPLAtof( papszArgv[i+3] ); y = CPLAtof( papszArgv[i+4] ); if( i < nArgc - 5 && (CPLAtof(papszArgv[i+5]) > 0.0 || papszArgv[i+5][0] == '0') ) { z_orig = z = CPLAtof(papszArgv[i+5]); nArgsUsed++; } else z_orig = z = 0; if( poCT == NULL || !poCT->Transform( 1, &x, &y, &z ) ) printf( "Transformation failed.\n" ); else printf( "(%f,%f,%f) -> (%f,%f,%f)\n", CPLAtof( papszArgv[i+3] ), CPLAtof( papszArgv[i+4] ), z_orig, x, y, z ); i += nArgsUsed; } else { /* coverity[tainted_data] */ if( oSRS.SetFromUserInput(papszArgv[i]) != OGRERR_NONE ) CPLError( CE_Failure, CPLE_AppDefined, "Error occurred translating %s.\n", papszArgv[i] ); else { char *pszWKT = NULL; if( oSRS.Validate() != OGRERR_NONE ) printf( "Validate Fails.\n" ); else printf( "Validate Succeeds.\n" ); oSRS.exportToPrettyWkt( &pszWKT, FALSE ); printf( "WKT[%s] =\n%s\n", papszArgv[i], pszWKT ); CPLFree( pszWKT ); printf( "\n" ); oSRS.exportToPrettyWkt( &pszWKT, TRUE ); printf( "Simplified WKT[%s] =\n%s\n", papszArgv[i], pszWKT ); CPLFree( pszWKT ); printf( "\n" ); OGRSpatialReference *poSRS2; poSRS2 = oSRS.Clone(); poSRS2->StripCTParms(); poSRS2->exportToWkt( &pszWKT ); printf( "Old Style WKT[%s] = %s\n", papszArgv[i], pszWKT ); CPLFree( pszWKT ); OGRSpatialReference::DestroySpatialReference( poSRS2 ); poSRS2 = oSRS.Clone(); poSRS2->morphToESRI(); poSRS2->exportToPrettyWkt( &pszWKT, FALSE ); printf( "ESRI'ified WKT[%s] = \n%s\n", papszArgv[i], pszWKT ); CPLFree( pszWKT ); OGRSpatialReference::DestroySpatialReference( poSRS2 ); oSRS.exportToProj4( &pszWKT ); printf( "PROJ.4 rendering of [%s] = %s\n", papszArgv[i], pszWKT ); CPLFree( pszWKT ); if( bReportXML ) { char *pszRawXML; if( oSRS.exportToXML(&pszRawXML) == OGRERR_NONE ) { printf( "XML[%s] =\n%s\n", papszArgv[i], pszRawXML ); CPLFree( pszRawXML ); } else { printf( "XML translation failed\n" ); } } printf( "\n" ); } } } CSLDestroy( papszArgv ); OSRCleanup(); CPLFinderClean(); CPLCleanupTLS(); return 0; }
int main(int argc, char *argv[]) { int i = 0; char* file_name = NULL; LASReaderH reader = NULL; LASHeaderH header = NULL; LASWriterH writer = NULL; int check_points = FALSE; int repair_header = FALSE; int change_header = FALSE; int repair_bounding_box = FALSE; int use_stdin = FALSE; int update_return_counts = FALSE; int skip_vlr = FALSE; int wkt = FALSE; char *system_identifier = NULL; char *generating_software = NULL; unsigned char file_creation_day = 0; unsigned char file_creation_year = 0; int err = 0; LASPointSummary* summary = NULL; for (i = 1; i < argc; i++) { if (strcmp(argv[i],"-v") == 0 || strcmp(argv[i],"--version") == 0) { char* ver = LAS_GetFullVersion(); fprintf(stderr,"%s", ver); LASString_Free(ver); exit(0); } else if (strcmp(argv[i],"-h") == 0 || strcmp(argv[i],"--help") == 0) { usage(); exit(0); } else if (strcmp(argv[i],"--input") == 0 || strcmp(argv[i],"-input") == 0 || strcmp(argv[i],"-i") == 0 || strcmp(argv[i],"-in") == 0) { i++; file_name = argv[i]; } else if (strcmp(argv[i], "--points") == 0 || strcmp(argv[i], "--check") == 0 || strcmp(argv[i], "--check_points") == 0 || strcmp(argv[i], "-c") == 0 || strcmp(argv[i], "-points") == 0 || strcmp(argv[i], "-check") == 0 || strcmp(argv[i], "-check_points") == 0) { check_points = TRUE; } else if (strcmp(argv[i], "--nocheck") == 0 || strcmp(argv[i], "-nocheck") == 0) { check_points = FALSE; } else if (strcmp(argv[i], "--stdin") == 0 || strcmp(argv[i], "-ilas") == 0) { use_stdin = TRUE; } else if (strcmp(argv[i], "--repair") == 0 || strcmp(argv[i], "-r") == 0 || strcmp(argv[i], "-repair_header") == 0 || strcmp(argv[i], "-repair") == 0) { repair_header = TRUE; check_points = TRUE; } else if (strcmp(argv[i], "--repair_bb") == 0 || strcmp(argv[i], "--repair_bounding_box") == 0 || strcmp(argv[i], "--repair_boundingbox") == 0 || strcmp(argv[i], "-repair_bb") == 0 || strcmp(argv[i], "-repair_bounding_box") == 0 || strcmp(argv[i], "-repair_boundingbox") == 0 || strcmp(argv[i], "-repair") == 0 || strcmp(argv[i], "-rb") == 0) { repair_bounding_box = TRUE; check_points = TRUE; } else if (strcmp(argv[i],"--system_identifier") == 0 || strcmp(argv[i],"-system_identifier") == 0 || strcmp(argv[i],"-s") == 0 || strcmp(argv[i],"-sys_id") == 0) { i++; system_identifier = (char*) malloc(31 * sizeof(char)); strcpy(system_identifier, argv[i]); change_header = TRUE; } else if (strcmp(argv[i],"--generating_software") == 0 || strcmp(argv[i],"-generating_software") == 0 || strcmp(argv[i],"-g") == 0 || strcmp(argv[i],"-gen_soft") == 0) { i++; generating_software = (char*) malloc(31*sizeof(char)); strcpy(generating_software, argv[i]); change_header = TRUE; } else if (strcmp(argv[i],"--file_creation") == 0 || strcmp(argv[i],"-file_creation") == 0) { /* XXX - mloskot: Consider replacing atoi with strtol, see http://www.iso-9899.info/wiki/Converting */ i++; file_creation_day = (unsigned char)atoi(argv[i]); i++; file_creation_year = (unsigned char)atoi(argv[i]); change_header = TRUE; } else if (strcmp(argv[i],"--skip_vlr") == 0 || strcmp(argv[i],"--no_vlr") == 0) { skip_vlr = TRUE; } else if (strcmp(argv[i],"--wkt") == 0) { wkt = TRUE; } else if (file_name == NULL) { file_name = argv[i]; } else { usage(); fprintf(stderr, "ERROR: unknown argument '%s'\n",argv[i]); exit(1); } } if (use_stdin) { file_name = "stdin"; } if (!file_name) { LASError_Print("No filename was provided to be opened"); usage(); exit(1); } reader = LASReader_Create(file_name); if (!reader) { LASError_Print("Could not open file "); exit(1); } header = LASReader_GetHeader(reader); if (!header) { LASError_Print("Could not get LASHeader "); exit(1); } print_header(stdout, header, file_name, skip_vlr, wkt); if (change_header) { if (system_identifier) { err = LASHeader_SetSystemId (header, system_identifier); if (err) LASError_Print("Could not set SystemId"); } if (generating_software) { err = LASHeader_SetSoftwareId(header, generating_software); if (err) LASError_Print("Could not set SoftwareId"); } if ( file_creation_day || file_creation_year) { err = LASHeader_SetCreationDOY(header, file_creation_day); if (err) LASError_Print("Could not set file creation day"); err = LASHeader_SetCreationYear(header, file_creation_year); if (err) LASError_Print("Could not set file creation year"); } /* We need to wipe out the reader and make a writer. */ if (reader) { LASReader_Destroy(reader); reader = NULL; } writer = LASWriter_Create(file_name, header, LAS_MODE_APPEND); if (!writer) { LASError_Print("Problem creating LASWriterH object"); LASHeader_Destroy(header); header = NULL; exit(1); } if (writer) LASWriter_Destroy(writer); writer = NULL; if (header) LASHeader_Destroy(header); header = NULL; } if (check_points) { if (!reader) { reader = LASReader_Create(file_name); if (!reader) { LASError_Print("Could not open file "); exit(1); } } if (! header) { header = LASReader_GetHeader(reader); if (!header) { LASError_Print("Could not get LASHeader "); exit(1); } } if (!summary) summary = SummarizePoints(reader); print_point_summary(stdout, summary, header); if (repair_header) { fprintf(stdout, "\n---------------------------------------------------------\n"); fprintf(stdout, " Repair Summary\n"); fprintf(stdout, "---------------------------------------------------------\n"); if (use_stdin) { LASError_Print("Cannot update header information on piped input!"); exit(1); } if (! header) { header = LASReader_GetHeader(reader); if (!header) { LASError_Print("Could not get LASHeader "); exit(1); } } if (! repair_bounding_box) { if ( LASHeader_GetMinX(header) != LASPoint_GetX(summary->pmin) ) repair_bounding_box = TRUE; if ( LASHeader_GetMinY(header) != LASPoint_GetY(summary->pmin) ) repair_bounding_box = TRUE; if ( LASHeader_GetMinZ(header) != LASPoint_GetZ(summary->pmin) ) repair_bounding_box = TRUE; if ( LASHeader_GetMaxX(header) != LASPoint_GetX(summary->pmax) ) repair_bounding_box = TRUE; if ( LASHeader_GetMaxY(header) != LASPoint_GetY(summary->pmax) ) repair_bounding_box = TRUE; if ( LASHeader_GetMaxZ(header) != LASPoint_GetZ(summary->pmax) ) repair_bounding_box = TRUE; } if (repair_bounding_box) { fprintf(stdout, " Reparing Bounding Box...\n"); err = LASHeader_SetMin( header, LASPoint_GetX(summary->pmin), LASPoint_GetY(summary->pmin), LASPoint_GetZ(summary->pmin) ); if (err) { LASError_Print("Could not set minimum for header "); exit(1); } err = LASHeader_SetMax( header, LASPoint_GetX(summary->pmax), LASPoint_GetY(summary->pmax), LASPoint_GetZ(summary->pmax) ); if (err) { LASError_Print("Could not set minimum for header "); exit(1); } } for (i = 0; i < 5; i++) { if (LASHeader_GetPointRecordsByReturnCount(header, i) != summary->number_of_points_by_return[i]) { update_return_counts = TRUE; break; } } if (update_return_counts) { fprintf(stdout, " Reparing Point Count by Return...\n"); for (i = 0; i < 5; i++) { LASHeader_SetPointRecordsByReturnCount( header, i, summary->number_of_points_by_return[i]); } } if (reader) { LASReader_Destroy(reader); reader = NULL; } writer = LASWriter_Create(file_name, header, LAS_MODE_APPEND); if (!writer) { LASError_Print("Problem creating LASWriterH object for append"); LASHeader_Destroy(header); header = NULL; exit(1); } LASWriter_Destroy(writer); writer = NULL; LASHeader_Destroy(header); header = NULL; } if (summary) { LASPoint_Destroy(summary->pmin); LASPoint_Destroy(summary->pmax); free(summary); } } if (reader) LASReader_Destroy(reader); if (header) LASHeader_Destroy(header); #ifdef HAVE_GDAL /* Various GDAL related cleanups */ #ifdef OSRCleanup OSRCleanup(); #endif CPLFinderClean(); CPLFreeConfig(); CPLCleanupTLS(); #endif return 0; }