source: trunk/zoo-project/zoo-services/cgal/cgal_service.c @ 795

Last change on this file since 795 was 775, checked in by djay, 9 years ago

Add GDAL 2 support to the cgal services. Updadte otb support to build against OTB 5.4.

File size: 3.3 KB
RevLine 
[469]1/**
2 * Author : Gérald FENOY
3 *
4 * Copyright 2009-2013 GeoLabs SARL. All rights reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 */
24#include "cgal_service.h"
25
26int parseInput(maps* conf,maps* inputs, std::vector<Point>* points,char* filename){
27  map* tmpm=NULL;
28  tmpm=getMapFromMaps(inputs,"InputPoints","value");
29  VSILFILE *ifile=VSIFileFromMemBuffer(filename,(GByte*)tmpm->value,strlen(tmpm->value),FALSE);
30  VSIFCloseL(ifile);
[775]31#if GDAL_VERSION_MAJOR >= 2
32  GDALDataset *ipoDS =
33    (GDALDataset*) GDALOpenEx( filename,
34                               GDAL_OF_READONLY | GDAL_OF_VECTOR,
35                               NULL, NULL, NULL );
36#else
[469]37  OGRDataSource* ipoDS = OGRSFDriverRegistrar::Open(filename,FALSE);
[775]38#endif
[469]39  if( ipoDS == NULL )
40    {
[775]41#if GDAL_VERSION_MAJOR >= 2
42      GDALDriverManager* poR=GetGDALDriverManager();
43#else
[469]44      OGRSFDriverRegistrar    *poR = OGRSFDriverRegistrar::GetRegistrar();
[775]45#endif
[469]46     
47      fprintf( stderr, "FAILURE:\n"
48               "Unable to open datasource `%s' with the following drivers.\n",
49               filename );
50     
51      for( int iDriver = 0; iDriver < poR->GetDriverCount(); iDriver++ )
52        {
[775]53#if GDAL_VERSION_MAJOR >= 2
54            fprintf( stderr, "  -> %s\n", poR->GetDriver(iDriver)->GetDescription() );
55#else
56            fprintf( stderr, "  -> %s\n", poR->GetDriver(iDriver)->GetName() );
57#endif
[469]58        }
59      char tmp[1024];
60      sprintf(tmp,"Unable to open datasource `%s' with the following drivers.",filename);
61      setMapInMaps(conf,"lenv","message",tmp);
62      return SERVICE_FAILED;
63    }
64  for( int iLayer = 0; iLayer < ipoDS->GetLayerCount();
65       iLayer++ )
66    {
67      OGRLayer        *poLayer = ipoDS->GetLayer(iLayer);
68     
69      if( poLayer == NULL )
70        {
71          fprintf( stderr, "FAILURE: Couldn't fetch advertised layer %d!\n",
72                   iLayer );
73#ifdef ZOO_SERVICE
74          char tmp[1024];
75          sprintf(tmp,"Couldn't fetch advertised layer %d!",iLayer);
76          setMapInMaps(conf,"lenv","message",tmp);
77          return SERVICE_FAILED;
78#else
79          exit( 1 );
80#endif
81        }
82     
83      OGRFeature  *poFeature;
84      while(TRUE){
85        poFeature = poLayer->GetNextFeature();
86        if( poFeature == NULL )
87          break;
88        if(poFeature->GetGeometryRef() != NULL){
89          points->push_back(Point(OGR_G_GetX(poFeature->GetGeometryRef(),0),OGR_G_GetY(poFeature->GetGeometryRef(),0)));
90        }
91      }
92    }
93  return SERVICE_SUCCEEDED;
94}
95
96
Note: See TracBrowser for help on using the repository browser.

Search

ZOO Sponsors

http://www.zoo-project.org/trac/chrome/site/img/geolabs-logo.pnghttp://www.zoo-project.org/trac/chrome/site/img/neogeo-logo.png http://www.zoo-project.org/trac/chrome/site/img/apptech-logo.png http://www.zoo-project.org/trac/chrome/site/img/3liz-logo.png http://www.zoo-project.org/trac/chrome/site/img/gateway-logo.png

Become a sponsor !

Knowledge partners

http://www.zoo-project.org/trac/chrome/site/img/ocu-logo.png http://www.zoo-project.org/trac/chrome/site/img/gucas-logo.png http://www.zoo-project.org/trac/chrome/site/img/polimi-logo.png http://www.zoo-project.org/trac/chrome/site/img/fem-logo.png http://www.zoo-project.org/trac/chrome/site/img/supsi-logo.png http://www.zoo-project.org/trac/chrome/site/img/cumtb-logo.png

Become a knowledge partner

Related links

http://zoo-project.org/img/ogclogo.png http://zoo-project.org/img/osgeologo.png