コード例 #1
0
ファイル: las2ght.c プロジェクト: HydroLogic/libght
static GhtErr
l2g_read_projection(const Las2GhtConfig *config, Las2GhtState *state)
{
    LASSRSH lassrs;    
    char *proj4_input = NULL;
    static char *proj4_output = "+proj=longlat +datum=WGS84 +no_defs";

    assert(state);
    assert(state->header);
    assert(config);


    lassrs = LASHeader_GetSRS(state->header);
    if ( ! lassrs )
    {   
        ght_error("%s: unable to read SRS from LAS header", __func__);
        return GHT_ERROR;
    }

    proj4_input = LASSRS_GetProj4(lassrs);
    if ( ! proj4_input )
    {   
        ght_error("%s: unable to read proj4 string from LAS SRS", __func__);
        return GHT_ERROR;
    }
    
    ght_info("Got LAS file projection information '%s'", proj4_input);

    state->pj_input = l2g_proj_from_string(proj4_input);
    LASString_Free(proj4_input);
    
    if ( ! state->pj_input )
    {
        ght_error("%s: unable to parse proj4 string '%s'", __func__, proj4_input);
        return GHT_ERROR;
    }

    state->pj_output = l2g_proj_from_string(proj4_output);
    if ( ! state->pj_output )
    {
        ght_error("%s: unable to parse proj4 string '%s'", __func__, proj4_input);
        return GHT_ERROR;
    }
    
    return GHT_OK;
}
コード例 #2
0
void usage()
{
    char* version = LAS_GetFullVersion();
    fprintf(stderr,"----------------------------------------------------------\n");
    fprintf(stderr,"    lasinfo-old (version %s) usage:\n", version);
    fprintf(stderr,"----------------------------------------------------------\n");
    fprintf(stderr,"\n");
    LASString_Free(version);
    version = NULL;

    fprintf(stderr,"Printing simple header info:\n");
    fprintf(stderr,"  lasinfo-old lidar.las\n");
    fprintf(stderr,"\n");

    fprintf(stderr,"Checking point information:\n");
    fprintf(stderr,"  lasinfo-old --input lidar.las --check\n");
    fprintf(stderr,"\n");

    fprintf(stderr,"Print header info and point summary and redirect output to a file:\n");
    fprintf(stderr,"  lasinfo-old --check --input lidar.las 2> output.txt\n");
    fprintf(stderr,"\n");

    fprintf(stderr,"Read from stdin, scan the points, and skip printing VLR info:\n");
    fprintf(stderr,"  lasinfo-old --stdin --check --skip_vlr < lidar.las\n");
    fprintf(stderr,"\n");

    fprintf(stderr,"Repairing header info to reflect point data:\n");
    fprintf(stderr,"  lasinfo-old -i lidar.las --repair\n");
    fprintf(stderr,"\n");

    fprintf(stderr,"Altering header info:\n");
    fprintf(stderr, "  lasinfo-old -i lidar.las --system_identifier \"hello world!\" "
                    "--generating_software \"this is a test (-:\"  --file_creation 8 2007\n");
    fprintf(stderr,"\n");

    fprintf(stderr,"Print this output:\n");
    fprintf(stderr, "  lasinfo-old --help\n");
    fprintf(stderr,"\n");

    fprintf(stderr, "\nFor more information, see the full documentation for lasinfo-old at:\n"
                    " http://liblas.org/utilities/lasinfo-old.html\n");
    fprintf(stderr,"----------------------------------------------------------\n");
}
コード例 #3
0
ファイル: lasreader_mex.c プロジェクト: joa-quim/mirone
/* ---------------------------------------------------------------------------------- */
void print_header(LASHeaderH header, int bSkipVLR) {

    char *pszSignature = NULL;
    char *pszProjectId = NULL;
    char *pszSystemId = NULL;
    char *pszSoftwareId = NULL;
    /*char *pszProj4 = NULL;*/
    
    char *pszVLRUser = NULL;
    char *pszVLRDescription = NULL;
    uint16_t nVLRLength = 0;
    uint16_t nVLRRecordId = 0;
    
    LASVLRH pVLR = NULL;
    LASSRSH pSRS = NULL;
    uint32_t nVLR = 0;
    int i = 0;

#ifdef HAVE_GEOTIFF
    const GTIF* pGTIF = NULL;
#else
    const void* pGTIF = NULL;
#endif    

    pszSignature = LASHeader_GetFileSignature(header);
    pszProjectId = LASHeader_GetProjectId(header);
    pszSystemId = LASHeader_GetSystemId(header);
    pszSoftwareId = LASHeader_GetSoftwareId(header);
    
    pSRS = LASHeader_GetSRS(header);
    /*pszProj4 = LASSRS_GetProj4(pSRS);*/
    pGTIF = LASSRS_GetGTIF(pSRS);
    
    nVLR = LASHeader_GetRecordsCount(header);
 
    mexPrintf("\n---------------------------------------------------------\n");
    mexPrintf("  Header Summary\n");
    mexPrintf("---------------------------------------------------------\n");

    if (strcmp(pszSignature,"LASF") !=0) {
        LASError_Print("File signature is not 'LASF'... aborting");
        return;
    }
    mexPrintf("  Version:                    %d.%d\n", 
                    LASHeader_GetVersionMajor(header), LASHeader_GetVersionMinor(header));

    mexPrintf("  Source ID:                  %d\n", LASHeader_GetFileSourceId(header) ) ;
    mexPrintf("  Reserved:                   %d\n", LASHeader_GetReserved(header) );
    mexPrintf("  Project ID/GUID:           '%s'\n", pszProjectId);
    mexPrintf("  System Identifier:         '%s'\n", pszSystemId);
    mexPrintf("  Generating Software:       '%s'\n", pszSoftwareId);
    mexPrintf("  File Creation Day/Year:    %d/%d\n", 
                    LASHeader_GetCreationDOY(header), LASHeader_GetCreationYear(header));

    mexPrintf("  Header Size                %d\n", LASHeader_GetHeaderSize(header));
    mexPrintf("  Offset to Point Data       %d\n", LASHeader_GetDataOffset(header));
    mexPrintf("  Number Var. Length Records %d\n", LASHeader_GetRecordsCount(header));
    mexPrintf("  Point Data Format          %d\n", LASHeader_GetDataFormatId(header));
    mexPrintf("  Point Data Record Length   %d\n", LASHeader_GetDataRecordLength(header));
    mexPrintf("  Number of Point Records    %d\n", LASHeader_GetPointRecordsCount(header));
    mexPrintf("  Number of Points by Return %d %d %d %d %d\n", 
                    LASHeader_GetPointRecordsByReturnCount(header, 0), 
                    LASHeader_GetPointRecordsByReturnCount(header, 1), 
                    LASHeader_GetPointRecordsByReturnCount(header, 2), 
                    LASHeader_GetPointRecordsByReturnCount(header, 3), 
                    LASHeader_GetPointRecordsByReturnCount(header, 4));

    mexPrintf("  Scale Factor X Y Z         %.6g %.6g %.6g\n", 
                    LASHeader_GetScaleX(header), 
                    LASHeader_GetScaleY(header),
                    LASHeader_GetScaleZ(header));

    mexPrintf("  Offset X Y Z               %.6f %.6f %.6f\n", 
                    LASHeader_GetOffsetX(header), 
                    LASHeader_GetOffsetY(header), 
                    LASHeader_GetOffsetZ(header));

    mexPrintf("  Min X Y Z                  %.6f %.6f %.6f\n",
                    LASHeader_GetMinX(header), 
                    LASHeader_GetMinY(header), 
                    LASHeader_GetMinZ(header));

    mexPrintf("  Max X Y Z                  %.6f %.6f %.6f\n", 
                    LASHeader_GetMaxX(header), 
                    LASHeader_GetMaxY(header), 
                    LASHeader_GetMaxZ(header));
    
    /*mexPrintf(" Spatial Reference           %s\n", pszProj4);*/
#ifdef HAVE_LIBGEOTIFF
    if (pGTIF) GTIFPrint((GTIF*)pGTIF, 0, 0);
#endif
    if (nVLR && !bSkipVLR) {
        
    mexPrintf("\n---------------------------------------------------------\n");
    mexPrintf("  VLR Summary\n");
    mexPrintf("---------------------------------------------------------\n");

        for (i = 0; i < (int)nVLR; i++) {
            pVLR = LASHeader_GetVLR(header, i);

            if (LASError_GetLastErrorNum()) {
                LASError_Print("Unable to fetch VLR");
                return;
            }
            
            pszVLRUser = LASVLR_GetUserId(pVLR);
            pszVLRDescription = LASVLR_GetDescription(pVLR);
            nVLRLength = LASVLR_GetRecordLength(pVLR);
            nVLRRecordId = LASVLR_GetRecordId(pVLR);
            
            mexPrintf("   User: '******' - Description: '%s'\n", pszVLRUser, pszVLRDescription);
            mexPrintf("   ID: %d Length: %d\n\n", nVLRRecordId, nVLRLength);
            
            LASVLR_Destroy(pVLR);
            pVLR = NULL;
            
            LASString_Free(pszVLRUser);
            LASString_Free(pszVLRDescription);
        }
        
    }
    LASString_Free(pszSignature);
    LASString_Free(pszProjectId);
    LASString_Free(pszSystemId);
    LASString_Free(pszSoftwareId);
    /*LASString_Free(pszProj4);*/
}
コード例 #4
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;
}