Changeset 11554
- Timestamp:
- 02/27/12 15:22:59 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/c/modules/Exp2Kmlx/Exp2Kmlx.cpp
r9761 r11554 48 48 KML_LinearRing* kring =NULL; 49 49 KML_LineString* kline =NULL; 50 KML_Point* kpoint=NULL; 50 51 51 52 FILE* fid=NULL; … … 60 61 /* read exp file */ 61 62 62 if (!DomainOutlineRead(&nprof,&pnvert,&pprofx,&pprofy,&closed,filexp, false))63 if (!DomainOutlineRead(&nprof,&pnvert,&pprofx,&pprofy,&closed,filexp,true)) 63 64 _error_("Error reading exp file."); 65 _printf_(true,"Exp2Kmlx -- Reading %d exp profiles from file \"%s\".\n",nprof,filexp); 66 // for (i=0; i<nprof; i++) 67 // printf("i=%d; nvert=%d, closed=%d\n",i,pnvert[i],closed[i]); 64 68 65 69 /* construct kml file */ … … 123 127 /* polygon with multiple holes */ 124 128 125 if (holes && nprof && !closed[0]) {129 if (holes && nprof && (pnvert[0] <= 1 || pprofx[0][pnvert[0]-1] != pprofx[0][0] || pprofy[0][pnvert[0]-1] != pprofy[0][0])) { 126 130 _printf_(true,"Warning -- Outer profile is not closed, so \"holes\" option will be ignored.\n"); 127 131 holes=false; … … 138 142 kring =new KML_LinearRing(); 139 143 140 lat=(double *) xmalloc(pnvert[i]*sizeof(double)); 141 lon=(double *) xmalloc(pnvert[i]*sizeof(double)); 142 Xy2llx(lat,lon,pprofx[i],pprofy[i],pnvert[i],sgn,cm,sp); 143 144 kring->ncoord =pnvert[i]; 145 kring->coords =(double (*)[3]) xmalloc(pnvert[i]*3*sizeof(double)); 146 for (j=0; j<pnvert[i]; j++) { 144 kring->ncoord =pnvert[i]-1; 145 lat=(double *) xmalloc(kring->ncoord*sizeof(double)); 146 lon=(double *) xmalloc(kring->ncoord*sizeof(double)); 147 Xy2llx(lat,lon,pprofx[i],pprofy[i],kring->ncoord,sgn,cm,sp); 148 kring->coords =(double (*)[3]) xmalloc(kring->ncoord*3*sizeof(double)); 149 for (j=0; j<kring->ncoord; j++) { 147 150 kring->coords[j][0]=lon[j]; 148 151 kring->coords[j][1]=lat[j]; … … 156 159 157 160 for (i=1; i<nprof; i++) { 158 if ( !closed[i]) {161 if (pnvert[i] <= 1 || pprofx[i][pnvert[i]-1] != pprofx[i][0] || pprofy[i][pnvert[i]-1] != pprofy[i][0]) { 159 162 _printf_(true,"Warning -- Inner profile %d is not closed with \"holes\" specified, so it will be ignored.\n",i+1); 160 163 continue; … … 163 166 kring =new KML_LinearRing(); 164 167 165 lat=(double *) xmalloc(pnvert[i]*sizeof(double));166 l on=(double *) xmalloc(pnvert[i]*sizeof(double));167 Xy2llx(lat,lon,pprofx[i],pprofy[i],pnvert[i],sgn,cm,sp);168 kring->ncoord =pnvert[i];169 kring->coords =(double (*)[3]) xmalloc( pnvert[i]*3*sizeof(double));170 for (j=0; j< pnvert[i]; j++) {168 kring->ncoord =pnvert[i]-1; 169 lat=(double *) xmalloc(kring->ncoord*sizeof(double)); 170 lon=(double *) xmalloc(kring->ncoord*sizeof(double)); 171 Xy2llx(lat,lon,pprofx[i],pprofy[i],kring->ncoord,sgn,cm,sp); 172 kring->coords =(double (*)[3]) xmalloc(kring->ncoord*3*sizeof(double)); 173 for (j=0; j<kring->ncoord; j++) { 171 174 kring->coords[j][0]=lon[j]; 172 175 kring->coords[j][1]=lat[j]; … … 192 195 kplace=new KML_Placemark(); 193 196 194 if (closed[i]) {197 if (pnvert[i] > 1 && pprofx[i][pnvert[i]-1] == pprofx[i][0] && pprofy[i][pnvert[i]-1] == pprofy[i][0]) { 195 198 sprintf(kplace->name ,"Polygon %d",i+1); 196 199 kplace->visibility=true; … … 200 203 kring =new KML_LinearRing(); 201 204 202 lat=(double *) xmalloc(pnvert[i]*sizeof(double)); 203 lon=(double *) xmalloc(pnvert[i]*sizeof(double)); 204 Xy2llx(lat,lon,pprofx[i],pprofy[i],pnvert[i],sgn,cm,sp); 205 206 kring->ncoord =pnvert[i]; 207 kring->coords =(double (*)[3]) xmalloc(pnvert[i]*3*sizeof(double)); 208 for (j=0; j<pnvert[i]; j++) { 205 kring->ncoord =pnvert[i]-1; 206 lat=(double *) xmalloc(kring->ncoord*sizeof(double)); 207 lon=(double *) xmalloc(kring->ncoord*sizeof(double)); 208 Xy2llx(lat,lon,pprofx[i],pprofy[i],kring->ncoord,sgn,cm,sp); 209 kring->coords =(double (*)[3]) xmalloc(kring->ncoord*3*sizeof(double)); 210 for (j=0; j<kring->ncoord; j++) { 209 211 kring->coords[j][0]=lon[j]; 210 212 kring->coords[j][1]=lat[j]; … … 221 223 } 222 224 223 else {225 else if (pnvert[i] > 1) { 224 226 sprintf(kplace->name ,"LineString %d",i+1); 225 227 kplace->visibility=true; … … 228 230 kline =new KML_LineString(); 229 231 230 lat=(double *) xmalloc(pnvert[i]*sizeof(double));231 lon=(double *) xmalloc(pnvert[i]*sizeof(double));232 Xy2llx(lat,lon,pprofx[i],pprofy[i],pnvert[i],sgn,cm,sp);233 234 232 kline->ncoord =pnvert[i]; 235 kline->coords =(double (*)[3]) xmalloc(pnvert[i]*3*sizeof(double)); 236 for (j=0; j<pnvert[i]; j++) { 233 lat=(double *) xmalloc(kline->ncoord*sizeof(double)); 234 lon=(double *) xmalloc(kline->ncoord*sizeof(double)); 235 Xy2llx(lat,lon,pprofx[i],pprofy[i],kline->ncoord,sgn,cm,sp); 236 kline->coords =(double (*)[3]) xmalloc(kline->ncoord*3*sizeof(double)); 237 for (j=0; j<kline->ncoord; j++) { 237 238 kline->coords[j][0]=lon[j]; 238 239 kline->coords[j][1]=lat[j]; … … 246 247 } 247 248 249 else if (pnvert[i]) { 250 sprintf(kplace->name ,"Point %d",i+1); 251 kplace->visibility=true; 252 sprintf(kplace->styleurl ,"#RandomLineEmptyPoly"); 253 254 kpoint=new KML_Point(); 255 256 lat=(double *) xmalloc(sizeof(double)); 257 lon=(double *) xmalloc(sizeof(double)); 258 Xy2llx(lat,lon,pprofx[i],pprofy[i],1,sgn,cm,sp); 259 kpoint->coords[0]=lon[0]; 260 kpoint->coords[1]=lat[0]; 261 kpoint->coords[2]=0.; 262 xfree((void**)&lon); 263 xfree((void**)&lat); 264 265 (kplace->geometry )->AddObject((Object*)kpoint); 266 kpoint =NULL; 267 } 268 248 269 (kfold ->feature )->AddObject((Object*)kplace); 249 270 kplace=NULL; … … 260 281 /* write kml file */ 261 282 262 _printf_(true," Writing kml document to file.\n");283 _printf_(true,"Exp2Kmlx -- Writing kml document to file \"%s\".\n",filkml); 263 284 fid=fopen(filkml,"w"); 264 285 fprintf(fid,"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
Note:
See TracChangeset
for help on using the changeset viewer.