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 | |
---|
26 | int 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); |
---|
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 |
---|
37 | OGRDataSource* ipoDS = OGRSFDriverRegistrar::Open(filename,FALSE); |
---|
38 | #endif |
---|
39 | if( ipoDS == NULL ) |
---|
40 | { |
---|
41 | #if GDAL_VERSION_MAJOR >= 2 |
---|
42 | GDALDriverManager* poR=GetGDALDriverManager(); |
---|
43 | #else |
---|
44 | OGRSFDriverRegistrar *poR = OGRSFDriverRegistrar::GetRegistrar(); |
---|
45 | #endif |
---|
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 | { |
---|
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 |
---|
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 | |
---|