Permalink
Browse files

Compute n_geometry early and skip shapes where n_geometry=0.

  • Loading branch information...
sdlime committed Feb 7, 2017
1 parent 010dc2a commit a62477ea3009b92ea6ff4048ca94ca8e0cb2aebd
Showing with 37 additions and 15 deletions.
  1. +37 −15 mapmvt.c
@@ -156,6 +156,9 @@ int mvtWriteShape( layerObj *layer, shapeObj *shape, VectorTile__Tile__Layer *mv
VectorTile__Tile__Feature *mvt_feature;
int i,j,iout;
value_lookup *value;
long int n_geometry;

/* could consider an intersection test here */

if(mvtTransformShape(shape, unbuffered_bbox, layer->type, mvt_layer->extent) != MS_SUCCESS) {
return MS_SUCCESS; /* degenerate shape */
@@ -164,6 +167,23 @@ int mvtWriteShape( layerObj *layer, shapeObj *shape, VectorTile__Tile__Layer *mv
return MS_SUCCESS; /* no features left after clipping */
}

n_geometry = 0;
if(layer->type == MS_LAYER_POINT) {
for(i=0;i<shape->numlines;i++)
n_geometry += shape->line[i].numpoints * 2;
if(mvt_feature->n_geometry)
n_geometry++; /* one MOVETO */
} else if(layer->type == MS_LAYER_LINE) {
for(i=0;i<shape->numlines;i++)
if(shape->line[i].numpoints >= 2) n_geometry += 2 + shape->line[i].numpoints * 2; /* one MOVETO, one LINETO */
} else {
for(i=0;i<shape->numlines;i++)
if(shape->line[i].numpoints >= 4) n_geometry += 3 + shape->line[i].numpoints * 2; /* one MOVETO, one LINETO, one CLOSEPATH */
}

fprintf(stderr, "n_geometry=%ld\n", n_geometry);
if(n_geometry == 0) return MS_SUCCESS;

mvt_layer->features[mvt_layer->n_features++] = msSmallMalloc(sizeof(VectorTile__Tile__Feature));
mvt_feature = mvt_layer->features[mvt_layer->n_features-1];
vector_tile__tile__feature__init(mvt_feature);
@@ -222,23 +242,23 @@ int mvtWriteShape( layerObj *layer, shapeObj *shape, VectorTile__Tile__Layer *mv
}

/* output geom */
mvt_feature->n_geometry = 0;
if(layer->type == MS_LAYER_POINT) {
for(i=0;i<shape->numlines;i++)
mvt_feature->n_geometry += shape->line[i].numpoints * 2;
if(mvt_feature->n_geometry)
mvt_feature->n_geometry++; /* one MOVETO */
} else if(layer->type == MS_LAYER_LINE) {
for(i=0;i<shape->numlines;i++)
if(shape->line[i].numpoints >= 2) mvt_feature->n_geometry += 2 + shape->line[i].numpoints * 2; /* one MOVETO, one LINETO */
} else {
for(i=0;i<shape->numlines;i++)
if(shape->line[i].numpoints >= 4) mvt_feature->n_geometry += 3 + shape->line[i].numpoints * 2; /* one MOVETO, one LINETO, one CLOSEPATH */
}
// mvt_feature->n_geometry = 0;
// if(layer->type == MS_LAYER_POINT) {
// for(i=0;i<shape->numlines;i++)
// mvt_feature->n_geometry += shape->line[i].numpoints * 2;
// if(mvt_feature->n_geometry)
// mvt_feature->n_geometry++; /* one MOVETO */
// } else if(layer->type == MS_LAYER_LINE) {
// for(i=0;i<shape->numlines;i++)
// if(shape->line[i].numpoints >= 2) mvt_feature->n_geometry += 2 + shape->line[i].numpoints * 2; /* one MOVETO, one LINETO */
// } else {
// for(i=0;i<shape->numlines;i++)
// if(shape->line[i].numpoints >= 4) mvt_feature->n_geometry += 3 + shape->line[i].numpoints * 2; /* one MOVETO, one LINETO, one CLOSEPATH */
// }

mvt_feature->n_geometry = n_geometry;
mvt_feature->geometry = msSmallMalloc(mvt_feature->n_geometry * sizeof(uint32_t));

fprintf(stderr, "n_geometry=%ld\n", mvt_feature->n_geometry);

if(layer->type == MS_LAYER_POINT) {
int idx=0, lastx=0, lasty=0;
mvt_feature->geometry[idx++] = COMMAND(MOVETO, mvt_feature->n_geometry-1);
@@ -305,6 +325,8 @@ int msMVTWriteFromQuery( mapObj *map, outputFormatObj *format, int sendheaders )
VectorTile__Tile mvt_tile = VECTOR_TILE__TILE__INIT;
mvt_tile.layers = msSmallCalloc(map->numlayers,sizeof(VectorTile__Tile__Layer*));

fprintf(stderr, "tile center: %0.6f %0.6f\n", (map->extent.minx+map->extent.maxx)/2, (map->extent.miny+map->extent.maxy)/2);

for( iLayer = 0; iLayer < map->numlayers; iLayer++ ) {
int status=MS_SUCCESS;
layerObj *layer = GET_LAYER(map, iLayer);

0 comments on commit a62477e

Please sign in to comment.