int mapObj_queryByShape(mapObj *self, shapeObj *shape) { msInitQuery(&(self->query)); self->query.type = MS_QUERY_BY_SHAPE; self->query.mode = MS_QUERY_MULTIPLE; self->query.shape = (shapeObj *) malloc(sizeof(shapeObj)); msInitShape(self->query.shape); msCopyShape(shape, self->query.shape); return msQueryByShape(self); }
/* for geomtransform, we don't have the mapObj */ shapeObj *msV8TransformShape(shapeObj *shape, const char* filename) { TryCatch try_catch; Isolate *isolate = Isolate::GetCurrent(); V8Context *v8context = (V8Context*)isolate->GetData(); HandleScope handle_scope(v8context->isolate); /* execution context */ Local<Context> context = Local<Context>::New(v8context->isolate, v8context->context); Context::Scope context_scope(context); Handle<Object> global = context->Global(); Shape* shape_ = new Shape(shape); shape_->setLayer(v8context->layer); shape_->disableMemoryHandler(); Handle<Value> ext = External::New(shape_); global->Set(String::New("shape"), Shape::Constructor()->NewInstance(1, &ext)); msV8ExecuteScript(filename); Handle<Value> value = global->Get(String::New("geomtransform")); if (value->IsUndefined()) { msDebug("msV8TransformShape: Function 'geomtransform' is missing.\n"); return NULL; } Handle<Function> func = Handle<Function>::Cast(value); Handle<Value> result = func->Call(global, 0, 0); if (result.IsEmpty() && try_catch.HasCaught()) { msV8ReportException(&try_catch); } if (!result.IsEmpty() && result->IsObject()) { Handle<Object> obj = result->ToObject(); if (obj->GetConstructorName()->Equals(String::New("shapeObj"))) { Shape* new_shape = ObjectWrap::Unwrap<Shape>(result->ToObject()); if (shape == new_shape->get()) { shapeObj *new_shape_ = (shapeObj *)msSmallMalloc(sizeof(shapeObj)); msInitShape(new_shape_); msCopyShape(shape, new_shape_); return new_shape_; } else { new_shape->disableMemoryHandler(); return new_shape->get(); } } } return NULL; }
shapeObj* msSmoothShapeSIA(shapeObj *shape, int ss, int si, char *preprocessing) { int i, j; pointObj *p; double *coeff; shapeObj *newShape; newShape = (shapeObj *) msSmallMalloc(sizeof (shapeObj)); msInitShape(newShape); if (ss < 3) ss = 3; if (si < 1) si = 1; /* Apply preprocessing */ if (preprocessing) { if (strcasecmp(preprocessing, "all") == 0) processShapePathDistance(shape, MS_TRUE); else if (strcasecmp(preprocessing, "angle") == 0) processShapePathDistance(shape, MS_FALSE); } p = (pointObj *) msSmallMalloc(ss*sizeof(pointObj)); coeff = (double *) msSmallMalloc(ss*sizeof (double)); for (i=0;i<si;++i) { shapeObj initialShape; if (si > 1 && i>0) { msInitShape(&initialShape); msCopyShape(shape, &initialShape); /* Clean our shape object */ for (j=0; j < newShape->numlines; ++j) free(newShape->line[j].point); newShape->numlines = 0; if (newShape->line) { free(newShape->line); newShape->line = NULL; } shape = &initialShape; } for (j=0;j<shape->numlines;++j) { int k, ws, res; lineObj newLine = {0,NULL}; lineWindow lw; /* determine if we can use the ss for this line */ ws = ss; if (ws >= shape->line[j].numpoints) { ws = shape->line[j].numpoints-1; } if (ws%2==0) ws-=1; initLineWindow(&lw, &shape->line[j], ws); msAddLine(newShape, &newLine); coeff[lw.index] = 1; for (k=0;k<lw.index;++k) { coeff[lw.index+(k+1)] = coeff[lw.index-k]/2; coeff[lw.index-(k+1)] = coeff[lw.index+k]/2; } while ((res = nextLineWindow(&lw)) != MS_DONE) { double sum_x=0, sum_y=0, sum = 0; pointObj point; int k = 0; if (res == MS_FALSE) { /* invalid window */ msAddPointToLine(&newShape->line[j], lw.points[lw.index]); continue; } /* Apply Coefficient */ p[lw.index] = *lw.points[lw.index]; for (k=0; k<lw.index; ++k) { p[lw.index-(k+1)] = *lw.points[lw.index-(k+1)]; p[lw.index-(k+1)].x *= coeff[lw.index-(k+1)]; p[lw.index-(k+1)].y *= coeff[lw.index-(k+1)]; p[lw.index+(k+1)] = *lw.points[lw.index+(k+1)]; p[lw.index+(k+1)].x *= coeff[lw.index+(k+1)]; p[lw.index+(k+1)].y *= coeff[lw.index+(k+1)]; } for (k=0; k<lw.size; ++k) { sum += coeff[k]; sum_x += p[k].x; sum_y += p[k].y; } point.x = sum_x/sum; point.y = sum_y/sum; msAddPointToLine(&newShape->line[j], &point); } freeLineWindow(&lw); } if (i>0) { msFreeShape(shape); shape = newShape; } } free(p); free(coeff); return newShape; }
/* Pre-Processing of a shape. It modifies the shape by adding intermediate points where a loop is detected to improve the smoothing result. */ static int processShapePathDistance(shapeObj *shape, int force) { shapeObj initialShape, *newShape; int i; /* initial shape to process */ msInitShape(&initialShape); msCopyShape(shape, &initialShape); newShape = shape; /* we modify the shape object directly */ shape = &initialShape; /* Clean our shape object */ for (i= 0; i < newShape->numlines; i++) free(newShape->line[i].point); newShape->numlines = 0; if (newShape->line) free(newShape->line); for (i=0;i<shape->numlines;++i) { const int windowSize = 5; int res; lineWindow lw; lineObj line = {0, NULL}; initLineWindow(&lw, &shape->line[i], windowSize); msAddLine(newShape, &line); while ((res = nextLineWindow(&lw)) != MS_DONE) { double ratio = 0; pointObj point; if (lw.lineIsRing && lw.pos==lw.line->numpoints-1) { point = newShape->line[i].point[0]; msAddPointToLine(&newShape->line[i], &point); continue; } if (res == MS_FALSE) { /* invalid window */ msAddPointToLine(&newShape->line[i], lw.points[lw.index]); continue; } if (!force) ratio = computePathDistanceRatio(lw.points, windowSize); if (force || (ratio > 1.3)) { point.x = (lw.line->point[lw.pos].x + lw.points[lw.index-1]->x)/2; point.y = (lw.line->point[lw.pos].y + lw.points[lw.index-1]->y)/2; msAddPointToLine(&newShape->line[i], &point); } point = lw.line->point[lw.pos]; msAddPointToLine(&newShape->line[i], &point); if (force || (ratio > 1.3)) { point.x = (lw.line->point[lw.pos].x + lw.points[lw.index+1]->x)/2; point.y = (lw.line->point[lw.pos].y + lw.points[lw.index+1]->y)/2; msAddPointToLine(&newShape->line[i], &point); } } freeLineWindow(&lw); } msFreeShape(shape); return MS_SUCCESS; }