27 #include "../common/STLUtils.h" 28 #include "../core/translator/Translator.h" 50 #include <geos/algorithm/CentroidArea.h> 51 #include <geos/algorithm/CGAlgorithms.h> 52 #include <geos/algorithm/LineIntersector.h> 53 #include <geos/geom/Coordinate.h> 54 #include <geos/geom/Geometry.h> 55 #include <geos/geom/LineSegment.h> 56 #include <geos/geom/Point.h> 57 #include <geos/geom/Polygon.h> 58 #include <geos/operation/polygonize/Polygonizer.h> 59 #include <geos/operation/union/CascadedPolygonUnion.h> 60 #include <geos/operation/union/UnaryUnionOp.h> 61 #include <geos/operation/distance/DistanceOp.h> 62 #include <geos/operation/overlay/snap/GeometrySnapper.h> 63 #include <geos/operation/valid/IsValidOp.h> 64 #include <geos/util/GEOSException.h> 80 if (std::fabs(p1.
getX() - p2.
getX()) > tol)
84 if (std::fabs(p1.
getY() - p2.
getY()) > tol)
114 std::unique_ptr<te::gm::Geometry> geometry;
116 if (geomVec.size() == 1)
119 geometry.reset(static_cast<te::gm::Geometry*>(abs));
121 else if (geomVec.size() > 1)
126 std::vector<te::gm::Geometry*> geomVecCopy;
127 geomVecCopy.reserve(geomVec.size());
130 for (std::size_t i = 0; i < geomVec.size(); ++i)
135 geomVecCopy.push_back(geometry);
138 for (std::size_t i = 0; i < geomVecCopy.size(); ++i)
144 std::vector<std::size_t> vecCandidatesIndexes;
145 rtree.
search(expandedEnv_A, vecCandidatesIndexes);
147 if (vecCandidatesIndexes.empty())
153 std::vector<te::gm::Geometry*> geomVecCopyFiltered;
154 for (std::size_t j = 0; j < vecCandidatesIndexes.size(); ++j)
156 std::size_t index = vecCandidatesIndexes[j];
163 geomVecCopyFiltered.push_back(geometry);
166 bool wasChanged =
false;
169 if (wasChanged ==
true)
172 delete geomVecCopy[i];
173 geomVecCopy[i] = geometryResult.release();
179 for (std::size_t i = 0; i < geomVecCopy.size(); ++i)
180 gc->add(geomVecCopy[i]);
182 bool success =
false;
197 std::unique_ptr<te::gm::Geometry> bufferedGeometry(gc->buffer(0));
200 catch(geos::util::GEOSException& e)
275 auxD = env.
m_llx/bWidth;
276 auxI =
static_cast<int>(env.
m_llx/bWidth);
277 if (env.
m_llx < 0 && (auxD - auxI) != 0)
278 magicX = static_cast<int>(env.
m_llx/bWidth - 1);
283 auxD = env.
m_lly/bHeight;
284 auxI =
static_cast<int>(env.
m_lly/bHeight);
285 if (env.
m_lly < 0 && (auxD - auxI) != 0)
286 magicY = static_cast<int>(env.
m_lly/bHeight - 1);
290 double xi = magicX*bWidth;
291 double yi = magicY*bHeight;
294 auxD = env.
m_urx/bWidth;
295 auxI =
static_cast<int>(env.
m_urx/bWidth);
296 if ((env.
m_urx < 0) || (auxD - auxI) == 0)
297 magicX2 =
static_cast<int>(env.
m_urx/bWidth);
299 magicX2 =
static_cast<int>(env.
m_urx/bWidth + 1);
302 auxD = env.
m_ury/bHeight;
303 auxI =
static_cast<int>(env.
m_ury/bHeight);
304 if ((env.
m_ury < 0) || (auxD - auxI) == 0)
305 magicY2 =
static_cast<int>(env.
m_ury/bHeight);
307 magicY2 =
static_cast<int>(env.
m_ury/bHeight + 1);
309 double xf = (magicX2)*bWidth;
310 double yf = (magicY2)*bHeight;
317 return o1->intersects(o2);
345 std::map<int, double> pointLenghtFromFirst;
347 double fullLineLenght = 0;
349 pointLenghtFromFirst[0] = 0;
350 for(std::size_t i = 1; i < line->
getNPoints(); i++)
352 std::unique_ptr<Point> pA = line->
getPointN(i);
353 std::unique_ptr<Point> pB = line->
getPointN(i - 1);
355 fullLineLenght += pA->distance(pB.get());
356 pointLenghtFromFirst[
static_cast<int>(i)] = fullLineLenght;
359 double diference =
final-initial;
361 tTof = ((target-initial)*fullLineLenght)/diference;
365 int pointBeforeTarget = -1;
367 for(std::size_t i = 0; i < pointLenghtFromFirst.size(); i++)
369 if(pointLenghtFromFirst[static_cast<int>(i)] == tTof)
371 onTheFly =
static_cast<int>(i);
374 if(tTof >= pointLenghtFromFirst[static_cast<int>(i)] && tTof < pointLenghtFromFirst[static_cast<int>(i+1)])
376 pointBeforeTarget =
static_cast<int>(i);
385 targetCoord->
x = line->
getPointN(static_cast<std::size_t>(onTheFly))->getX();
386 targetCoord->
y = line->
getPointN(static_cast<std::size_t>(onTheFly))->getY();
391 std::unique_ptr<Point> p1 = line->
getPointN(static_cast<std::size_t>(pointBeforeTarget));
392 std::unique_ptr<Point> p2 = line->
getPointN(static_cast<std::size_t>(pointBeforeTarget + 1));
395 double pd = tTof - pointLenghtFromFirst[pointBeforeTarget];
398 double td = pointLenghtFromFirst[pointBeforeTarget+1] - pointLenghtFromFirst[pointBeforeTarget];
400 targetCoord->
x = ((pd*(p2->getX()-p1->getX()))/
td)+p1->getX();
402 targetCoord->
y = ((pd*(p2->getY()-p1->getY()))/
td)+p1->getY();
420 geoms.push_back(dynamic_cast<te::gm::Geometry*>(g->
clone()));
425 #ifdef TERRALIB_GEOS_ENABLED 427 std::vector<geos::geom::Polygon*> geosPolygonVector;
431 if(polygonVector.empty())
434 int srid = polygonVector[0]->
getSRID();
436 for(
auto i : polygonVector)
440 geos::geom::Polygon* geosPolygon = GEOSWriter::write(i);
441 geosPolygonVector.push_back(geosPolygon);
449 if(unionGeom ==
nullptr)
452 unionGeom->setSRID(srid);
454 return GEOSReader::read(unionGeom.get());
456 catch(geos::util::GEOSException& e)
469 #ifdef TERRALIB_GEOS_ENABLED 473 std::unique_ptr<geos::geom::Geometry> geomGeos(GEOSWriter::write(geom));
477 unionGeom->setSRID(geom->
getSRID());
479 return GEOSReader::read(unionGeom.get());
481 catch(geos::util::GEOSException& e)
494 #ifdef TERRALIB_GEOS_ENABLED 495 std::unique_ptr<geos::geom::Geometry> thisGeomA(GEOSWriter::write(geomA));
496 std::unique_ptr<geos::geom::Geometry> thisGeomB(GEOSWriter::write(geomB));
498 geos::operation::distance::DistanceOp op(thisGeomA.get(), thisGeomB.get());
500 geos::geom::CoordinateSequence* cs = op.closestPoints();
502 if (cs->getSize() == 2)
517 std::vector<te::gm::Geometry*> geomVec;
522 for (std::size_t t = 0; t < geomVec.size(); ++t)
532 std::unique_ptr<te::gm::Point> p0 = ls->
getPointN(0);
533 std::unique_ptr<te::gm::Point> p1 = ls->
getPointN(1);
537 line->
setCoord(0, p0->getX(), p0->getY());
538 line->
setCoord(1, p1->getX(), p1->getY());
546 std::unique_ptr<te::gm::Point> p0 = ls->
getPointN(
p);
547 std::unique_ptr<te::gm::Point> p1 = ls->
getPointN(
p + 1);
550 line->setCoord(0, p0->getX(), p0->getY());
551 line->setCoord(1, p1->getX(), p1->getY());
555 if (geomMBR->intersects(pRef.get()))
557 return line.release();
569 if (coordA.
x == coordB.
x)
571 return 1.57079632679489661923;
574 if (coordA.
y == coordB.
y)
579 double dx = (coordA.
x - coordB.
x);
580 double dy = (coordA.
y - coordB.
y);
582 double rad = std::atan(dy / dx);
585 double angle = rad / 0.01745329251994329576;
603 alfa = (4.*std::atan(1.)*angle) / 180.;
608 for (std::size_t count = 0; count < l->
size(); count++)
610 std::unique_ptr<te::gm::Point> curPoint = l->
getPointN(count);
612 x = curPoint->getX() -
dx;
613 y = curPoint->getY() - dy;
615 xr = x * std::cos(alfa) - y * std::sin(alfa);
616 yr = x * std::sin(alfa) + y * std::cos(alfa);
618 lOut->
setPoint(count, xr + dx, yr + dy);
650 if (pFim1->
distance(P1) <= pFim2->distance(P1))
652 P0out.
x = P0->
getX();
653 P0out.
y = P0->
getY();
654 P1out.
x = pFim1->
getX();
655 P1out.
y = pFim1->
getY();
659 P0out.
x = P0->
getX();
660 P0out.
y = P0->
getY();
661 P1out.
x = pFim2->getX();
662 P1out.
y = pFim2->getY();
675 #ifdef TERRALIB_GEOS_ENABLED 679 std::unique_ptr<geos::geom::Geometry> geomGeos(GEOSWriter::write(g));
680 polygonizer.add(geomGeos.get());
682 std::vector <geos::geom::Polygon*>* vecpolGeos = polygonizer.getPolygons();
684 for (std::size_t i = 0; i < vecpolGeos->size(); i++)
686 vecpolGeos->at(i)->setSRID(g->
getSRID());
687 pols.push_back(GEOSReader::read(vecpolGeos->at(i)));
697 #ifdef TERRALIB_GEOS_ENABLED 701 std::unique_ptr<geos::geom::Geometry> g(GEOSWriter::write(geom));
703 geos::operation::valid::IsValidOp vop(g.get());
705 geos::operation::valid::TopologyValidationError* err = vop.getValidationError();
717 catch(
const geos::util::GEOSException& e)
725 throw Exception(
TE_TR(
"isValid routine is supported by GEOS! Please, enable the GEOS support."));
731 #ifdef TERRALIB_GEOS_ENABLED 733 std::unique_ptr<geos::geom::Geometry> g(GEOSWriter::write(geom));
735 std::vector<te::gm::Geometry*> pAdd;
738 switch (g->getGeometryTypeId())
740 case geos::geom::GEOS_POLYGON:
745 return GEOSReader::read(g.get());
748 AddPolygon(dynamic_cast<te::gm::Polygon*>(GEOSReader::read(g.get())), pAdd);
752 case geos::geom::GEOS_MULTIPOLYGON:
756 return GEOSReader::read(g.get());
759 for (std::size_t n = g->getNumGeometries(); n-- > 0;)
760 AddPolygon(dynamic_cast<te::gm::Polygon*>(GEOSReader::read(g->getGeometryN(n))), pAdd);
769 for (std::size_t i = 0; i < pAdd.size(); i++)
770 polygonizer.add(GEOSWriter::write(pAdd[i]));
774 std::vector <geos::geom::Polygon*>* vecpolGeos = polygonizer.getPolygons();
776 switch (vecpolGeos->size())
779 vecpolGeos->at(0)->setSRID(geom->
getSRID());
780 return GEOSReader::read(vecpolGeos->at(0));
785 while (i < vecpolGeos->size())
787 if (!vecpolGeos->at(i)->isValid())
789 vecpolGeos->erase(vecpolGeos->begin() +
static_cast<int>(i));
798 vecpolGeos->at(0)->setSRID(geom->
getSRID());
801 for (std::size_t
p = 1;
p < vecpolGeos->size();
p++)
814 throw Exception(
TE_TR(
"validate routine is supported by GEOS! Please, enable the GEOS support."));
820 #ifdef TERRALIB_GEOS_ENABLED 829 throw Exception(
TE_TR(
"addPolygon routine is supported by GEOS! Please, enable the GEOS support."));
835 #ifdef TERRALIB_GEOS_ENABLED 837 std::unique_ptr<geos::geom::LineString> ls(GEOSWriter::write(lineString));
840 geos::geom::Point* point = GEOSGeometryFactory::getGeomFactory()->createPoint(ls->getCoordinateN(0));
842 geos::geom::Geometry* toAdd = ls->
Union(point);
844 pAdd.push_back(GEOSReader::read(toAdd));
847 throw Exception(
TE_TR(
"addLineString routine is supported by GEOS! Please, enable the GEOS support."));
855 #ifdef TERRALIB_GEOS_ENABLED 856 double d12, xmin, ymin;
858 double xi = first.
getX();
859 double xf = last.
getX();
860 double yi = first.
getY();
861 double yf = last.
getY();
862 double x = pin.
getX();
863 double y = pin.
getY();
867 double a2 = (y - yi) * dx - (x - xi)*dy;
869 if (dx == 0. && dy == 0.)
871 d12 = sqrt(((x - xi) * (x - xi)) + ((y - yi) * (y - yi)));
875 d12 = a2 * a2 / (dx * dx + dy * dy);
889 double alfa = dy /
dx;
890 xmin = (x + alfa * (y - yi) + alfa * alfa * xi) / (1. + alfa * alfa);
891 ymin = (x - xmin) / alfa + y;
899 throw Exception(
TE_TR(
"PerpendicularDistance routine is supported by GEOS! Please, enable the GEOS support."));
905 std::vector<te::gm::Geometry*> vecGeomB;
906 vecGeomB.push_back(geomB);
915 #ifdef TERRALIB_GEOS_ENABLED 933 std::vector<te::gm::LineString> rtreeSegments;
936 for (std::size_t i = 0; i < vecGeomB.size(); ++i)
946 if (expandedEnv_A.
intersects(expandedGeometryEnv_B) ==
false)
952 for (std::size_t j = 0; j < multiLineStringVectorB.size(); ++j)
955 const std::vector<te::gm::Geometry*>& vecGeometries = multiLineB->
getGeometries();
957 for (std::size_t k = 0; k < vecGeometries.size(); ++k)
967 if (expandedEnv_A.
intersects(expandedLineEnv_B) ==
false)
973 std::size_t nSegmentsB = lineB->
size() - 1;
974 for (std::size_t s = 0; s < nSegmentsB; ++s)
984 if (expandedEnv_A.
intersects(expandedSegmentEnv_B) ==
true)
989 segment_B.setPoint(1, lineB->
getX(s + 1), lineB->
getY(s + 1));
991 rtree.
insert(currentSegmentEnvelope, rtreeSegments.size());
992 rtreeSegments.push_back(segment_B);
1000 for (std::size_t i = 0; i < multiLineStringVectorA.size(); ++i)
1002 bool currentWasChanged =
false;
1003 std::unique_ptr<te::gm::MultiLineString> currentResult(
PrepareGeometriesToIntersection(*multiLineStringVectorA[i], rtree, rtreeSegments, currentWasChanged));
1005 if (currentWasChanged ==
true)
1008 delete multiLineStringVectorA[i];
1009 multiLineStringVectorA[i] = currentResult.release();
1015 std::unique_ptr<te::gm::Geometry> preparedGeometryResult(
MultiLineToDefinedType(multiLineStringVectorA, geomTypeA));
1018 bool result =
CheckValidity(preparedGeometryResult.get(), error);
1019 if (result ==
false)
1021 preparedGeometryResult.reset(preparedGeometryResult->buffer(0));
1024 geomResult = preparedGeometryResult.release();
1037 throw Exception(
TE_TR(
"PrepareGeometriesToIntersection routine is supported by GEOS! Please, enable the GEOS support."));
1043 std::vector<te::gm::LineString>& vecRtreeSegments,
1048 #ifdef TERRALIB_GEOS_ENABLED 1052 const std::vector<te::gm::Geometry*>& geometryVectorA = mline_A.
getGeometries();
1054 for (std::size_t i = 0; i < geometryVectorA.size(); ++i)
1056 bool currentWasChanged =
false;
1059 multiLineStringResult->
add(singleResult);
1061 if (currentWasChanged ==
true)
1067 return multiLineStringResult;
1070 throw Exception(
TE_TR(
"PrepareGeometriesToIntersection routine is supported by GEOS! Please, enable the GEOS support."));
1076 std::vector<te::gm::LineString>& vecRtreeSegments,
1081 #ifdef TERRALIB_GEOS_ENABLED 1084 bool wasSnapped =
false;
1087 std::vector<std::size_t> report;
1096 std::size_t n_segments_A = n_pointsA - 1;
1098 std::vector<te::gm::Point> vecOutputPoints;
1099 vecOutputPoints.reserve(n_pointsA);
1101 std::set<std::size_t> setIndexesIgnored;
1102 for (std::size_t i = 0; i < n_segments_A; ++i)
1110 std::vector<std::size_t> segmentReport;
1111 rtree.
search(segmentEnvelope, segmentReport);
1113 for (std::size_t i = 0; i < segmentReport.size(); ++i)
1115 std::size_t index = segmentReport[i];
1117 if (setIndexesIgnored.find(index) != setIndexesIgnored.end())
1125 if(segmentEnvelope.equals(*candidate.
getMBR()) ==
false)
1137 if (
IsEqual(segmentP1, candidateP1) ==
false &&
IsEqual(segmentP1, candidateP2) ==
false)
1143 setIndexesIgnored.insert(index);
1147 std::unique_ptr<te::gm::LineString> lr_Result(dynamic_cast<te::gm::LineString*>(ls_A.
clone()));
1148 lr_Result.reset(
SnapLineToPoints(rtree, vecRtreeSegments, setIndexesIgnored, *lr_Result.get(), wasSnapped));
1150 lr_Result.reset(
AddIntersectionPoints(rtree, vecRtreeSegments, setIndexesIgnored, *lr_Result.get(),
true));
1151 lr_Result.reset(
AddIntersectionPoints(rtree, vecRtreeSegments, setIndexesIgnored, *lr_Result.get()));
1153 if (wasSnapped ==
true || lr_Result->size() != ls_A.
size())
1158 return lr_Result.release();
1161 throw Exception(
TE_TR(
"PrepareGeometriesToIntersection routine is supported by GEOS! Please, enable the GEOS support."));
1166 const std::vector<te::gm::LineString>& referenceSegments,
1167 const std::set<std::size_t>& setIndexesIgnored,
1168 const LineString& linearRingToSnap,
bool& wasChanged)
1172 #ifdef TERRALIB_GEOS_ENABLED 1176 std::size_t npoints_A = linearRingToSnap.
getNPoints();
1178 for (std::size_t i = 0; i < npoints_A; ++i)
1180 std::unique_ptr<Point> currentPoint = lr_Result->
getPointN(i);
1187 std::vector<size_t> report;
1188 rtree.
search(expandedEnv, report);
1194 std::vector<te::gm::Point> candidates;
1195 for (std::size_t ls = 0; ls < report.size(); ++ls)
1197 std::size_t index = report[ls];
1200 if (setIndexesIgnored.find(index) != setIndexesIgnored.end())
1205 std::unique_ptr<Point> pStart = referenceSegments[index].getPointN(0);
1206 candidates.push_back(*pStart.get());
1208 std::unique_ptr<Point> pEnd = referenceSegments[index].getPointN(1);
1209 candidates.push_back(*pEnd.get());
1212 if (candidates.empty() ==
true)
1220 std::sort(candidates.begin(), candidates.end(), func);
1222 double distance = currentPoint->distance(&candidates[0]);
1223 if(distance != 0 && distance <=
TOLERANCE)
1231 lr_Result->
setPointN(npoints_A - 1, candidates[0]);
1239 throw Exception(
TE_TR(
"SnapLineToPoints routine is supported by GEOS! Please, enable the GEOS support."));
1244 const std::vector<te::gm::LineString>& candidateSegments,
1245 const std::set<std::size_t>& setIndexesIgnored,
1247 const bool& usePerpendicularDistance)
1249 #ifdef TERRALIB_GEOS_ENABLED 1251 bool addedIntersectionPoints =
false;
1253 std::size_t n_pointsA = lr_Reference.
getNPoints();
1254 std::size_t n_segments_A = n_pointsA - 1;
1256 std::vector<te::gm::Point> vecOutputPoints;
1257 vecOutputPoints.reserve(n_pointsA);
1259 for (std::size_t i = 0; i < n_segments_A; ++i)
1264 std::unique_ptr<Point> pCurrentStartPoint = lr_Reference.
getPointN(i);
1266 vecOutputPoints.push_back(*pCurrentStartPoint.get());
1273 std::vector<size_t> report;
1274 rtree.
search(expandedEnv, report);
1282 segment_A.setPoint(1, lr_Reference.
getX(i + 1), lr_Reference.
getY(i + 1));
1284 std::vector<te::gm::LineString> candidates;
1285 candidates.reserve(report.size());
1286 for(std::size_t ls = 0; ls < report.size(); ++ls)
1288 std::size_t index = report[ls];
1291 if (setIndexesIgnored.find(index) != setIndexesIgnored.end())
1297 candidates.push_back(segmentCandidate);
1300 if (candidates.empty() ==
true)
1306 std::vector<te::gm::Point> vecIntersectionPoints;
1308 if(usePerpendicularDistance)
1314 std::sort(vecIntersectionPoints.begin(), vecIntersectionPoints.end(), func);
1316 for (std::size_t j = 0; j < vecIntersectionPoints.size(); ++j)
1318 const te::gm::Point& currentIntersectionPoint = vecIntersectionPoints[j];
1319 const te::gm::Point& lastPoint = vecOutputPoints[vecOutputPoints.size() - 1];
1325 if (
IsEqual(currentIntersectionPoint, *pCurrentStartPoint.get(),
TOLERANCE) ==
true)
1329 std::unique_ptr<Point> pCurrentEndPoint = lr_Reference.
getPointN(i + 1);
1330 if (
IsEqual(currentIntersectionPoint, *pCurrentEndPoint.get(),
TOLERANCE) ==
true)
1335 addedIntersectionPoints =
true;
1336 vecOutputPoints.push_back(vecIntersectionPoints[j]);
1341 if (addedIntersectionPoints ==
false)
1347 std::unique_ptr<Point> pStart = lr_Reference.
getStartPoint();
1348 vecOutputPoints.push_back(*pStart.get());
1352 for (std::size_t i = 0; i < vecOutputPoints.size(); ++i)
1353 result->
setPointN(i, vecOutputPoints[i]);
1358 throw Exception(
TE_TR(
"GetIntersectionPoints routine is supported by GEOS! Please, enable the GEOS support."));
1364 const std::vector<te::gm::LineString>& candidates)
1366 #ifdef TERRALIB_GEOS_ENABLED 1368 std::vector<te::gm::Point> intersectionPoints;
1369 std::unique_ptr<te::gm::Point> startPoint;
1370 std::unique_ptr<te::gm::Point> endPoint;
1372 geos::geom::Coordinate referenceP1(lsReference.
getX(0), lsReference.
getY(0));
1373 geos::geom::Coordinate referenceP2(lsReference.
getX(1), lsReference.
getY(1));
1375 for (std::size_t i = 0; i < candidates.size(); ++i)
1379 geos::geom::Coordinate candidateP1(lineCandidate.
getX(0), lineCandidate.
getY(0));
1380 geos::geom::Coordinate candidateP2(lineCandidate.
getX(1), lineCandidate.
getY(1));
1382 geos::algorithm::LineIntersector intersector;
1383 intersector.computeIntersection(referenceP1, referenceP2, candidateP1, candidateP2);
1384 if (intersector.hasIntersection() ==
false)
1389 std::vector<te::gm::Point> candidatesIntersectionPoints;
1390 int numberOfIntersections = intersector.getIntersectionNum();
1391 for (
int j = 0; j < numberOfIntersections; ++j)
1393 const geos::geom::Coordinate& interCoord = intersector.getIntersection(j);
1395 candidatesIntersectionPoints.push_back(
te::gm::Point(interCoord.x, interCoord.y, lsReference.
getSRID()));
1398 for (std::size_t j = 0; j < candidatesIntersectionPoints.size(); ++j)
1400 if (startPoint.get() ==
nullptr || endPoint.get() ==
nullptr)
1406 const te::gm::Point& candidateIntersectionPoint = candidatesIntersectionPoints[j];
1414 std::unique_ptr<te::gm::Point>candidateStartPoint = candidates[i].getStartPoint();
1415 std::unique_ptr<te::gm::Point>candidateEndPoint = candidates[i].getEndPoint();
1418 double distanceStartPointB = candidateIntersectionPoint.
distance(candidateStartPoint.get());
1419 double distanceEndPointB = candidateIntersectionPoint.
distance(candidateEndPoint.get());
1423 intersectionPoints.push_back(*candidateStartPoint.get());
1425 else if (distanceEndPointB <=
TOLERANCE)
1427 intersectionPoints.push_back(*candidateEndPoint.get());
1431 intersectionPoints.push_back(candidateIntersectionPoint);
1436 return intersectionPoints;
1439 throw Exception(
TE_TR(
"GetIntersectionPointsByOperators routine is supported by GEOS! Please, enable the GEOS support."));
1445 const std::vector<te::gm::LineString>& candidates)
1447 #ifdef TERRALIB_GEOS_ENABLED 1449 std::vector<te::gm::Point> intersectionPoints;
1451 std::unique_ptr<te::gm::Point> startPoint = lsReference.
getStartPoint();
1452 std::unique_ptr<te::gm::Point> endPoint = lsReference.
getEndPoint();
1454 for (std::size_t i = 0; i < candidates.size(); ++i)
1456 std::unique_ptr<te::gm::Point>candidateStartPoint = candidates[i].getStartPoint();
1457 std::unique_ptr<te::gm::Point>candidateEndPoint = candidates[i].getEndPoint();
1459 std::unique_ptr<geos::geom::LineSegment> lineSegment(
1460 new geos::geom::LineSegment(startPoint->getX(), startPoint->getY(),
1461 endPoint->getX(), endPoint->getY()));
1470 std::unique_ptr<geos::geom::Coordinate> coordStart(
new geos::geom::Coordinate(pInterStart.
getX(), pInterStart.
getY()));
1472 double projFactorStart = lineSegment->projectionFactor(*coordStart.get());
1473 if (startDistance <=
TOLERANCE && (projFactorStart >= 0 && projFactorStart <= 1))
1475 intersectionPoints.push_back(*candidateStartPoint.get());
1486 std::unique_ptr<geos::geom::Coordinate> coordEnd(
new geos::geom::Coordinate(pInterEnd.
getX(), pInterEnd.
getY()));
1488 double projFactorEnd = lineSegment->projectionFactor(*coordEnd.get());
1489 if (endDistance <=
TOLERANCE && (projFactorEnd >= 0 && projFactorEnd <= 1))
1491 intersectionPoints.push_back(*candidateEndPoint.get());
1496 return intersectionPoints;
1499 throw Exception(
TE_TR(
"GetIntersectionPointsByPerpendicularDistance routine is supported by GEOS! Please, enable the GEOS support."));
1505 std::vector<te::gm::MultiLineString*> multiLineStringVector;
1518 multiLineString->
add(lineString);
1520 multiLineStringVector.push_back(multiLineString);
1531 std::vector<te::gm::Geometry*> geometryVector;
1534 for(
auto g : geometryVector)
1538 multiLineString->
add(lineString);
1540 multiLineStringVector.push_back(multiLineString);
1556 const std::vector<te::gm::Curve*>& curveVector = polygon->
getRings();
1558 for (
auto curve : curveVector)
1562 multiLineString->
add(lineString);
1565 multiLineStringVector.push_back(multiLineString);
1574 std::vector<te::gm::Geometry*> geometryVector;
1577 for(
auto g : geometryVector)
1581 multiLineStringVector.insert(multiLineStringVector.end(), multiLineStringVectorTemp.begin(), multiLineStringVectorTemp.end());
1589 throw Exception(
"This type of geometry is not composed by LineString.");
1592 return multiLineStringVector;
1599 if(multiLineStringVector.empty())
1602 int srid = multiLineStringVector[0]->
getSRID();
1604 switch (geometryType)
1633 polygon->
add(dynamic_cast<te::gm::Curve*>(g->clone()));
1646 for(
auto inMls : multiLineStringVector)
1648 if(inMls->isEmpty())
1651 for(
auto g : inMls->getGeometries())
1652 outMls->
add(dynamic_cast<te::gm::Geometry*>(g->clone()));
1666 for(
auto inMls : multiLineStringVector)
1668 if(inMls->getGeometries().empty())
1671 std::size_t numRings = inMls->getGeometries().size();
1675 for (std::size_t j = 0; j < numRings; ++j)
1677 polygon->
setRingN(j, dynamic_cast<te::gm::Curve*>(inMls->getGeometryN(j)->clone()));
1680 outMPolygon->
add(polygon);
1683 geometry = outMPolygon;
1688 throw Exception(
"This type of geometry is not composed by LineString.");
1831 double gapX = (endCoord.
getX() - startCoord.
getX()) / static_cast<double>(numberOfIntermediateCoords + 1);
1832 double gapY = (endCoord.
getY() - startCoord.
getY()) / static_cast<double>(numberOfIntermediateCoords + 1);
1834 std::vector<te::gm::Coord2D> coords;
1836 coords.push_back(startCoord);
1837 for (std::size_t i = 0; i < static_cast<std::size_t>(numberOfIntermediateCoords); ++i)
1839 std::size_t coordIndex = i + 1;
1841 coords.push_back(coord);
1843 coords.push_back(endCoord);
1847 for (std::size_t t = 0; t < coords.size(); ++t)
1848 resultLine.
setPoint(t, coords[t].getX(), coords[t].getY());
1866 std::vector<te::gm::Coord2D> coords;
1869 for (std::size_t i = 0; i < bottomLine.
size() - 1; ++i)
1872 for (std::size_t i = 0; i < leftLine.
size() - 1; ++i)
1875 for (std::size_t i = 0; i < topLine.
size() - 1; ++i)
1878 for (std::size_t i = 0; i < rightLine.
size() - 1; ++i)
1883 for (std::size_t t = 0; t < coords.size(); ++t)
1884 fullLine->
setPoint(t, coords[t].getX(), coords[t].getY());
static te::dt::TimeDuration td(20, 30, 50, 11)
std::size_t getNumGeometries() const
It returns the number of geometries in this GeometryCollection.
Curve * getInteriorRingN(std::size_t i) const
It returns the n-th interior ring for this curve polygon as a curve.
TEGEOMEXPORT te::gm::Geometry * UnaryUnion(te::gm::Geometry *geom)
It will get the union of the input geometries.
std::unique_ptr< Point > getEndPoint() const
It returns the curve end point.
TEGEOMEXPORT std::vector< MultiLineString * > GetAsMultiLineStringVector(const te::gm::Geometry &geometry)
Get the vector of MultLineStrings that compose the Geometry.
void add(Curve *ring)
It adds the ring to the curve polygon.
MultiPolygon is a MultiSurface whose elements are Polygons.
void init(const double &llx, const double &lly, const double &urx, const double &ury)
It initializes (sets) the envelope bounds.
The global factory used by TerraLib in order to create GEOS geometries.
std::vector< Curve * > & getRings()
It returns the polygon rings.
GeomType
Each enumerated type is compatible with a Well-known Binary (WKB) type code.
A Line is LineString with 2 points.
virtual Geometry * symDifference(const Geometry *const rhs) const _NOEXCEPT_OP(false)
It returns a geometric object that represents the point set symetric difference with another geometry...
A Line is LineString with 2 points.
bool intersects(const Envelope &rhs) const
It returns true if the envelopes "spatially intersects".
A LinearRing is a LineString that is both closed and simple.
TEGEOMEXPORT bool Rotate(te::gm::Coord2D pr, te::gm::LineString *l, double angle, te::gm::LineString *lOut)
virtual double distance(const Geometry *const rhs) const _NOEXCEPT_OP(false)
It returns the shortest distance between any two points in the two geometry objects.
static te::dt::Date dx(2010, 12, 31)
Base exception class for plugin module.
virtual te::dt::AbstractData * clone() const
It clones the linestring.
TEGEOMEXPORT te::gm::GeomType GetMultiType(te::gm::GeomType geomType)
Get the collection type of GeomType.
std::size_t getNumInteriorRings() const
It returns the number of interior rings in this CurvePolygon.
GeomType getGeomTypeId() const _NOEXCEPT_OP(true)
It returns the geometry subclass type identifier.
const double & getUpperRightX() const
It returns a constant refernce to the x coordinate of the upper right corner.
A point with x and y coordinate values.
TEGEOMEXPORT bool SatisfySpatialRelation(const Geometry *g1, const Geometry *g2, SpatialRelation relation)
It returns if two geometries satisfy a given spatial relation.
TEGEOMEXPORT te::gm::LineString CreateLine(const te::gm::Coord2D &startCoord, const te::gm::Coord2D &endCoord, const int &srid, const int &numberOfIntermediateCoords)
Creates a LineString between the given startCoord and endCoord with the given number of intermediate ...
TEGEOMEXPORT bool AdjustSegment(te::gm::Point *P0, te::gm::Point *P1, double d0, te::gm::Coord2D &P0out, te::gm::Coord2D &P1out)
Curve * getExteriorRing() const
It returns the exterior ring of this CurvePolygon.
double m_urx
Upper right corner x-coordinate.
std::unique_ptr< Point > getPointN(std::size_t i) const
It returns the specified point in this LineString.
TEGEOMEXPORT double PerpendicularDistance(const te::gm::Point &first, const te::gm::Point &last, te::gm::Point &pin, Point &pinter)
Calculate the perpendicular distance of a point in a segment.
virtual bool disjoint(const Geometry *const rhs) const _NOEXCEPT_OP(false)
It returns true if the geometry object is spatially disjoint from rhs geometry.
TEGEOMEXPORT bool IsMultiType(te::gm::GeomType geomType)
Verifies if the geomType is a collection type.
const double & getLowerLeftY() const
It returns a constant refernce to the y coordinate of the lower left corner.
TEGEOMEXPORT std::unique_ptr< te::gm::Geometry > GetGeometryUnion(const std::vector< te::gm::Geometry * > &geomVec)
It returns the union of a geometry vector.
SpatialRelation
Spatial relations between geometric objects.
TEGEOMEXPORT te::gm::GeomType GetSimpleType(te::gm::GeomType geomType)
Get the simple type of GeomType.
TEGEOMEXPORT te::gm::Envelope CreateEnvelope(double x1, double y1, double x2, double y2)
Creates an envelope that fits the given coordinates. It makes all the adjustments needed to return a ...
An utility struct for representing 2D coordinates.
double getY() const
It returns the y-coordinate.
const double & getUpperRightY() const
It returns a constant refernce to the x coordinate of the upper right corner.
#define TE_TR(message)
It marks a string in order to get translated.
virtual Geometry * Union(const Geometry *const rhs) const _NOEXCEPT_OP(false)
It returns a geometric object that represents the point set union with another geometry.
virtual bool intersects(const Geometry *const rhs) const _NOEXCEPT_OP(false)
It returns true if the geometry object spatially intersects rhs geometry.
virtual bool touches(const Geometry *const rhs) const _NOEXCEPT_OP(false)
It returns true if the geometry object spatially touches rhs geometry.
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
TEGEOMEXPORT void Multi2Single(const te::gm::Geometry *g, std::vector< te::gm::Geometry * > &geoms)
It will get a GeometryCollection and distribute in a vector.
This struct is used sorts a vector of points by distance.
TEGEOMEXPORT te::gm::Geometry * MultiLineToDefinedType(const std::vector< te::gm::MultiLineString * > &multiLineStringVector, te::gm::GeomType geometryType)
A geometry is built based on a Vector of MultiLineString and the origin geometry type.
const double & getY(std::size_t i) const
It returns the n-th y coordinate value.
virtual bool overlaps(const Geometry *const rhs) const _NOEXCEPT_OP(false)
It returns true if this geometry object spatially overlaps rhs geometry.
te::gm::GeometryCollection * gc
Utility functions for the Geometry Module.
TEGEOMEXPORT LineString * SnapLineToPoints(const te::sam::rtree::Index< std::size_t, 8 > &rtree, const std::vector< te::gm::LineString > &referenceSegments, const std::set< std::size_t > &setIndexesIgnored, const te::gm::LineString &linearRingToSnap, bool &wasChanged)
Snaps a LinearRing based on a set of LineString.
A LinearRing is a LineString that is both closed and simple.
int getSRID() const _NOEXCEPT_OP(true)
It returns the Spatial Reference System ID associated to this geometric object.
double m_llx
Lower left corner x-coordinate.
An Envelope defines a 2D rectangular region.
LineString is a curve with linear interpolation between points.
const double & getY() const
It returns the Point y-coordinate value.
A point with x and y coordinate values.
const Envelope * getMBR() const _NOEXCEPT_OP(true)
It returns the minimum bounding rectangle for the geometry in an internal representation.
void setPoint(std::size_t i, const double &x, const double &y)
It sets the value of the specified point.
An Envelope defines a 2D rectangular region.
const double & getX(std::size_t i) const
It returns the n-th x coordinate value.
MultiLineString is a MultiCurve whose elements are LineStrings.
virtual bool within(const Geometry *const rhs) const _NOEXCEPT_OP(false)
It returns true if the geometry object is spatially within rhs geometry.
virtual bool isEmpty() const _NOEXCEPT_OP(false)
It returns true if this geometric object is the empty Geometry.
TEGEOMEXPORT te::gm::Geometry * CascadedPolygonUnion(const std::vector< te::gm::Polygon * > &polygonVector)
Provides an efficient method of unioning a collection of Polygonal geometries. This algorithm is fast...
TEGEOMEXPORT Coord2D * locateAlong(const LineString *line, double initial, double final, double target)
Make the line interpolation to find a target.
MultiPolygon is a MultiSurface whose elements are Polygons.
void setCoord(int index, double x, double y, double z=0., double m=0.)
std::size_t getNPoints() const
It returns the number of points (vertexes) in the linestring.
virtual bool contains(const Geometry *const rhs) const _NOEXCEPT_OP(false)
It returns true if this geometry object spatially contains rhs geometry.
virtual AbstractData * clone() const =0
It returns a clone of this object.
TEGEOMEXPORT te::gm::Geometry * PrepareGeometriesToIntersection(const te::gm::Geometry *geom_A, te::gm::Geometry *geomB, bool &wasChanged)
Prepares the geometry A with intersection points in geometry B.
A base class for values that can be retrieved from the data access module.
int search(const te::gm::Envelope &mbr, std::vector< DATATYPE > &report) const
Range search query.
A class that converts a GEOS geometry to a TerraLib geometry.
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
TEGEOMEXPORT void Polygonizer(te::gm::Geometry *g, std::vector< te::gm::Polygon * > &pols)
It will get a list of polygons formed by the polygonization.
Curve is an abstract class that represents 1-dimensional geometric objects stored as a sequence of co...
A class that converts a TerraLib geometry to a GEOS geometry.
bool Intersects(const T1 &o1, const T2 &o2)
double m_lly
Lower left corner y-coordinate.
TEGEOMEXPORT std::vector< te::gm::Point > GetIntersectionPointsByOperators(const te::gm::LineString &lsReference, const std::vector< te::gm::LineString > &candidates)
Gets a vector of LineString reference points including intersection points using GEOS operators...
TEGEOMEXPORT void ClosestPoints(te::gm::Geometry *geomA, te::gm::Geometry *geomB, te::gm::Coord2D &coordA, te::gm::Coord2D &coordB)
Compute the the closest points of two geometries.
Polygon is a subclass of CurvePolygon whose rings are defined by linear rings.
Geometry * getGeometryN(std::size_t i) const
It returns the n-th geometry in this GeometryCollection.
TEGEOMEXPORT double GetAngle(te::gm::Coord2D coordA, te::gm::Coord2D coordB)
MultiLineString is a MultiCurve whose elements are LineStrings.
Polygon is a subclass of CurvePolygon whose rings are defined by linear rings.
double getX() const
It returns the x-coordinate.
void insert(const te::gm::Envelope &mbr, const DATATYPE &data)
It inserts an item into the tree.
double m_ury
Upper right corner y-coordinate.
void add(Geometry *g)
It adds the geometry into the collection.
te::gm::Geometry * Union(te::gm::Geometry *g1, te::gm::Geometry *g2)
const double & getLowerLeftX() const
It returns a constant reference to the x coordinate of the lower left corner.
const std::vector< Geometry * > & getGeometries() const
It returns a reference to the internal list of geometries.
virtual void setSRID(int srid) _NOEXCEPT_OP(true)=0
It sets the Spatial Reference System ID of the geometry and all its parts if it is a GeometryCollecti...
TEGEOMEXPORT bool CheckValidity(const Geometry *geom, te::gm::TopologyValidationError &error)
It check geometry validity using GEOS.
TEGEOMEXPORT Envelope AdjustToCut(const Envelope &env, double bWidth, double bHeight)
Finds the correspondent smallest box that allows a box to be cut in blocks of a given size...
TEGEOMEXPORT std::vector< te::gm::Point > GetIntersectionPointsByPerpendicularDistance(const te::gm::LineString &lsReference, const std::vector< te::gm::LineString > &candidates)
Gets a vector of LineString reference points including intersection points using perpendicular distan...
TEGEOMEXPORT bool IsEqual(const te::gm::Point &p1, const te::gm::Point &p2)
Checks if a point p1 is exactly equal to the point p2.
LineString is a curve with linear interpolation between points.
void setPointN(std::size_t i, const Point &p)
It sets the value of the specified point to this new one.
TEGEOMEXPORT void AddPolygon(te::gm::Polygon *polygon, std::vector< te::gm::Geometry * > &pAdd)
Add all line strings from the polygon given to the vector given.
TEGEOMEXPORT LineString * AddIntersectionPoints(const te::sam::rtree::Index< std::size_t, 8 > &rtree, const std::vector< te::gm::LineString > &candidateSegments, const std::set< std::size_t > &setIndexesIgnored, const te::gm::LineString &lr_Reference, const bool &usePerpendicularDistance=false)
Add intersection points in a LinearRing based on a Vector of LineString as reference.
TEGEOMEXPORT void AddLineString(te::gm::LineString *lineString, std::vector< te::gm::Geometry * > &pAdd)
Add the linestring given to the vector.
virtual bool crosses(const Geometry *const rhs) const _NOEXCEPT_OP(false)
It returns true if the geometry object spatially crosses rhs geometry.
It is a collection of other geometric objects.
TEGEOMEXPORT te::gm::Polygon CreatePolygon(const te::gm::Envelope &box, const int &srid, const int &numberOfIntermediateCoords)
Creates a Polygon from the given envelope and with the given number of intermediate coordinates in ea...
TEGEOMEXPORT te::gm::Line * GetIntersectionLine(te::gm::Geometry *geom, te::gm::Coord2D coord)
This struct contains informations about GEOS TopologyValidationError.
void FreeContents(boost::unordered_map< K, V * > &m)
This function can be applied to a map of pointers. It will delete each pointer in the map...
An exception class for the Geometry module.
std::unique_ptr< Point > getStartPoint() const
The length of this Curve in its associated spatial reference.
TEGEOMEXPORT te::gm::GeomType GetMultiLineStringType(const te::gm::Geometry &geometry)
Get the LineStrings that compose the Geometry.
const double & getX() const
It returns the Point x-coordinate value.
TEGEOMEXPORT te::gm::Geometry * Validate(te::gm::Geometry *geom)
Get/create a valid version of the geometry given. If the geometry is a polygon or multi polygon...
It is a collection of other geometric objects.
TEGEOMEXPORT Geometry * GetGeomFromEnvelope(const Envelope *const e, int srid)
It creates a Geometry (a polygon) from the given envelope.
virtual bool coveredBy(const Geometry *const rhs) const _NOEXCEPT_OP(false)
It returns true if this geometry object is spatially covered by rhs geometry.
std::size_t size() const
It returns the number of points (vertexes) in the geometry.
virtual bool equals(const Geometry *const rhs, const bool exact=false) const _NOEXCEPT_OP(false)
It returns true if the geometry object is spatially equal to rhs geometry.
void setRingN(std::size_t i, Curve *r)
It sets the informed position ring to the new one.
virtual bool covers(const Geometry *const rhs) const _NOEXCEPT_OP(false)
It returns true if this geometry object spatially covers the rhs geometry.