我有一个在std :: string中形成的查询字符串,查询有4个点,每个点都有一个x,y,每个点都是double数据类型。
如何连接字符串以将4个点(8个变量)放在c ++中的查询中
'MULTIPOINT(16.17951 47.85549, 16.17951 47.85549, 16.17951 47.85549, 16.17951 47.85549)';
这是查询的形式:
string query = "SELECT * from areas WHERE st_contains(ST_ConvexHull(areas.GEOMETRY),st_mpointfromtext('MULTIPOINT(16.17951 47.85549, 16.17951 47.85549, 16.17951 47.85549, 16.17951 47.85549)',4326));";
double x1 = 6.17951, x2 = 6.17951, x3 = 6.17951, x4 = 6.17951;
double y1 = 7.85549, y2 = 7.85549, y3 = 7.85549, y4 = 7.85549;
/* std::string query = "SELECT * from areas WHERE st_contains(ST_ConvexHull(areas.GEOMETRY),st_mpointfromtext('MULTIPOINT("
+ to_string(x1) + " " + to_string(y1) + ", "
+ to_string(x2) + " " + to_string(y2) + ", "
+ to_string(x3) + " " + to_string(y3) + ", "
+ to_string(x4) + " " + to_string(y4) + "',4326));";
*/
string query = "SELECT * from areas WHERE st_contains(ST_ConvexHull(areas.GEOMETRY),st_mpointfromtext('MULTIPOINT(6.17951 7.85549, 6.17951 7.85549, 6.17951 7.85549, 6.17951 7.85549)',4326));";
答案 0 :(得分:1)
根据您的输入类型,有几个选项。
如果您有std::string mp = "'MULTIPOINT(16.17951 47.85549, 16.17951 47.85549, 16.17951 47.85549, 16.17951 47.85549)'";
std::string query = "SELECT * from areas WHERE st_contains(ST_ConvexHull(areas.GEOMETRY),st_mpointfromtext(" + mp + ",4326));";
,请执行以下操作:
doubles
如果您的输入为C++11
,并且您使用std::string query = "SELECT * from areas WHERE st_contains(ST_ConvexHull(areas.GEOMETRY),st_mpointfromtext('MULTIPOINT("
+ std::to_string(x1) + " " + std::to_string(y1) + ", "
+ std::to_string(x2) + " " + std::to_string(y2) + ", "
+ std::to_string(x3) + " " + std::to_string(y3) + ", "
+ std::to_string(x4) + " " + std::to_string(y4) + ")',4326));";
,那么您可以这样做:
export class XComponent{
someProp: string;
someList: string[];
someFn(){
this.someService.subscribe(
data=>{
this.someProp = data.prop;
this.someList = data.list;
}
);
}
}