void wxSimpleFillSymbol::DrawPolygon(OGRPolygon* pPoly, IDisplay* pwxGISDisplay) { IDisplayTransformation* pDisplayTransformation = pwxGISDisplay->GetDisplayTransformation(); int NumInteriorRings = pPoly->getNumInteriorRings(); OGRLinearRing *pRing = pPoly->getExteriorRing(); OGRLineString *pLStr = (OGRLineString*)pRing; int nPointCount = pLStr->getNumPoints(); if(nPointCount > 2) { if(NumInteriorRings == 0) { OGRRawPoint* pOGRRawPoints = new OGRRawPoint[nPointCount]; pLStr->getPoints(pOGRRawPoints); wxPoint* pPoints = pDisplayTransformation->TransformCoordWorld2DC(pOGRRawPoints, nPointCount); delete[](pOGRRawPoints); pwxGISDisplay->DrawPolygon(nPointCount, pPoints); delete[](pPoints); } else { int *nN = new int[NumInteriorRings + 1]; nN[0] = nPointCount; int jPoint(nPointCount); for(int iPart = 0; iPart < NumInteriorRings; iPart++) { pRing = pPoly->getInteriorRing(iPart); OGRLineString *pLStrInt = (OGRLineString*)pRing; nPointCount = pLStrInt->getNumPoints(); jPoint += (nN[iPart + 1] = nPointCount > 2 ? nPointCount/* + 1*/ : 0); } wxPoint *pFullPoints = new wxPoint[jPoint]; OGRRawPoint* pOGRRawPoints = new OGRRawPoint[nN[0]]; pLStr->getPoints(pOGRRawPoints); int counter(0); pDisplayTransformation->TransformCoordWorld2DC(pOGRRawPoints, nN[0], &pFullPoints[counter]); delete[](pOGRRawPoints); counter += nN[0]; for(int iPart = 0; iPart < NumInteriorRings; iPart++) { pRing = pPoly->getInteriorRing(iPart); OGRLineString *pLStrInt = (OGRLineString*)pRing; pOGRRawPoints = new OGRRawPoint[nN[iPart + 1]]; pLStrInt->getPoints(pOGRRawPoints); pDisplayTransformation->TransformCoordWorld2DC(pOGRRawPoints, nN[iPart + 1], &pFullPoints[counter]); delete[](pOGRRawPoints); counter += nN[iPart + 1]; } pwxGISDisplay->DrawPolyPolygon(NumInteriorRings + 1, nN, pFullPoints, 0, 0, wxODDEVEN_RULE); delete[](pFullPoints); delete[](nN); } } }
int OGR_G_GetPoints( OGRGeometryH hGeom, void* pabyX, int nXStride, void* pabyY, int nYStride, void* pabyZ, int nZStride) { VALIDATE_POINTER1( hGeom, "OGR_G_GetPoints", 0 ); switch( wkbFlatten(((OGRGeometry *) hGeom)->getGeometryType()) ) { case wkbPoint: { if (pabyX) *((double*)pabyX) = ((OGRPoint *)hGeom)->getX(); if (pabyY) *((double*)pabyY) = ((OGRPoint *)hGeom)->getY(); if (pabyZ) *((double*)pabyZ) = ((OGRPoint *)hGeom)->getZ(); return 1; } break; case wkbLineString: { OGRLineString* poLS = (OGRLineString *) hGeom; poLS->getPoints(pabyX, nXStride, pabyY, nYStride, pabyZ, nZStride); return poLS->getNumPoints(); } break; default: CPLError(CE_Failure, CPLE_NotSupported, "Incompatible geometry for operation"); return 0; break; } }
//! Simplifies the OGR-geometry (Removing duplicated points) when is applied the specified map2pixel context bool QgsOgrMapToPixelSimplifier::simplifyOgrGeometry( OGRGeometry* geometry, bool isaLinearRing ) { OGRwkbGeometryType wkbGeometryType = wkbFlatten( geometry->getGeometryType() ); // Simplify the geometry rewriting temporally its WKB-stream for saving calloc's. if ( wkbGeometryType == wkbLineString ) { OGRLineString* lineString = ( OGRLineString* )geometry; int numPoints = lineString->getNumPoints(); if (( isaLinearRing && numPoints <= 5 ) || ( !isaLinearRing && numPoints <= 2 ) ) return false; OGREnvelope env; geometry->getEnvelope( &env ); QgsRectangle envelope( env.MinX, env.MinY, env.MaxX, env.MaxY ); // Can replace the geometry by its BBOX ? if (( mSimplifyFlags & QgsMapToPixelSimplifier::SimplifyEnvelope ) && canbeGeneralizedByMapBoundingBox( envelope ) ) { OGRRawPoint* points = NULL; int numPoints = 0; double x1 = envelope.xMinimum(); double y1 = envelope.yMinimum(); double x2 = envelope.xMaximum(); double y2 = envelope.yMaximum(); if ( isaLinearRing ) { numPoints = 5; points = mallocPoints( numPoints ); points[0].x = x1; points[0].y = y1; points[1].x = x2; points[1].y = y1; points[2].x = x2; points[2].y = y2; points[3].x = x1; points[3].y = y2; points[4].x = x1; points[4].y = y1; } else { numPoints = 2; points = mallocPoints( numPoints ); points[0].x = x1; points[0].y = y1; points[1].x = x2; points[1].y = y2; } lineString->setPoints( numPoints, points ); lineString->flattenTo2D(); return true; } else if ( mSimplifyFlags & QgsMapToPixelSimplifier::SimplifyGeometry ) { QGis::GeometryType geometryType = isaLinearRing ? QGis::Polygon : QGis::Line; int numSimplifiedPoints = 0; OGRRawPoint* points = mallocPoints( numPoints ); double* xptr = ( double* )points; double* yptr = xptr + 1; lineString->getPoints( points ); if ( simplifyOgrGeometry( geometryType, envelope, xptr, 16, yptr, 16, numPoints, numSimplifiedPoints ) ) { lineString->setPoints( numSimplifiedPoints, points ); lineString->flattenTo2D(); } return numSimplifiedPoints != numPoints; } } else if ( wkbGeometryType == wkbPolygon ) { OGRPolygon* polygon = ( OGRPolygon* )geometry; bool result = simplifyOgrGeometry( polygon->getExteriorRing(), true ); for ( int i = 0, numInteriorRings = polygon->getNumInteriorRings(); i < numInteriorRings; ++i ) { result |= simplifyOgrGeometry( polygon->getInteriorRing( i ), true ); } if ( result ) polygon->flattenTo2D(); return result; } else if ( wkbGeometryType == wkbMultiLineString || wkbGeometryType == wkbMultiPolygon ) { OGRGeometryCollection* collection = ( OGRGeometryCollection* )geometry; bool result = false; for ( int i = 0, numGeometries = collection->getNumGeometries(); i < numGeometries; ++i ) { result |= simplifyOgrGeometry( collection->getGeometryRef( i ), wkbGeometryType == wkbMultiPolygon ); } if ( result ) collection->flattenTo2D(); return result; } return false; }
void wxSimpleFillSymbol::DrawPolyPolygon(OGRMultiPolygon* pPoly, IDisplay* pwxGISDisplay) { IDisplayTransformation* pDisplayTransformation = pwxGISDisplay->GetDisplayTransformation(); long nNumPolys(0); OGRGeometryCollection* pOGRGeometryCollection = (OGRGeometryCollection*)pPoly; for(int i = 0; i < pOGRGeometryCollection->getNumGeometries(); i++) { OGRPolygon* pPolygon = (OGRPolygon*)pOGRGeometryCollection->getGeometryRef(i); nNumPolys += pPolygon->getNumInteriorRings() + 1; } int *nN = new int[nNumPolys]; long counter(0); long point_count(0); for(int i = 0; i < pOGRGeometryCollection->getNumGeometries(); i++) { OGRPolygon* pPolygon = (OGRPolygon*)pOGRGeometryCollection->getGeometryRef(i); OGRLinearRing *pRing = pPolygon->getExteriorRing(); OGRLineString *pLStr = (OGRLineString*)pRing; nN[counter] = pLStr->getNumPoints(); point_count += nN[counter]; counter++; int NumInteriorRings = pPolygon->getNumInteriorRings(); for(int iPart = 0; iPart < NumInteriorRings; iPart++) { pRing = pPolygon->getInteriorRing(iPart); OGRLineString *pLStrInt = (OGRLineString*)pRing; nN[counter] = pLStrInt->getNumPoints(); point_count += nN[counter]; counter++; } } wxPoint *pFullPoints = new wxPoint[point_count]; counter = 0; long pos = 0; for(int i = 0; i < pOGRGeometryCollection->getNumGeometries(); i++) { OGRPolygon* pPolygon = (OGRPolygon*)pOGRGeometryCollection->getGeometryRef(i); OGRLinearRing *pRing = pPolygon->getExteriorRing(); OGRLineString *pLStr = (OGRLineString*)pRing; OGRRawPoint* pOGRRawPoints = new OGRRawPoint[nN[counter]]; pLStr->getPoints(pOGRRawPoints); pDisplayTransformation->TransformCoordWorld2DC(pOGRRawPoints, nN[counter], &pFullPoints[pos]); pos += nN[counter]; delete[](pOGRRawPoints); counter++; int NumInteriorRings = pPolygon->getNumInteriorRings(); for(int iPart = 0; iPart < NumInteriorRings; iPart++) { pRing = pPolygon->getInteriorRing(iPart); OGRLineString *pLStrInt = (OGRLineString*)pRing; pOGRRawPoints = new OGRRawPoint[nN[counter]]; pLStrInt->getPoints(pOGRRawPoints); pDisplayTransformation->TransformCoordWorld2DC(pOGRRawPoints, nN[counter], &pFullPoints[pos]); pos += nN[counter]; delete[](pOGRRawPoints); counter++; } } pwxGISDisplay->DrawPolyPolygon(nNumPolys, nN, pFullPoints, 0, 0, wxODDEVEN_RULE); delete[](pFullPoints); delete[](nN); }