Skip to content

Instantly share code, notes, and snippets.

@nathankerr
Created May 7, 2010 12:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nathankerr/393386 to your computer and use it in GitHub Desktop.
Save nathankerr/393386 to your computer and use it in GitHub Desktop.
Alternative Approaches to Parallel GIS Processing
/* remove all residential parcels */
parcel = parcels->data;
head = &(parcels->data);
while(parcel != NULL) {
if(strncmp(parcel->data[2], "R", 1) == 0) {
head = &(parcel->next);
parcel = parcel->next;
} else {
*head = parcel->next;
clusterGIS_Free_record(parcel);
parcel = *head;
}
}
/* Find the min distance */
employer = employers->data;
min = malloc(sizeof(double)*2);
global_min = malloc(sizeof(double)*2);
output = clusterGIS_Create_dataset();
while(employer != NULL) {
/* find the local min */
parcel = parcels->data;
GEOSDistance(employer->geometry, parcel->geometry, &min_distance);
min_distance_parcel = parcel;
while(parcel != NULL) {
if(strncmp(employer->data[2], parcel->data[2], 1) == 0) {
GEOSDistance(employer->geometry, parcel->geometry, &distance);
if(distance < min_distance) {
min_distance = distance;
min_distance_parcel = parcel;
}
}
parcel = parcel->next;
}
/* find the global min */
min[0] = atoi(min_distance_parcel->data[0]);
min[1] = min_distance;
MPI_Allreduce(min, global_min, 2, MPI_DOUBLE, min_distance_op, parcels_comm);
/* Add the min to the output dataset using front insertion*/
sprintf(output_csv, "\"%s\",\"%d\"\n", employer->data[0], (int) global_min[0]);
start = 0;
output_record = clusterGIS_Create_record_from_csv(output_csv, &start);
output_record->next = output->data;
output->data = output_record;
employer = employer->next;
}
if(rank == 0) {
int start = 0;
record = clusterGIS_Create_record_from_csv("97123897,POINT(0 0),C\n", &start);
record->next = dataset->data;
dataset->data = record;
}
box = GEOSWKTReader_read(reader, "POLYGON((-112.0859375 33.4349975585938,-112.0859375 33.4675445556641,-112.059799194336 33.4675445556641,-112.059799194336 33.4349975585938,-112.0859375 33.4349975585938))");
record = dataset->data;
head = &(dataset->data);
/* keep records that match the criteria, otherwise delete them */
while(record != NULL) {
char intersects;
intersects = GEOSIntersects(record->geometry, box);
if(intersects == 1) { /* record overlaps with box */
head = &(record->next);
record = record->next;
} else { /* no overlap */
*head = record->next;
clusterGIS_Free_record(record);
record = *head;
}
}
record = dataset->data;
head = &(dataset->data);
/* keep records that match the criteria, otherwise delete them */
while(record != NULL) {
if(atoi(record->data[0]) == 1008130) {
head = &(record->next);
record = record->next;
} else {
*head = record->next;
clusterGIS_Free_record(record);
record = *head;
}
}
record = dataset->data;
/* keep records that match the criteria, otherwise delete them */
while(record != NULL) {
if(atoi(record->data[0]) == 1008130) {
record->data[2] = "C";
}
record = record->next;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment