int main(void) { GEOSWKTReader *reader; GEOSGeometry *mp; GEOSGeometry *p; const GEOSPreparedGeometry *prep_mp; unsigned long int i; unsigned long int count = 1e6; initGEOS(NULL, NULL); reader = GEOSWKTReader_create(); mp = GEOSWKTReader_read(reader, "MULTIPOLYGON(((0 0, 10 0, 10 10, 0 10, 0 0)))"); p = GEOSWKTReader_read(reader, "POLYGON((2 2, 6 2, 6 6, 2 6, 2 2))"); assert(GEOSisValid(mp)); assert(GEOSisValid(p)); prep_mp = GEOSPrepare(mp); for (i=0; i<count; i++) { if ( !(i%100) ) printf("%lu iterations\n", i); /* does not leak */ /* GEOSContains(mp, p); */ /* leaks */ GEOSPreparedContains(prep_mp, p); } printf("%lu iterations (END)\n", i); return 0; }
int main(int argc, char** argv) { GEOSGeometry* box; GEOSWKTReader* reader; clusterGIS_dataset* dataset; clusterGIS_record* record; clusterGIS_record** head; GEOSGeometry* record_geometry; int rank; double startprocessing; if(argc != 3) { fprintf(stderr, "Usage %s input output", argv[0]); exit(1); } clusterGIS_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &rank); reader = GEOSWKTReader_create(); 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))"); dataset = clusterGIS_Load_csv_distributed(MPI_COMM_WORLD, argv[1]); clusterGIS_Create_wkt_geometries(dataset, 1); startprocessing = MPI_Wtime(); record = dataset->data; head = &(dataset->data); /* keep records that match the criteria, otherwise delete them */ while(record != NULL) { char intersects; /*record_geometry = GEOSWKTReader_read(reader, record->data[1]); if(record_geometry == NULL) { fprintf(stderr, "%d: parse error\n", rank); MPI_Abort(MPI_COMM_WORLD, 2); }*/ intersects = GEOSIntersects(record->geometry, box); if(intersects == 2) { fprintf(stderr, "%d: error with overlap function\n", rank); MPI_Abort(MPI_COMM_WORLD, 2); } if(intersects == 1) { /* record overlaps with box */ head = &(record->next); record = record->next; } else if(intersects == 0) { /* no overlap */ *head = record->next; clusterGIS_Free_record(record); record = *head; } else { /* should never get here */ MPI_Abort(MPI_COMM_WORLD, 2); } } printf("%d: processing time %5.2fs\n", rank, MPI_Wtime() - startprocessing); clusterGIS_Write_csv_distributed(MPI_COMM_WORLD, argv[2], dataset); clusterGIS_Finalize(); return 0; }
int main(int argc, const char **argv) { /* initialize apr_getopt_t */ apr_getopt_t *opt; const char *configfile=NULL; #ifndef USE_FORK apr_thread_t **threads; apr_threadattr_t *thread_attrs; #endif const char *tileset_name=NULL; const char *tileset_transfer_name=NULL; const char *grid_name = NULL; int *zooms = NULL;//[2]; double *extent = NULL;//[4]; int optch; int rv,n; const char *old = NULL; const char *optarg; apr_table_t *argdimensions; char *dimkey=NULL, *dimvalue=NULL,*key, *last, *optargcpy=NULL; int keyidx; int *metasizes = NULL;//[2]; int metax=-1,metay=-1; #ifdef USE_CLIPPERS const char *ogr_where = NULL; const char *ogr_layer = NULL; const char *ogr_sql = NULL; const char *ogr_datasource = NULL; #endif apr_initialize(); (void) signal(SIGINT,handle_sig_int); apr_pool_create(&ctx.pool,NULL); mapcache_context_init(&ctx); ctx.process_pool = ctx.pool; #ifndef USE_FORK apr_thread_mutex_create((apr_thread_mutex_t**)&ctx.threadlock,APR_THREAD_MUTEX_DEFAULT,ctx.pool); #else ctx.threadlock = NULL; #endif cfg = mapcache_configuration_create(ctx.pool); ctx.config = cfg; ctx.log= mapcache_context_seeding_log; apr_getopt_init(&opt, ctx.pool, argc, argv); seededtiles=seededtilestot=queuedtilestot=0; mapcache_gettimeofday(&starttime,NULL); lastlogtime=starttime; argdimensions = apr_table_make(ctx.pool,3); /* parse the all options based on opt_option[] */ while ((rv = apr_getopt_long(opt, seed_options, &optch, &optarg)) == APR_SUCCESS) { switch (optch) { case 'h': return usage(argv[0],NULL); break; case 'f': force = 1; break; case 'q': quiet = 1; break; case 'v': verbose = 1; break; case 'c': configfile = optarg; break; case 'g': grid_name = optarg; break; case 't': tileset_name = optarg; break; case 'x': tileset_transfer_name = optarg; break; case 'm': if(!strcmp(optarg,"delete")) { mode = MAPCACHE_CMD_DELETE; } else if(!strcmp(optarg,"transfer")){ mode = MAPCACHE_CMD_TRANSFER; } else if(strcmp(optarg,"seed")){ return usage(argv[0],"invalid mode, expecting \"seed\", \"delete\" or \"transfer\""); } else { mode = MAPCACHE_CMD_SEED; } break; case 'n': nthreads = (int)strtol(optarg, NULL, 10); break; case 'e': if ( MAPCACHE_SUCCESS != mapcache_util_extract_double_list(&ctx, (char*)optarg, ",", &extent, &n) || n != 4 || extent[0] >= extent[2] || extent[1] >= extent[3] ) { return usage(argv[0], "failed to parse extent, expecting comma separated 4 doubles"); } break; case 'z': if ( MAPCACHE_SUCCESS != mapcache_util_extract_int_list(&ctx, (char*)optarg, ",", &zooms, &n) || n != 2 || zooms[0] > zooms[1]) { return usage(argv[0], "failed to parse zooms, expecting comma separated 2 ints"); } else { minzoom = zooms[0]; maxzoom = zooms[1]; } break; case 'M': if ( MAPCACHE_SUCCESS != mapcache_util_extract_int_list(&ctx, (char*)optarg, ",", &metasizes, &n) || n != 2 || metasizes[0] <= 0 || metasizes[1] <=0) { return usage(argv[0], "failed to parse metasize, expecting comma separated 2 positive ints (e.g. -M 8,8"); } else { metax = metasizes[0]; metay = metasizes[1]; } break; case 'o': old = optarg; break; case 'D': optargcpy = apr_pstrdup(ctx.pool,optarg); keyidx = 0; for (key = apr_strtok(optargcpy, "=", &last); key != NULL; key = apr_strtok(NULL, "=", &last)) { if(keyidx == 0) { dimkey = key; } else { dimvalue = key; } keyidx++; } if(keyidx!=2 || !dimkey || !dimvalue || !*dimkey || !*dimvalue) { return usage(argv[0], "failed to parse dimension, expecting DIMNAME=DIMVALUE"); } apr_table_set(argdimensions,dimkey,dimvalue); break; #ifdef USE_CLIPPERS case 'd': ogr_datasource = optarg; break; case 's': ogr_sql = optarg; break; case 'l': ogr_layer = optarg; break; case 'w': ogr_where = optarg; break; #endif } } if (rv != APR_EOF) { return usage(argv[0],"bad options"); } if( ! configfile ) { return usage(argv[0],"config not specified"); } else { mapcache_configuration_parse(&ctx,configfile,cfg,0); if(ctx.get_error(&ctx)) return usage(argv[0],ctx.get_error_message(&ctx)); mapcache_configuration_post_config(&ctx,cfg); if(ctx.get_error(&ctx)) return usage(argv[0],ctx.get_error_message(&ctx)); } #ifdef USE_CLIPPERS if(extent && ogr_datasource) { return usage(argv[0], "cannot specify both extent and ogr-datasource"); } if( ogr_sql && ( ogr_where || ogr_layer )) { return usage(argv[0], "ogr-where or ogr_layer cannot be used in conjunction with ogr-sql"); } if(ogr_datasource) { OGRDataSourceH hDS = NULL; OGRLayerH layer = NULL; OGRRegisterAll(); hDS = OGROpen( ogr_datasource, FALSE, NULL ); if( hDS == NULL ) { printf( "OGR Open failed\n" ); exit( 1 ); } if(ogr_sql) { layer = OGR_DS_ExecuteSQL( hDS, ogr_sql, NULL, NULL); if(!layer) { return usage(argv[0],"aborting"); } } else { int nLayers = OGR_DS_GetLayerCount(hDS); if(nLayers>1 && !ogr_layer) { return usage(argv[0],"ogr datastore contains more than one layer. please specify which one to use with --ogr-layer"); } else { if(ogr_layer) { layer = OGR_DS_GetLayerByName(hDS,ogr_layer); } else { layer = OGR_DS_GetLayer(hDS,0); } if(!layer) { return usage(argv[0],"aborting"); } if(ogr_where) { if(OGRERR_NONE != OGR_L_SetAttributeFilter(layer, ogr_where)) { return usage(argv[0],"aborting"); } } } } if((nClippers=OGR_L_GetFeatureCount(layer, TRUE)) == 0) { return usage(argv[0],"no features in provided ogr parameters, cannot continue"); } initGEOS(notice, log_and_exit); clippers = (const GEOSPreparedGeometry**)malloc(nClippers*sizeof(GEOSPreparedGeometry*)); OGRFeatureH hFeature; GEOSWKTReader *geoswktreader = GEOSWKTReader_create(); OGR_L_ResetReading(layer); extent = apr_pcalloc(ctx.pool,4*sizeof(double)); int f=0; while( (hFeature = OGR_L_GetNextFeature(layer)) != NULL ) { OGRGeometryH geom = OGR_F_GetGeometryRef(hFeature); if(!geom || !OGR_G_IsValid(geom)) continue; char *wkt; OGR_G_ExportToWkt(geom,&wkt); GEOSGeometry *geosgeom = GEOSWKTReader_read(geoswktreader,wkt); free(wkt); clippers[f] = GEOSPrepare(geosgeom); //GEOSGeom_destroy(geosgeom); OGREnvelope ogr_extent; OGR_G_GetEnvelope (geom, &ogr_extent); if(f == 0) { extent[0] = ogr_extent.MinX; extent[1] = ogr_extent.MinY; extent[2] = ogr_extent.MaxX; extent[3] = ogr_extent.MaxY; } else { extent[0] = MAPCACHE_MIN(ogr_extent.MinX, extent[0]); extent[1] = MAPCACHE_MIN(ogr_extent.MinY, extent[1]); extent[2] = MAPCACHE_MAX(ogr_extent.MaxX, extent[2]); extent[3] = MAPCACHE_MAX(ogr_extent.MaxY, extent[3]); } OGR_F_Destroy( hFeature ); f++; } nClippers = f; } #endif if( ! tileset_name ) { return usage(argv[0],"tileset not specified"); } else { tileset = mapcache_configuration_get_tileset(cfg,tileset_name); if(!tileset) { return usage(argv[0], "tileset not found in configuration"); } if( ! grid_name ) { grid_link = APR_ARRAY_IDX(tileset->grid_links,0,mapcache_grid_link*); } else {
bool Geometry::FromWKT(const char* wkt) { GEOSWKTReader *wkt_reader = GEOSWKTReader_create(); geos_geom_ = GEOSWKTReader_read(wkt_reader, wkt); return geos_geom_ == NULL ? false : true; }