| 187 | |
| 188 | |
| 189 | void CropFilter::transform(const SpatialReference& srs) |
| 190 | { |
| 191 | for (auto& geom : m_geoms) |
| 192 | { |
| 193 | auto ok = geom.m_poly.transform(srs); |
| 194 | if (!ok) |
| 195 | throwError(ok.what()); |
| 196 | geom.m_gridPnps.clear(); |
| 197 | std::vector<Polygon> polys = geom.m_poly.polygons(); |
| 198 | for (auto& p : polys) |
| 199 | { |
| 200 | std::unique_ptr<GridPnp> gridPnp(new GridPnp( |
| 201 | p.exteriorRing(), p.interiorRings())); |
| 202 | geom.m_gridPnps.push_back(std::move(gridPnp)); |
| 203 | } |
| 204 | } |
| 205 | |
| 206 | // If we don't have any SRS, do nothing. |
| 207 | if (srs.empty() && m_args->m_assignedSrs.empty()) |
| 208 | return; |
| 209 | |
| 210 | // Note that we should never have assigned SRS empty here since |
| 211 | // if it is missing we assign it from the point data. |
| 212 | assert(!m_args->m_assignedSrs.empty()); |
| 213 | if (srs.empty() || m_args->m_assignedSrs.empty()) |
| 214 | throwError("Unable to transform crop geometry to point coordinate system."); |
| 215 | |
| 216 | for (auto& box : m_boxes) |
| 217 | { |
| 218 | if (!gdal::reprojectBounds(box, m_args->m_assignedSrs.getWKT(), |
| 219 | srs.getWKT())) |
| 220 | throwError("Unable to reproject bounds."); |
| 221 | } |
| 222 | for (auto& point : m_args->m_centers) |
| 223 | { |
| 224 | point.setSpatialReference(m_args->m_assignedSrs); |
| 225 | auto ok = point.transform(srs); |
| 226 | if (!ok) |
| 227 | throwError(ok.what()); |
| 228 | } |
| 229 | // Set the assigned SRS for the points/bounds to the one we've |
| 230 | // transformed to. |
| 231 | m_args->m_assignedSrs = srs; |
| 232 | } |
| 233 | |
| 234 | |
| 235 | PointViewSet CropFilter::run(PointViewPtr view) |
no test coverage detected