|
@@ -68,20 +68,23 @@ int patch_density(int fd, char **par, struct area_entry *ad, double *result)
|
|
double EW_DIST1, EW_DIST2, NS_DIST1, NS_DIST2;
|
|
double EW_DIST1, EW_DIST2, NS_DIST1, NS_DIST2;
|
|
int mask_fd = -1, *mask_buf, *mask_sup, null_count = 0;
|
|
int mask_fd = -1, *mask_buf, *mask_sup, null_count = 0;
|
|
|
|
|
|
|
|
+ G_debug(1, "begin patch_density() index");
|
|
|
|
+
|
|
Rast_set_c_null_value(&complete_value, 1);
|
|
Rast_set_c_null_value(&complete_value, 1);
|
|
Rast_get_cellhd(ad->raster, "", &hd);
|
|
Rast_get_cellhd(ad->raster, "", &hd);
|
|
|
|
|
|
- sup = Rast_allocate_c_buf();
|
|
|
|
-
|
|
|
|
/* open mask if needed */
|
|
/* open mask if needed */
|
|
if (ad->mask == 1) {
|
|
if (ad->mask == 1) {
|
|
if ((mask_fd = open(ad->mask_name, O_RDONLY, 0755)) < 0)
|
|
if ((mask_fd = open(ad->mask_name, O_RDONLY, 0755)) < 0)
|
|
return 0;
|
|
return 0;
|
|
|
|
+
|
|
mask_buf = malloc(ad->cl * sizeof(int));
|
|
mask_buf = malloc(ad->cl * sizeof(int));
|
|
mask_sup = malloc(ad->cl * sizeof(int));
|
|
mask_sup = malloc(ad->cl * sizeof(int));
|
|
}
|
|
}
|
|
|
|
|
|
- /*calculate distance */
|
|
|
|
|
|
+ sup = Rast_allocate_c_buf();
|
|
|
|
+
|
|
|
|
+ /* calculate distance */
|
|
G_begin_distance_calculations();
|
|
G_begin_distance_calculations();
|
|
/* EW Dist at North edge */
|
|
/* EW Dist at North edge */
|
|
EW_DIST1 = G_distance(hd.east, hd.north, hd.west, hd.north);
|
|
EW_DIST1 = G_distance(hd.east, hd.north, hd.west, hd.north);
|
|
@@ -93,15 +96,15 @@ int patch_density(int fd, char **par, struct area_entry *ad, double *result)
|
|
NS_DIST2 = G_distance(hd.west, hd.north, hd.west, hd.south);
|
|
NS_DIST2 = G_distance(hd.west, hd.north, hd.west, hd.south);
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- /*calculate number of patch */
|
|
|
|
|
|
+ /* calculate number of patch */
|
|
|
|
|
|
for (i = 0; i < ad->rl; i++) {
|
|
for (i = 0; i < ad->rl; i++) {
|
|
buf = RLI_get_cell_raster_row(fd, i + ad->y, ad);
|
|
buf = RLI_get_cell_raster_row(fd, i + ad->y, ad);
|
|
|
|
+
|
|
if (i > 0) {
|
|
if (i > 0) {
|
|
sup = RLI_get_cell_raster_row(fd, i - 1 + ad->y, ad);
|
|
sup = RLI_get_cell_raster_row(fd, i - 1 + ad->y, ad);
|
|
}
|
|
}
|
|
|
|
+
|
|
/* mask values */
|
|
/* mask values */
|
|
if (ad->mask == 1) {
|
|
if (ad->mask == 1) {
|
|
int k;
|
|
int k;
|
|
@@ -201,5 +204,6 @@ int patch_density(int fd, char **par, struct area_entry *ad, double *result)
|
|
*result = -1;
|
|
*result = -1;
|
|
|
|
|
|
G_free(sup);
|
|
G_free(sup);
|
|
|
|
+
|
|
return RLI_OK;
|
|
return RLI_OK;
|
|
}
|
|
}
|