Skip to content

Instantly share code, notes, and snippets.

@nathankerr
Created May 7, 2010 12:59
Show Gist options
  • Select an option

  • Save nathankerr/393386 to your computer and use it in GitHub Desktop.

Select an option

Save nathankerr/393386 to your computer and use it in GitHub Desktop.

Revisions

  1. nathankerr created this gist May 7, 2010.
    50 changes: 50 additions & 0 deletions clusterGIS-chaining.c
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,50 @@
    /* 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;
    }
    6 changes: 6 additions & 0 deletions clusterGIS-create.c
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,6 @@
    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;
    }
    19 changes: 19 additions & 0 deletions clusterGIS-filter.c
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    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;
    }
    }
    13 changes: 13 additions & 0 deletions clusterGIS-read.c
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,13 @@
    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;
    }
    }
    10 changes: 10 additions & 0 deletions clusterGIS-update.c
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    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;
    }