Created
April 15, 2014 20:16
-
-
Save thejefflarson/10768422 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// not checking error codes cause YOLO | |
void | |
plot_dots(OGRLayerH layer, cairo_t *ctx, simplet_map_t *map, const char *color){ | |
OGRFeatureH feature; | |
while((feature = OGR_L_GetNextFeature(layer))){ | |
int num = OGR_F_GetFieldAsInteger(feature, 0); | |
OGRGeometryH geom = OGR_F_GetGeometryRef(feature); | |
OGR_G_TransformTo(geom, map->proj); | |
OGREnvelope env; | |
OGR_G_GetEnvelope(geom, &env); | |
double width = env.MaxX - env.MinX; | |
double height = env.MaxY - env.MinY; | |
while(num > 0){ | |
double x = env.MinX + drand48() * width; | |
double y = env.MinY + drand48() * height; | |
OGRGeometryH *pt = OGR_G_CreateGeometry(wkbPoint); | |
printf("."); | |
OGR_G_AddPoint_2D(pt, x, y); | |
if(OGR_G_Within(pt, geom)) { | |
printf("%d", num); | |
cairo_move_to(ctx, x, y); | |
double rad = 0.5, dy = 0; | |
cairo_save(ctx); | |
cairo_device_to_user_distance(ctx, &rad, &dy); | |
cairo_new_path(ctx); | |
cairo_arc(ctx, x - rad / 2, y - rad / 2, rad, 0., 2 * SIMPLET_PI); | |
cairo_user_to_device_distance(ctx, &y, &x); | |
unsigned int r, g, b, a; | |
simplet_parse_color(color, &r, &g, &b, &a); | |
cairo_set_source_rgba(ctx, r / 255.0, g / 255.0, b / 255.0, a / 255.0); | |
cairo_fill(ctx); | |
cairo_close_path(ctx); | |
cairo_restore(ctx); | |
num--; | |
} | |
fflush(stdout); | |
OGR_G_DestroyGeometry(pt); | |
} | |
puts(""); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment