/****************************************************************************** * $Id: gdal2ogr.c $ * * Project: GDAL Utilities * Purpose: Create an OGR datasource from the values of a GDAL dataset * May be useful to test gdal_grid and generate its input OGR file * Author: Even Rouault, * ****************************************************************************** * Copyright (c) 2008, Even Rouault * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. ****************************************************************************/ #include "gdal.h" #include "ogr_api.h" #include "ogr_srs_api.h" #include "cpl_string.h" /************************************************************************/ /* Usage() */ /************************************************************************/ void Usage() { int iDriver; int nDriverCount; printf( "Usage: gdal2ogr [--help-general] [-f format_name]\n" " [-b band_number] [-l dest_layer_name]\n" " [-t type]\n" " gdal_datasource_src_name ogr_datasource_dst_name\n" "\n" " -f format_name: output file format name, possible values are:\n"); nDriverCount = OGRGetDriverCount(); for( iDriver = 0; iDriver \n"); fprintf(fOutVRT, " \n", CPLGetBasename(pszDstFilename)); fprintf(fOutVRT, " %s \n", pszDstFilename); fprintf(fOutVRT, " wkbPoint\n"); fprintf(fOutVRT, " \n"); fprintf(fOutVRT, " \n"); fprintf(fOutVRT, "\n"); fclose(fOutVRT); fOutVRT = NULL; } else { OGRSpatialReferenceH hSRS = NULL; const char* pszWkt; hOGRDriver = OGRGetDriverByName(pszFormat); if (hOGRDriver == NULL) { fprintf(stderr, "Can't find OGR driver %s\n", pszFormat); exit(1); } hOGRDS = OGR_Dr_CreateDataSource(hOGRDriver, pszDstFilename, NULL); if (hOGRDS == NULL) { fprintf(stderr, "Can't create OGR datasource %s\n", pszDstFilename); exit(1); } pszWkt = GDALGetProjectionRef(hDS); if (pszWkt && pszWkt[0]) { hSRS = OSRNewSpatialReference(pszWkt); } if (pszLayerName == NULL) pszLayerName = CPLStrdup(CPLGetBasename(pszDstFilename)); hOGRLayer = OGR_DS_CreateLayer( hOGRDS, pszLayerName, hSRS, eType, NULL); if (hSRS) OSRDestroySpatialReference(hSRS); if (hOGRLayer == NULL) { fprintf(stderr, "Can't create layer %s\n", pszLayerName); exit(1); } if (eType != wkbPoint25D) { OGRFieldDefnH hFieldDefn = OGR_Fld_Create( "z", OFTReal ); OGR_L_CreateField(hOGRLayer, hFieldDefn, 0); OGR_Fld_Destroy( hFieldDefn ); } } padfBuffer = (double*)CPLMalloc(nXSize * sizeof(double)); #define GET_X(j, i) adfGeotransform[0] + (j) * adfGeotransform[1] + (i) * adfGeotransform[2] #define GET_Y(j, i) adfGeotransform[3] + (j) * adfGeotransform[4] + (i) * adfGeotransform[5] #define GET_XY(j, i) GET_X(j, i), GET_Y(j, i) /* -------------------------------------------------------------------- */ /* "Translate" the source dataset */ /* -------------------------------------------------------------------- */ for(i=0;i