遥感影像镶嵌及实现(三)

遥感影像镶嵌及实现(一);遥感影像镶嵌及实现(二);遥感影像镶嵌及实现(四);遥感影像镶嵌及实现(五);遥感影像镶嵌及实现(六)。
主要内容:

1 获取重叠区域: 利用获取的影像有效区域,通过GDAL OGRPolygon 分别构建两幅影像几何体OGRGeometry ,求取两幅影像有效区域的重叠部分;
2 获取有效区域交点:利用获取的影像有效区域,通过GDAL OGRLineString分别构建两幅影像的几何体OGRGeometry,求取两幅影像有效区域的交点;
3 获取有效区域交叉点(重叠区域镶嵌线的起始、结束点):找到交点中距离最远的两个点,分别判断这两个点对两幅影像的进出性,来作为起始、结束的依据。
4 demo
1 获取重叠区域
//使用有效区域构建wkbPolygon几何体 //构建几何级1 string wkbFirst = "POLYGON((x0 y0,x1 y1,...,xn yn,x0 y0))"; //注意回路 char *pszFirst = (char*)wkbFirst.data(); OGRGeometry *poGeometryFirst = OGRGeometryFactory::createGeometry(wkbPolygon); poGeometryFirst ->importFromWkt((char**)&(pszFirst )); //构建几何体2 ... OGRGeometry *poGeometrySencond = OGRGeometryFactory::createGeometry(wkbPolygon); ... //求交 if(poGeometryFirst ->Within(poGeometrySencond ) || poGeometryFirst ->Contains(poGeometrySencond ) ){} char *pszInsectionWkt = NULL; char *pszInsectionJson = NULL; int iPointCount = 0; Json::Reader reader; Json::Value root; if(poGeometryFirst ->Intersects(poGeometrySencond )) { OGRGeometry *poGeometryInters = poGeometryFirst ->Intersection(poGeometrySencond ) if(poGeometryInters != NULL && !poGeometryInters->IsEmpty()) { pszInsectionJson = poGeometryInters->exportToJson(); if(reader.parse(pszInsectionJson,root)) { iPointCount = root["coordinates"][0].size(); //获取点数,导出 } else { } } } //导出点 vector ValidPoint; Point iPoint; for(int i = 0; i < iPointCount-1; i++) { iPoint.x = root["coordinates"][0][i][0].asDouble(); iPoint.y = root["coordinates"][0][i][1].asDouble(); ValidPoint.push_back(iPoint); }

后续使用重叠区域的点,查找镶嵌线。
2 获取有效区域交点
(1)LINESTRING方法
使用有效区域点构建wkbLineString,与1中相似;
string wkbFirst = "LINESTRING(x0 y0,x1 y1,...,xn yn,x0 y0)"; //注意回路 OGRGeometry *poGeometryFirst = OGRGeometryFactory::createGeometry(wkbLineString); ... if(reader.parse(pszInsectionJson,root)) { iPointCount = root["coordinates"].size(); //获取点数,导出 } ... //导出点 vector ValidPoint; Point iPoint; for(int i = 0; i < iPointCount-1; i++) { iPoint.x = root["coordinates"][i][0].asDouble(); iPoint.y = root["coordinates"][i][1].asDouble(); ValidPoint.push_back(iPoint); }

(2)使用const OGRLineString* OGRGeometry::toLineString() const
直接将1中的wkbPolygon几何体Down-cast to OGRLineString*。
后续使用交点,查找镶嵌线的起始、结束点。
3 获取有效区域交叉点(重叠区域镶嵌线的起始、结束点)
(1)从所有交点中找到距离最大的两个点,作为交叉点
迭代距离,找到最大点对。
(2)判断交叉点对每幅影像区域的进出性
<1>交叉点非有效区域点
交叉点必定在某两个有效区域指点之间,顺时针(查找有效区域时,由左上顺时针方向搜索)迭代有效区域点,找到交叉点所在的有效区域点线段两端,标记点index。如果使用斜率判断,注意垂直的情况哦!
<2>交叉点与有效区域点重合
判断下一个有效区域点与另一幅影像有效区域的关系。如果在内部,那个交叉点为入点(进点),而另一个交叉点为出点。
4 demo
影像1有效区域wkbPolygon:有效区域点:9509;压缩后:29
POLYGON((355311.975285321 4434616.664178752,394375.898863577 4425437.788583105,393843.237144360 4423154.730624536,393934.990777613 4423081.122712593,394677.078684115 4423070.830476722,395672.957261133 4422623.153613895,398450.480138563 4422175.777931183,401298.148822493 4421390.986072093,390683.292026611 4375703.636607970,379706.713504453 4378253.396138636,379002.853626275 4378601.921024554,377418.593859200 4378747.433146919,370137.256780411 4380867.566228855,366694.653063409 4381432.555968507,364209.755754306 4382319.768711558,360693.085284871 4382864.669607927,357576.065776047 4383813.730178432,356550.789189196 4383856.832852076,354153.657905290 4384359.920656587,353525.102262930 4384661.190893612,351291.551238470 4384920.943779380,347617.480074180 4385908.993595377,349431.998661245 4393807.021735130,350375.450420327 4397285.227618206,355028.997036976 4417789.702228969,358285.548758775 4431088.037187239,356016.736460076 4431709.436173828,355817.443055600 4431954.366659450,354708.242215216 4432120.183828845,355311.975285321 4434616.664178752))

影像2有效区域wkbPolygon:有效区域点:9256;压缩后:11
POLYGON((362750.063995277 4476033.157933494,386477.351879805 4470439.439743850,404176.435044228 4466078.930857699,393875.803919497 4423227.469141340,397306.405711504 4422266.346437510,396404.208085254 4418549.909967643,357580.286273485 4427981.920199280,358213.910179673 4431194.238457647,356003.864847716 4431717.006560705,355805.474488865 4431985.441774787,352395.342257962 4432604.331232955,362750.063995277 4476033.157933494))

wkbPolygon OGRGeometry求交结果:
{ "type": "Polygon", "coordinates": [ [ [ 355311.97528532101, 4434616.6641787523 ], [ 394375.89886357699, 4425437.7885831054 ], [ 393843.23714436003, 4423154.73 06245361 ], [ 393934.99077761301, 4423081.1227125926 ], [ 394422.29202694626, 44 23074.3641879568 ], [ 395077.67209964234, 4422890.7518931767 ], [ 395672.9572611 3301, 4422623.1536138952 ], [ 396519.55211061449, 4422486.7925592856 ], [ 397306 .40571150399, 4422266.3464375101 ], [ 396404.20808525401, 4418549.9099676432 ], [ 357580.28627348499, 4427981.9201992797 ], [ 357809.58540531754, 4429144.410725 ], [ 358285.548758775, 4431088.0371872392 ], [ 358197.70768018928, 4431112.0957 47414 ], [ 358213.910179673, 4431194.2384576472 ], [ 356012.17633061629, 4431715 .0405475702 ], [ 355937.38091873308, 4431806.9636927601 ], [ 355805.474488865, 4 431985.4417747874 ], [ 354723.15911321313, 4432181.8662917996 ], [ 355311.975285 32101, 4434616.6641787523 ] ] ] }

影像1有效区域wkbLineString:
LINESTRING(355311.975285321 4434616.664178752,394375.898863577 4425437.788583105,393843.237144360 4423154.730624536,393934.990777613 4423081.122712593,394677.078684115 4423070.830476722,395672.957261133 4422623.153613895,398450.480138563 4422175.777931183,401298.148822493 4421390.986072093,390683.292026611 4375703.636607970,379706.713504453 4378253.396138636,379002.853626275 4378601.921024554,377418.593859200 4378747.433146919,370137.256780411 4380867.566228855,366694.653063409 4381432.555968507,364209.755754306 4382319.768711558,360693.085284871 4382864.669607927,357576.065776047 4383813.730178432,356550.789189196 4383856.832852076,354153.657905290 4384359.920656587,353525.102262930 4384661.190893612,351291.551238470 4384920.943779380,347617.480074180 4385908.993595377,349431.998661245 4393807.021735130,350375.450420327 4397285.227618206,355028.997036976 4417789.702228969,358285.548758775 4431088.037187239,356016.736460076 4431709.436173828,355817.443055600 4431954.366659450,354708.242215216 4432120.183828845,355311.975285321 4434616.664178752)

【遥感影像镶嵌及实现(三)】影像2有效区域wkbLineString:
LINESTRING(362750.063995277 4476033.157933494,386477.351879805 4470439.439743850,404176.435044228 4466078.930857699,393875.803919497 4423227.469141340,397306.405711504 4422266.346437510,396404.208085254 4418549.909967643,357580.286273485 4427981.920199280,358213.910179673 4431194.238457647,356003.864847716 4431717.006560705,355805.474488865 4431985.441774787,352395.342257962 4432604.331232955,362750.063995277 4476033.157933494)

wkbLineString OGRGeometry求交结果(交点):
{ "type": "MultiPoint", "coordinates": [ [ 354723.15911321313, 4432181.866291799 6 ], [ 355937.38091873308, 4431806.9636927601 ], [ 356012.17633061629, 4431715.0 405475702 ], [ 357809.58540531754, 4429144.410725 ], [ 358197.70768018928, 44311 12.095747414 ], [ 394422.29202694626, 4423074.3641879568 ], [ 395077.67209964234 , 4422890.7518931767 ], [ 396519.55211061449, 4422486.7925592856 ] ] }

交叉点:
354723.159113213134432181.8662917996 396519.55211061449 4422486.7925592856

影像1交叉点位置:
[28 0] [5 6]

影像2交叉点位置:
[9 10] [3 4]

    推荐阅读