25 double **pprofx = NULL,**pprofy=NULL;
27 double *lat = NULL, *lon=NULL;
44 clock_t clock0,clock1;
49 _printf0_(
"\nExp2Kmlx Module -- " << ctime(&time0));
53 if (!
ExpRead(&nprof,&pnvert,&pprofx,&pprofy,&closed,filexp))
54 _error_(
"Error reading exp file.");
55 _printf0_(
"Exp2Kmlx -- Reading " << nprof <<
" exp profiles from file \"" << filexp <<
"\".\n");
62 kfile->
AddAttrib(
"xmlns",
"http://www.opengis.net/kml/2.2");
67 sprintf(kdoc->
name ,
"Exp2Kmlx Module -- %s",ctime(&time0));
73 sprintf(klsty->
color ,
"ff000000");
77 sprintf(kpsty->
color ,
"%02xffffff",(
int)floor(popac*255+0.5));
80 kstyle->
AddAttrib(
"id",
"BlackLineRandomPoly");
86 sprintf(klsty->
color ,
"ff000000");
90 sprintf(kpsty->
color ,
"00ffffff");
93 kstyle->
AddAttrib(
"id",
"BlackLineEmptyPoly");
99 sprintf(klsty->
color ,
"%02xffffff",(
int)floor(popac*255+0.5));
101 klsty->
width =lwidth*2;
103 sprintf(kpsty->
color ,
"00ffffff");
106 kstyle->
AddAttrib(
"id",
"RandomLineEmptyPoly");
114 sprintf(kfold->
name ,
"Profiles translated from file \"%s\".",filexp);
119 if (holes && nprof && (pnvert[0] <= 1 || pprofx[0][pnvert[0]-1] != pprofx[0][0] || pprofy[0][pnvert[0]-1] != pprofy[0][0])) {
120 _printf0_(
"Warning -- Outer profile is not closed, so \"holes\" option will be ignored.\n");
127 sprintf(kplace->
name ,
"Polygon with Holes");
129 sprintf(kplace->
styleurl ,
"#BlackLineRandomPoly");
134 kring->
ncoord =pnvert[i]-1;
135 lat=xNew<double>(kring->
ncoord);
136 lon=xNew<double>(kring->
ncoord);
137 Xy2llx(lat,lon,pprofx[i],pprofy[i],kring->
ncoord,sgn,cm,sp);
139 for (j=0; j<kring->
ncoord; j++) {
140 kring->
coords[3*j+0]=lon[j];
141 kring->
coords[3*j+1]=lat[j];
144 xDelete<double>(lon);
145 xDelete<double>(lat);
150 for (i=1; i<nprof; i++) {
151 if (pnvert[i] <= 1 || pprofx[i][pnvert[i]-1] != pprofx[i][0] || pprofy[i][pnvert[i]-1] != pprofy[i][0]) {
152 _printf0_(
"Warning -- Inner profile " << i+1 <<
" is not closed with \"holes\" specified, so it will be ignored.\n");
158 kring->
ncoord =pnvert[i]-1;
159 lat=xNew<double>(kring->
ncoord);
160 lon=xNew<double>(kring->
ncoord);
161 Xy2llx(lat,lon,pprofx[i],pprofy[i],kring->
ncoord,sgn,cm,sp);
163 for (j=0; j<kring->
ncoord; j++) {
164 kring->
coords[3*j+0]=lon[j];
165 kring->
coords[3*j+1]=lat[j];
168 xDelete<double>(lon);
169 xDelete<double>(lat);
184 for (i=0; i<nprof; i++) {
187 if (pnvert[i] > 1 && pprofx[i][pnvert[i]-1] == pprofx[i][0] && pprofy[i][pnvert[i]-1] == pprofy[i][0]) {
188 sprintf(kplace->
name ,
"Polygon %d",i+1);
190 sprintf(kplace->
styleurl ,
"#BlackLineRandomPoly");
195 kring->
ncoord =pnvert[i]-1;
196 lat=xNew<double>(kring->
ncoord);
197 lon=xNew<double>(kring->
ncoord);
198 Xy2llx(lat,lon,pprofx[i],pprofy[i],kring->
ncoord,sgn,cm,sp);
200 for (j=0; j<kring->
ncoord; j++) {
201 kring->
coords[3*j+0]=lon[j];
202 kring->
coords[3*j+1]=lat[j];
205 xDelete<double>(lon);
206 xDelete<double>(lat);
215 else if (pnvert[i] > 1) {
216 sprintf(kplace->
name ,
"LineString %d",i+1);
218 sprintf(kplace->
styleurl ,
"#RandomLineEmptyPoly");
223 lat=xNew<double>(kline->
ncoord);
224 lon=xNew<double>(kline->
ncoord);
225 Xy2llx(lat,lon,pprofx[i],pprofy[i],kline->
ncoord,sgn,cm,sp);
227 for (j=0; j<kline->
ncoord; j++) {
228 kline->
coords[3*j+0]=lon[j];
229 kline->
coords[3*j+1]=lat[j];
232 xDelete<double>(lon);
233 xDelete<double>(lat);
239 else if (pnvert[i]) {
240 sprintf(kplace->
name ,
"Point %d",i+1);
242 sprintf(kplace->
styleurl ,
"#RandomLineEmptyPoly");
247 lat=xNew<double>(one);
248 lon=xNew<double>(one);
249 Xy2llx(lat,lon,pprofx[i],pprofy[i],1,sgn,cm,sp);
253 xDelete<double>(lon);
254 xDelete<double>(lat);
274 _printf0_(
"Exp2Kmlx -- Writing kml document to file \"" << filkml <<
"\".\n");
275 fid=fopen(filkml,
"w");
276 fprintf(fid,
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
277 kfile->
Write(fid,indent);
281 for (i=nprof-1; i>=0; i--) {
282 xDelete<double>(pprofy[i]);
283 xDelete<double>(pprofx[i]);
285 xDelete<int>(pnvert);
289 _printf_(
"Exp2Kmlx Module -- " <<((
double)(clock1-clock0))/CLOCKS_PER_SEC <<
" CPU seconds; " <<difftime(time1,time0) <<
" elapsed seconds.\n\n\n");