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

Last change on this file since 948 was 917, checked in by djay, 6 years ago

Merge prototype-v0 branch in trunk

File size: 3.6 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
[917]26int parseInput(maps* conf,maps* inputs, std::vector<Pointz>* points,char* filename){
[469]27  map* tmpm=NULL;
[917]28  tmpm=getMapFromMaps(inputs,"InputPoints","cache_file");
[775]29#if GDAL_VERSION_MAJOR >= 2
[917]30  GDALDataset *ipoDS;
[775]31#else
[917]32  OGRDataSource* ipoDS;
[775]33#endif
[917]34  if(tmpm==NULL){
35    tmpm=getMapFromMaps(inputs,"InputPoints","value");
36    VSILFILE *ifile=VSIFileFromMemBuffer(filename,(GByte*)tmpm->value,strlen(tmpm->value),FALSE);
37    VSIFCloseL(ifile);
38#if GDAL_VERSION_MAJOR >= 2
39  ipoDS = (GDALDataset*) GDALOpenEx( filename,
40                                     GDAL_OF_READONLY | GDAL_OF_VECTOR,
41                                     NULL, NULL, NULL );
42#else
43  ipoDS = OGRSFDriverRegistrar::Open(filename,FALSE);
44#endif
45  }else
46#if GDAL_VERSION_MAJOR >= 2
47    ipoDS = (GDALDataset*) GDALOpenEx( tmpm->value,
48                                       GDAL_OF_READONLY | GDAL_OF_VECTOR,
49                                       NULL, NULL, NULL );
50#else
51    ipoDS = OGRSFDriverRegistrar::Open(tmpm->value,FALSE);
52#endif
53   
[469]54  if( ipoDS == NULL )
55    {
[775]56#if GDAL_VERSION_MAJOR >= 2
57      GDALDriverManager* poR=GetGDALDriverManager();
58#else
[469]59      OGRSFDriverRegistrar    *poR = OGRSFDriverRegistrar::GetRegistrar();
[775]60#endif
[469]61     
62      fprintf( stderr, "FAILURE:\n"
63               "Unable to open datasource `%s' with the following drivers.\n",
64               filename );
65     
66      for( int iDriver = 0; iDriver < poR->GetDriverCount(); iDriver++ )
67        {
[775]68#if GDAL_VERSION_MAJOR >= 2
69            fprintf( stderr, "  -> %s\n", poR->GetDriver(iDriver)->GetDescription() );
70#else
71            fprintf( stderr, "  -> %s\n", poR->GetDriver(iDriver)->GetName() );
72#endif
[469]73        }
74      char tmp[1024];
75      sprintf(tmp,"Unable to open datasource `%s' with the following drivers.",filename);
76      setMapInMaps(conf,"lenv","message",tmp);
77      return SERVICE_FAILED;
78    }
79  for( int iLayer = 0; iLayer < ipoDS->GetLayerCount();
80       iLayer++ )
81    {
82      OGRLayer        *poLayer = ipoDS->GetLayer(iLayer);
83     
84      if( poLayer == NULL )
85        {
86          fprintf( stderr, "FAILURE: Couldn't fetch advertised layer %d!\n",
87                   iLayer );
88#ifdef ZOO_SERVICE
89          char tmp[1024];
90          sprintf(tmp,"Couldn't fetch advertised layer %d!",iLayer);
91          setMapInMaps(conf,"lenv","message",tmp);
92          return SERVICE_FAILED;
93#else
94          exit( 1 );
95#endif
96        }
97     
98      OGRFeature  *poFeature;
99      while(TRUE){
100        poFeature = poLayer->GetNextFeature();
101        if( poFeature == NULL )
102          break;
103        if(poFeature->GetGeometryRef() != NULL){
[917]104          points->push_back(Pointz(OGR_G_GetX(poFeature->GetGeometryRef(),0),OGR_G_GetY(poFeature->GetGeometryRef(),0)));
[469]105        }
106      }
107    }
108  return SERVICE_SUCCEEDED;
109}
110
111
Note: See TracBrowser for help on using the repository browser.

Search

Context Navigation

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