/* **************************************************************************** * $Id$ * * Project: GdalExtractProfile * Purpose: Extract Profile from a Raster file for an Input Geometry (LINE) * Author: GĂ©rald Fenoy, gerald.fenoy@geolabs.fr * * **************************************************************************** * Copyright (c) 2010-2011, GeoLabs SARL * * 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. ****************************************************************************/ #ifdef ZOO_SERVICE #include "service.h" #include "service_internal.h" #endif #include "gdal.h" #include "cpl_conv.h" #include "ogr_api.h" #ifdef ZOO_SERVICE extern "C" { #endif #ifdef WIN32 __declspec(dllexport) #endif #ifdef ZOO_SERVICE int GdalExtractProfile(maps*& conf,maps*& inputs,maps*& outputs) #else int main(int argc,char** argv) #endif { char *pszFilename; #ifdef ZOO_SERVICE map* tmp=NULL; map* tmp1=NULL; tmp=getMapFromMaps(conf,"main","dataPath"); tmp1=getMapFromMaps(inputs,"RasterFile","value"); pszFilename=(char *)malloc((2+strlen(tmp->value)+strlen(tmp1->value))*sizeof(char)); sprintf(pszFilename,"%s/%s",tmp->value,tmp1->value); #else pszFilename=argv[1]; #endif GDALDatasetH hDataset; GDALAllRegister(); OGRRegisterAll(); hDataset = GDALOpen( pszFilename, GA_ReadOnly ); free(pszFilename); if( hDataset != NULL ) { GDALDriverH hDriver; double adfGeoTransform[6]; if( GDALGetGeoTransform( hDataset, adfGeoTransform ) == CE_None ) { GDALRasterBandH hBand; int nBlockXSize, nBlockYSize; int bGotMin, bGotMax; double adfMinMax[2]; hBand = GDALGetRasterBand( hDataset, 1 ); adfMinMax[0] = GDALGetRasterMinimum( hBand, &bGotMin ); adfMinMax[1] = GDALGetRasterMaximum( hBand, &bGotMax ); if( ! (bGotMin && bGotMax) ) GDALComputeRasterMinMax( hBand, TRUE, adfMinMax ); #ifdef ZOO_SERVICE tmp1=getMapFromMaps(inputs,"Geometry","value"); OGRGeometryH geometry=OGR_G_CreateGeometryFromJson(tmp1->value); #else OGRGeometryH geometry=OGR_G_CreateGeometryFromJson(argv[2]); #endif OGR_G_Segmentize(geometry, adfGeoTransform[1]); int nbGeom=OGR_G_GetPointCount(geometry); int k=0; double ppx=0,ppy=0; double value; char *buffer=NULL; int length=0; buffer=(char*)malloc(37*sizeof(char)); sprintf(buffer,"{\"type\":\"LineString\",\"coordinates\":["); length+=strlen(buffer); for(k=0;k