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 | OGRDataSource* ipoDS = OGRSFDriverRegistrar::Open(filename,FALSE); |
---|
32 | if( ipoDS == NULL ) |
---|
33 | { |
---|
34 | OGRSFDriverRegistrar *poR = OGRSFDriverRegistrar::GetRegistrar(); |
---|
35 | |
---|
36 | fprintf( stderr, "FAILURE:\n" |
---|
37 | "Unable to open datasource `%s' with the following drivers.\n", |
---|
38 | filename ); |
---|
39 | |
---|
40 | for( int iDriver = 0; iDriver < poR->GetDriverCount(); iDriver++ ) |
---|
41 | { |
---|
42 | fprintf( stderr, " -> %s\n", poR->GetDriver(iDriver)->GetName() ); |
---|
43 | } |
---|
44 | char tmp[1024]; |
---|
45 | sprintf(tmp,"Unable to open datasource `%s' with the following drivers.",filename); |
---|
46 | setMapInMaps(conf,"lenv","message",tmp); |
---|
47 | return SERVICE_FAILED; |
---|
48 | } |
---|
49 | for( int iLayer = 0; iLayer < ipoDS->GetLayerCount(); |
---|
50 | iLayer++ ) |
---|
51 | { |
---|
52 | OGRLayer *poLayer = ipoDS->GetLayer(iLayer); |
---|
53 | |
---|
54 | if( poLayer == NULL ) |
---|
55 | { |
---|
56 | fprintf( stderr, "FAILURE: Couldn't fetch advertised layer %d!\n", |
---|
57 | iLayer ); |
---|
58 | #ifdef ZOO_SERVICE |
---|
59 | char tmp[1024]; |
---|
60 | sprintf(tmp,"Couldn't fetch advertised layer %d!",iLayer); |
---|
61 | setMapInMaps(conf,"lenv","message",tmp); |
---|
62 | return SERVICE_FAILED; |
---|
63 | #else |
---|
64 | exit( 1 ); |
---|
65 | #endif |
---|
66 | } |
---|
67 | |
---|
68 | OGRFeature *poFeature; |
---|
69 | while(TRUE){ |
---|
70 | poFeature = poLayer->GetNextFeature(); |
---|
71 | if( poFeature == NULL ) |
---|
72 | break; |
---|
73 | if(poFeature->GetGeometryRef() != NULL){ |
---|
74 | points->push_back(Point(OGR_G_GetX(poFeature->GetGeometryRef(),0),OGR_G_GetY(poFeature->GetGeometryRef(),0))); |
---|
75 | } |
---|
76 | } |
---|
77 | } |
---|
78 | return SERVICE_SUCCEEDED; |
---|
79 | } |
---|
80 | |
---|
81 | |
---|