- Timestamp:
- Nov 21, 2017, 10:24:14 AM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/prototype-v0/zoo-project/zoo-kernel/service_internal_ms.c
r851 r854 138 138 exit(-1); 139 139 } 140 int finalProto=-1; 140 141 map *msOgcVersion=getMapFromMaps(m,"main","msOgcVersion"); 141 142 map *dataPath=getMapFromMaps(m,"main","dataPath"); … … 147 148 map* protoMap=getMap(tmpI->content,"msOgc"); 148 149 map* versionMap=getMap(tmpI->content,"msOgcVersion"); 149 char options[ 3][5][25]={150 char options[4][5][25]={ 150 151 {"WMS","1.3.0","GetMap","layers=%s","wms_extent"}, 151 152 {"WFS","1.1.0","GetFeature","typename=%s","wcs_extent"}, 152 //{"WCS","1.1.0","GetCoverage","coverage=%s","wcs_extent"}153 {"WCS"," 2.0.0","GetCoverage","coverageid=%s","wcs_extent"}153 {"WCS","2.0.0","GetCoverage","coverageid=%s","wcs_extent"}, 154 {"WCS","1.1.0","GetCoverage","coverage=%s","wcs_extent"} 154 155 }; 156 map* datatype=getMap(tmpI->content,"geodatatype"); 157 if(datatype==NULL || strncmp(datatype->value,"other",5)==0){ 158 setMapInMaps(m,"lenv","mapError","true"); 159 setMapInMaps(m,"lenv","locator",tmpI->name); 160 setMapInMaps(m,"lenv","message",_("The ZOO-Kernel was able to retrieve the data but could not read it as geographic data.")); 161 if(getMapFromMaps(m,"lenv","state")==NULL) 162 errorException (m, _("Unable to find any geographic data"), "WrongInputData", tmpI->name); 163 return; 164 } 155 165 int proto=0; 156 166 if(rformat==NULL){ … … 194 204 195 205 char* webService_url=(char*)malloc((strlen(msUrl->value)+strlen(format->value)+strlen(tmpI->name)+strlen(width->value)+strlen(height->value)+strlen(extent->value)+256)*sizeof(char)); 196 map* datatype=getMap(tmpI->content,"geodatatype");197 206 198 207 if(proto>0){ 208 if(proto==2) 209 finalProto=1; 199 210 sprintf(webService_url, 200 211 "%s?map=%s/%s_%s.map&request=%s&service=%s&version=%s&%s&format=%s&bbox=%s&crs=%s", … … 248 259 } 249 260 addToMap(tmpI->content,"Reference",webService_url); 250 261 memset(layers,0,128); 262 sprintf(layers,options[proto][3],tmpI->name); 251 263 protoVersion=options[proto][1]; 252 264 extent=getMap(tmpI->content,options[proto][4]); 253 265 memset(webService_url,0,strlen(webService_url)); 254 266 if(proto>0){ 267 if(proto==2) 268 finalProto=1; 255 269 sprintf(webService_url, 256 270 "%s?map=%s/%s_%s.map&request=%s&service=%s&version=%s&%s&format=%s&bbox=%s&crs=%s", … … 292 306 addToMap(tmpI->content,"ref_wms_link",webService_url); 293 307 } 308 if(finalProto>0){ 309 proto=3; 310 memset(layers,0,128); 311 sprintf(layers,options[proto][3],tmpI->name); 312 protoVersion=options[proto][1]; 313 extent=getMap(tmpI->content,options[proto][4]); 314 memset(webService_url,0,strlen(webService_url)); 315 sprintf(webService_url, 316 "%s?map=%s/%s_%s.map&request=%s&service=%s&version=%s&%s&format=%s&bbox=%s&crs=%s", 317 msUrl->value, 318 dataPath->value, 319 tmpI->name, 320 sid->value, 321 options[proto][2], 322 options[proto][0], 323 protoVersion, 324 layers, 325 rformat->value, 326 extent->value, 327 crs->value 328 ); 329 addToMap(tmpI->content,"ref_wcs_preview_link",webService_url); 330 } 294 331 if(hasCRS==0){ 295 332 freeMap(&crs); … … 299 336 free(rformat); 300 337 free(webService_url); 301 dumpMaps(tmpI);302 338 } 303 339 … … 492 528 /** 493 529 * Try to load the file as ZIP 494 */ 495 530 * 496 531 OGRDataSourceH poDS1 = NULL; 497 532 OGRSFDriverH *poDriver1 = NULL; … … 534 569 fprintf(stderr,"Unable to access the DataSource as ZIP File\n"); 535 570 setMapInMaps(conf,"lenv","message","Unable to open datasource in read only mode"); 571 fprintf(stderr,"Remove ZIP File!\n"); 572 unlink(odsName); 536 573 //OGR_DS_Destroy(poDS1); 537 574 }else{ … … 594 631 } 595 632 OGR_DS_Destroy(poDS1); 596 }633 } 597 634 free(sdsName); 598 free(dsName); 635 free(dsName);*/ 599 636 600 637 OGRDataSourceH poDS = NULL; … … 649 686 myLayer->status = MS_ON; 650 687 msConnectLayer(myLayer,MS_OGR,pszDataSource); 688 689 addIntToMap(output->content,"nb_features",OGR_L_GetFeatureCount(poLayer,1)); 651 690 652 691 /** … … 811 850 */ 812 851 GDALAllRegister(); 813 hDataset = GDALOpen( pszFilename, GA_ ReadOnly);852 hDataset = GDALOpen( pszFilename, GA_Update ); 814 853 if( hDataset == NULL ){ 815 854 #ifdef DEBUGMS … … 866 905 m->width=GDALGetRasterXSize( hDataset ); 867 906 m->height=GDALGetRasterYSize( hDataset ); 907 addIntToMap(output->content,"nb_pixels",GDALGetRasterXSize( hDataset )*GDALGetRasterYSize( hDataset )); 868 908 869 909 /** … … 880 920 setSrsInformations(output,m,myLayer,pszProjection); 881 921 }else{ 882 fprintf(stderr,"NO SRS FOUND ! %s\n",GDALGetProjectionRef( hDataset )); 922 fprintf(stderr,"NO SRS FOUND ! %s\n",GDALGetProjectionRef( hDataset )); 923 CPLErr sp=GDALSetProjection( hDataset , "+init=epsg:4326" ); 924 if(sp!=CE_None){ 925 fprintf(stderr,"NO SRS FOUND ! %s\n",CPLGetLastErrorMsg()); 926 } 883 927 } 884 928 … … 905 949 addToMap(output->content,"boundingbox",extent); 906 950 } 951 }else{ 952 int scale=1; 953 if(m->width>2048){ 954 addIntToMap(output->content,"width",2048); 955 scale=2048/m->width; 956 }else 957 addIntToMap(output->content,"width",m->width); 958 addIntToMap(output->content,"height",m->height*scale); 907 959 } 908 960 … … 919 971 } 920 972 if(nBandsI>=3) 921 msLayerAddProcessing(myLayer,"BANDS=1,2,3"); 973 if(nBandsI==4) 974 msLayerAddProcessing(myLayer,"BANDS=1,2,3,4"); 975 else 976 msLayerAddProcessing(myLayer,"BANDS=1,2,3"); 922 977 else if(nBandsI>=2) 923 978 msLayerAddProcessing(myLayer,"BANDS=1,2"); 924 979 else 925 980 msLayerAddProcessing(myLayer,"BANDS=1"); 981 926 982 927 983 /** … … 929 985 */ 930 986 char lBands[7]; 931 memset(&nBands,0,7);932 987 char *nameBands=NULL; 933 988 for( iBand = 0; iBand < nBandsI; iBand++ ){ 989 memset(&lBands,0,7); 934 990 sprintf(lBands,"Band%d",iBand+1); 935 991 if(nameBands==NULL){ … … 937 993 sprintf(nameBands,"%s",lBands); 938 994 }else{ 939 if(iBand<4){995 /*if(iBand<4)*/{ 940 996 char *tmpS=zStrdup(nameBands); 941 997 nameBands=(char*)realloc(nameBands,(strlen(tmpS)+strlen(lBands)+2)*sizeof(char)); … … 954 1010 */ 955 1011 for( iBand = 0; iBand < nBandsI; iBand++ ){ 956 //int bGotNodata;//, bSuccess; 957 double adfCMinMax[2]/*, dfNoData*/; 958 //int nBlockXSize, nBlockYSize, nMaskFlags; 959 //double /*dfMean, dfStdDev*/; 1012 double pdfMin, pdfMax, pdfMean, pdfStdDev; 960 1013 hBand = GDALGetRasterBand( hDataset, iBand+1 ); 961 1014 962 1015 CPLErrorReset(); 963 GDALComputeRaster MinMax( hBand, FALSE, adfCMinMax);1016 GDALComputeRasterStatistics( hBand, TRUE, &pdfMin, &pdfMax, &pdfMean, &pdfStdDev, NULL,NULL); 964 1017 char tmpN[21]; 965 1018 sprintf(tmpN,"Band%d",iBand+1); 966 1019 if (CPLGetLastErrorType() == CE_None){ 967 char tmpMm[100]; 968 sprintf(tmpMm,"%.3f %.3f",adfCMinMax[0],adfCMinMax[1]); 1020 char tmpMm[100],tmpMp[100]; 1021 sprintf(tmpMm,"%.3f %.3f",pdfMin,pdfMax); 1022 sprintf(tmpMp,"SCALE_%d=%.3f,%.3f",iBand+1,pdfMean-(2*pdfStdDev),pdfMean+(2*pdfStdDev)); 969 1023 char tmpI[31]; 970 1024 sprintf(tmpI,"%s_interval",tmpN); 971 1025 msInsertHashTable(&(myLayer->metadata), tmpI, tmpMm); 972 1026 if(pdfMax>255) 1027 msLayerAddProcessing(myLayer,tmpMp); 973 1028 map* test=getMap(output->content,"msClassify"); 974 1029 if(test!=NULL && strncasecmp(test->value,"true",4)==0){ … … 990 1045 991 1046 if(nBandsI==1){ 992 double delta= adfCMinMax[1]-adfCMinMax[0];1047 double delta=pdfMax-pdfMin; 993 1048 double interval=delta/10; 994 double cstep= adfCMinMax[0];1049 double cstep=pdfMin; 995 1050 for(i=0;i<10;i++){ 996 1051 /** … … 1036 1091 1037 1092 char tmpMm[100]; 1038 sprintf(tmpMm,"%.3f %.3f", adfCMinMax[0],adfCMinMax[1]);1093 sprintf(tmpMm,"%.3f %.3f",pdfMin,pdfMax); 1039 1094 1040 1095 } … … 1046 1101 myLayer->offsite.blue=0; 1047 1102 } 1048 msLayerAddProcessing(myLayer,"RESAMPLE=BILINEAR");1049 1103 } 1050 1104 } … … 1056 1110 1057 1111 } 1112 msLayerAddProcessing(myLayer,"RESAMPLE=BILINEAR"); 1058 1113 1059 1114 m->layerorder[m->numlayers] = m->numlayers; … … 1081 1136 ext="json"; 1082 1137 1083 map* tmpMap=getMapFromMaps(conf,"main","dataPath"); 1084 map* sidMap=getMapFromMaps(conf,"lenv","usid"); 1085 char *pszDataSource=(char*)malloc((strlen(tmpMap->value)+strlen(sidMap->value)+strlen(outputs->name)+17)*sizeof(char)); 1086 sprintf(pszDataSource,"%s/ZOO_DATA_%s_%s.%s",tmpMap->value,outputs->name,sidMap->value,ext); 1087 int f=zOpen(pszDataSource,O_WRONLY|O_CREAT,S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH); 1088 map *gfile=getMap(outputs->content,"generated_file"); 1089 if(gfile!=NULL){ 1090 readGeneratedFile(conf,outputs->content,gfile->value); 1091 } 1092 map* sizeMap=getMap(outputs->content,"size"); 1093 map* vData=getMap(outputs->content,"value"); 1094 if(sizeMap!=NULL){ 1095 zWrite(f,vData->value,atoi(sizeMap->value)*sizeof(char)); 1096 } 1097 else{ 1098 zWrite(f,vData->value,(strlen(vData->value)+1)*sizeof(char)); 1099 } 1100 close(f); 1101 addToMap(outputs->content,"storage",pszDataSource); 1102 free(pszDataSource); 1138 map* storage=getMap(outputs->content,"storage"); 1139 if(storage==NULL){ 1140 map* tmpMap=getMapFromMaps(conf,"main","dataPath"); 1141 map* sidMap=getMapFromMaps(conf,"lenv","usid"); 1142 char *pszDataSource=(char*)malloc((strlen(tmpMap->value)+strlen(sidMap->value)+strlen(outputs->name)+17)*sizeof(char)); 1143 sprintf(pszDataSource,"%s/ZOO_DATA_%s_%s.%s",tmpMap->value,outputs->name,sidMap->value,ext); 1144 int f=zOpen(pszDataSource,O_WRONLY|O_CREAT,S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH); 1145 map *gfile=getMap(outputs->content,"generated_file"); 1146 if(gfile!=NULL){ 1147 readGeneratedFile(conf,outputs->content,gfile->value); 1148 } 1149 map* sizeMap=getMap(outputs->content,"size"); 1150 map* vData=getMap(outputs->content,"value"); 1151 if(sizeMap!=NULL){ 1152 zWrite(f,vData->value,atoi(sizeMap->value)*sizeof(char)); 1153 } 1154 else{ 1155 zWrite(f,vData->value,(strlen(vData->value)+1)*sizeof(char)); 1156 } 1157 close(f); 1158 addToMap(outputs->content,"storage",pszDataSource); 1159 free(pszDataSource); 1160 } 1103 1161 1104 1162 /* … … 1174 1232 #endif 1175 1233 1234 outputFormatObj *o6=msCreateDefaultOutputFormat(NULL,"GDAL/GTiff","geotiff"); 1235 if(!o6) 1236 fprintf(stderr,"Unable to initialize GDAL driver !\n"); 1237 else{ 1238 o6->imagemode=MS_IMAGEMODE_BYTE; 1239 o6->mimetype=strdup("image/geotiff"); 1240 o6->inmapfile=MS_TRUE; 1241 msAppendOutputFormat(myMap,msCloneOutputFormat(o6)); 1242 msFreeOutputFormat(o6); 1243 } 1244 1176 1245 /* 1177 1246 * Set default projection to EPSG:4326 … … 1262 1331 msSaveMap(myMap,mapPath); 1263 1332 free(mapPath); 1333 //msFreeSymbolSet(&myMap->symbolset); 1334 msFreeMap(myMap); 1335 //msFree(myMap); 1264 1336 msGDALCleanup(); 1265 msFreeMap(myMap);1266 1337 } 1267 1338
Note: See TracChangeset
for help on using the changeset viewer.