45 #define NO_ELEVATION 0.0
46 #define LX_CENTER -0.5
55 #define INIT_VALUE -999
57 #define FLOATING_POINT_TYPE 0
58 #define MAP_FORMAT 3 // output esri asccii according to Stefano Endrizzi's 2007 functions
95 long r,c,j,data_counter;
97 printf(
"ENTRANCE: %ld %ld %ld %ld ",row_shift,col_shift,lmask->
nrh,lmask->
nch);
99 if ((row_shift<-1)|| (row_shift>1) || (col_shift<-1)|| (col_shift>1) ) {
100 printf (
"Warning in addresses function source file g_raster2plvector_novalue_manegement: parameters row_shift or col_shift exceed 1 (in absolute value) \n");
101 printf (
"This could cause bus errors!!\n ");
105 for (r=lmask->
nrl;r<=lmask->nrh;r++) {
106 if ((lmask->element[r][lmask->
ncl]==1) || (lmask->element[r][lmask->
nch]==1)) printf (
"Warning in addresses function source file g_raster2plvector_novalue_manegement: at row %ld the mask of the basin reaches the border !\n",r);
108 for (c=lmask->
ncl;c<=lmask->nch;c++) {
109 if ((lmask->element[lmask->
nrl][c]==1) || (lmask->element[lmask->
nrh][c]==1)) printf (
"Warning in addresses function source file g_raster2plvector_novalue_manegement: at column %ld the mask of the basin reaches the border!\n",c);
112 ndata->element[ndata->
nl]=0;
114 for (r=lmask->
nrl+1;r<=lmask->nrh;r++){
116 for (c=lmask->
ncl+1;c<=lmask->nch;c++){
117 if ((lmask->element[r][c]==1) || (lmask->element[r][c+col_shift]==1) || (lmask->element[r+row_shift][c]==1) || (lmask->element[r+row_shift][c+col_shift]==1))
121 ndata->element[r]=data_counter;
128 for (r=lmask->
nrl+1;r<=lmask->nrh;r++){
130 for (c=lmask->
ncl+1;c<=lmask->nch;c++){
131 if ((lmask->element[r][c]==1) || (lmask->element[r][c+col_shift]==1) || (lmask->element[r+row_shift][c]==1) || (lmask->element[r+row_shift][c+col_shift]==1)) {
165 l=s_index->element[r]-c+1;
168 l=s_index->element[r-1]+c;
198 s_index->element[s_index->
nl]=laddresses->
index->element[s_index->
nl];
199 for (l=s_index->
nl+1;l<=s_index->nh;l++){
200 if (laddresses->
index->element[l]>nch) printf(
"Error: in m_indices_with_novalues at row %ld , %ld exceeds number of columns %ld \n",l,laddresses->
index->element[l],nch);
201 s_index->element[l]=s_index->element[l-1]+laddresses->
index->element[l];
207 for(r=m_ind->
nrl;r<=m_ind->nrh;r++) {
208 for(c=m_ind->
ncl;c<=m_ind->nch;c++) {
209 m_ind->element[r][c]=novalue;
213 for(j=m_ind->
ncl;j<=laddresses->index->element[r];j++){
214 m_ind->element[r][laddresses->element[r][j]]=(*index_pixel_from_a_bin)(r,j,s_index)+IBASE;
235 LONGMATRIX *
m_indices_from_mask(
DOUBLEMATRIX *mask,
long row_shift,
long col_shift,
long novalue,
long IBASE,
long (*
index_pixel_from_a_bin)(
long r,
long c,
LONGVECTOR *s_index),
DOUBLEVECTOR *V,
int (*check_novalues)(
double x,
DOUBLEVECTOR *V)){
258 printf(
"1: lmask %ld %ld:\n",lmask->
nrh,lmask->
nch);
260 for (r=mask->
nrl;r<=mask->nrh;r++) {
261 for (c=mask->
ncl;c<=mask->nch;c++) {
263 if ((*check_novalues)(mask->element[r][c],V)==0) {
265 lmask->element[r][c]=1;
267 }
else if ((*check_novalues)(mask->element[r][c],V)==1) {
268 lmask->element[r][c]=0;
273 printf(
"lmask %ld %ld :\n",lmask->
nrh,lmask->
nch);
294 POINT *
new_point_from_raster(
long r,
long c,
long nrh,
long nch,
double lx,
double ly,
double nsres,
double ewres,
double blc_x,
double blc_y,
long index) {
320 x=((double)c+lx)*ewres+blc_x;
321 y=((double)(nrh-r)+ly)*nsres+blc_y;
329 LINE *
new_horizontal_line_from_raster(
long r,
long c,
long nrh,
long nch,
double nsres,
double ewres,
double blc_x,
double blc_y,
long iline,
long ivertex1,
long ivertex2){
361 P1=
new_point_from_raster(r,c,nrh,nch,
LEFT,
TOP,nsres,ewres,blc_x,blc_y,ivertex1);
362 P2=
new_point_from_raster(r,c,nrh,nch,
RIGHT,
TOP,nsres,ewres,blc_x,blc_y,ivertex2);
375 LINE *
new_vertical_line_from_raster(
long r,
long c,
long nrh,
long nch,
double nsres,
double ewres,
double blc_x,
double blc_y,
long iline,
long ivertex1,
long ivertex2){
407 P1=
new_point_from_raster(r,c,nrh,nch,
LEFT,
BOTTOM,nsres,ewres,blc_x,blc_y,ivertex1);
408 P2=
new_point_from_raster(r,c,nrh,nch,
LEFT,
TOP,nsres,ewres,blc_x,blc_y,ivertex2);
448 for(r=i_vertical->
nrl;r<=i_vertical->nrh;r++){
449 for (c=i_vertical->
ncl;c<=i_vertical->nch;c++){
452 if (i_vertical->element[r][c]!=novalue) count++;
458 for(r=i_horizontal->
nrl;r<=i_horizontal->nrh;r++){
459 for (c=i_horizontal->
ncl;c<=i_horizontal->nch;c++){
461 if (i_horizontal->element[r][c]!=novalue) count++ ;
470 for(r=i_vertical->
nrl;r<=i_vertical->nrh;r++){
471 for (c=i_vertical->
ncl;c<=i_vertical->nch;c++){
474 if (i_vertical->element[r][c]!=novalue) lines->
element[i_vertical->element[r][c]]=
new_vertical_line_from_raster(r,c,i_vertical->
nrh,i_vertical->
nch,nsres,ewres,blc_x,blc_y,i_vertical->element[r][c],i_vertex->element[r+1][c],i_vertex->element[r][c]);
480 for(r=i_horizontal->
nrl;r<=i_horizontal->nrh;r++){
481 for (c=i_horizontal->
ncl;c<=i_horizontal->nch;c++){
483 if (i_horizontal->element[r][c]!=novalue) lines->
element[i_horizontal->element[r][c]]=
new_horizontal_line_from_raster(r,c,i_horizontal->
nrh,i_horizontal->
nch,nsres,ewres,blc_x,blc_y,i_horizontal->element[r][c],i_vertex->element[r][c],i_vertex->element[r][c+1]);
488 for (i=lines->
nl;i<=lines->nh;i++){
489 if (!lines->
element[i]) printf(
"Warning:: element %ld corresponding of lines was not assigned !!\n",i);
495 POLYGON *
new_pixel_from_raster(
long index,
long r,
long c ,
LINEVECTOR *lines,
LONGMATRIX *i_horizontal,
LONGMATRIX *i_vertical,
double nsres,
double ewres,
double blc_x,
double blc_y,
short print) {
526 nch=i_horizontal->
nch;
529 centroid=
new_point_from_raster(r,c,nrh,nch,
LX_CENTER,
LY_CENTER,nsres,ewres,blc_x,blc_y,index);
535 if ((!i_vertical->element[r][c]) || (i_vertical->element[r][c]<=0)) {
536 printf (
"Warning: left vertical line missing (polygon %ld) at r=%ld c=%ld \n ",index,r,c);
537 ledges->element[1]=i_vertical->element[r][c];
539 ledges->element[1]=i_vertical->element[r][c];
543 if ((!i_vertical->element[r][c+1]) || (i_vertical->element[r][c+1]<=0)) {
544 printf (
"Warning: right vertical line missing (polygon %ld) at r=%ld c=%ld \n ",index,r,c);
545 ledges->element[2]=i_vertical->element[r][c+1];
547 ledges->element[2]=i_vertical->element[r][c+1];
551 if ((!i_horizontal->element[r][c]) || (i_horizontal->element[r][c]<=0)) {
552 printf (
"Warning: top horizontal line missing (polygon %ld) at r=%ld c=%ld \n",index,r,c);
553 ledges->element[3]=i_horizontal->element[r][c];
555 ledges->element[3]=i_horizontal->element[r][c];
560 if ((!i_horizontal->element[r+1][c]) || (i_horizontal->element[r+1][c]<=0)) {
561 printf (
"Warning: bottom horizontal line missing (polygon %ld) at r=%ld c=%ld \n",index,r,c);
562 ledges->element[4]=i_horizontal->element[r+1][c];
564 ledges->element[4]=i_horizontal->element[r+1][c];
569 if (print==1) printf(
" Polygon : %ld [r= %ld , c = %ld ] lines (edges): %ld, %ld, %ld, %ld \n",index,r,c,ledges->element[1],ledges->element[2],ledges->element[3],ledges->element[4]);
575 if (print==1) printf(
" Polygon : %ld [r= %ld , c = %ld ] lines (edges): %ld, %ld, %ld, %ld was allocated \n",index,r,c,ledges->element[1],ledges->element[2],ledges->element[3],ledges->element[4]);
609 for(r=i_pixels->
nrl;r<=i_pixels->nrh;r++){
610 for(c=i_pixels->
ncl;c<=i_pixels->nch;c++){
611 if (i_pixels->element[r][c]!=novalue) count++;
619 for(r=i_pixels->
nrl;r<=i_pixels->nrh;r++){
620 for(c=i_pixels->
ncl;c<=i_pixels->nch;c++){
621 if (i_pixels->element[r][c]!=novalue) {
622 i=i_pixels->element[r][c];
623 pv->
element[i]=
new_pixel_from_raster(i,r,c,lines,i_horizontal,i_vertical,nsres, ewres,blc_x,blc_y,print);
633 for (i=pv->
nl;i<=pv->nh;i++){
634 if (!pv->
element[i]) printf(
"Warning:: element %ld corresponding of polygons was not assigned !!\n",i);
657 if ((indices->
nrh!=M->
nrh) || (indices->
nch!=M->
nch)) printf(
"Error:: in get_doublevector_from_doublematrix indices [%ld,%ld] and M [%ld,%ld] has different sizes! \n",indices->
nrh,indices->
nch,M->
nrh,M->
nch);
659 for (r=M->
nrl;r<=M->nrh;r++){
660 for (c=M->
ncl;c<=M->nch;c++){
661 if (M->element[r][c]!=novalue) cnt++;
668 for (i=v->
nl;i<=v->nh;i++){
671 if (cnt>M->
nrh*M->
nch) printf (
"Error:: Error:: in get_doublevector_from_doublematrix vector elements [%ld] execeed number doublematrix elements [%ld]!!\n",v->
nh,M->
nrh*M->
nch);
672 for (r=M->
nrl;r<=M->nrh;r++){
673 for (c=M->
ncl;c<=M->nch;c++){
674 i=indices->element[r][c];
675 if ((i<v->nl) || (i>v->
nh)) {
676 if (M->element[r][c]!=novalue) printf (
"Error:: in get_doublevector_from_doublevector index %ld exceeds size of matrix [%ld,%ld] at %ld,%ld \n",i,M->
nrh,M->
nch,r,c);
678 v->element[i]=M->element[r][c];
683 for (i=v->
nl;i<=v->nh;i++){
684 if (v->element[i]==
INIT_VALUE) printf(
"Error:: in get_doublevector_from_doublematrix index %ld was not assigned (%lf) !!\n",i,v->element[i]);
713 if ((indices->
nrh!=M->
nrh) || (indices->
nch!=M->
nch)) printf(
"Error:: in get_doublematrix_from_doublevector indices [%ld,%ld] and M [%ld,%ld] has different sizes! \n",indices->
nrh,indices->
nch,M->
nrh,M->
nch);
715 for (r=M->
nrl;r<=M->nrh;r++){
716 for (c=M->
ncl;c<=M->nch;c++) {
721 for (r=M->
nrl;r<=M->nrh;r++){
722 for (c=M->
ncl;c<=M->nch;c++){
723 i=indices->element[r][c];
725 if ((i>v->
nh) || (i<v->nl)) {
726 if (Mref->element[r][c]!=novalue) printf (
"Error:: in get_doublematrix_from_doublevector index %ld [%ld %ld] exceeds size of matrix [%ld,%ld] at %ld,%ld ",i,v->
nl,v->
nh,M->
nrh,M->
nch,r,c);
728 M->element[r][c]=v->element[i];
730 if ((M->element[r][c]==
INIT_VALUE) && (Mref->element[r][c]==novalue)) M->element[r][c]=novalue;
734 for (r=M->
nrl;r<=M->nrh;r++){
735 for (c=M->
ncl;c<=M->nch;c++){
736 if (M->element[r][c]==
INIT_VALUE) printf(
"Error:: in get_doublematrix_from_doublevector matrix element %ld, %ld [%ld,%ld] was not assigned \n",r,c,M->
nrh,M->
nch);
766 if (M==NULL)
return NULL;
815 for (l=mapseries->
ndl;l<=mapseries->ndh;l++){
822 for (c=mv->
ncl;c<=mv->nch;c++){
823 mv->element[l][c]=v->element[c];