//--------------------------------------------------------- void CGrid_Cross_Profiles::Make_Report(const SG_Char *FileName, CSG_Grid *pDEM, CSG_Shapes *pLines, CSG_Shapes *pProfiles, double Distance) { if( FileName ) { int iProfile, iPoint, nSamples, iBox; CSG_Rect r; CSG_Shape *pProfile, *pLine; CSG_Shapes Profile; CSG_Doc_PDF pdf; pdf.Open(PDF_PAGE_SIZE_A4, PDF_PAGE_ORIENTATION_PORTRAIT, _TL("Cross Profiles")); pdf.Layout_Add_Box(5, 5, 95, 20); pdf.Layout_Add_Box(5, 25, 95, 45); pdf.Layout_Add_Box(5, 50, 95, 70); pdf.Layout_Add_Box(5, 75, 95, 90); nSamples = pProfiles->Get_Field_Count() - OFFSET; Distance = Distance / (nSamples - 1); iBox = 0; for(iProfile=0; iProfile<pProfiles->Get_Count() && Set_Progress(iProfile, pProfiles->Get_Count()); iProfile++) { pProfile = pProfiles->Get_Shape(iProfile); Profile.Create(SHAPE_TYPE_Line); pLine = Profile.Add_Shape(); for(iPoint=0; iPoint<nSamples; iPoint++) { if( !pProfile->is_NoData(OFFSET + iPoint) ) { pLine->Add_Point( (iPoint - nSamples / 2) * Distance, pProfile->asDouble(OFFSET + iPoint) ); } } if( pLine->Get_Point_Count(0) > 1 ) { if( iBox >= NBOXES ) { pdf.Add_Page(); iBox = 0; } // pdf.Draw_Graticule (pdf.Layout_Get_Box(iBox), Profile.Get_Extent(), 20); // pdf.Draw_Shapes (pdf.Layout_Get_Box(iBox), &Profile); r = pLine->Get_Extent(); r.Inflate(10); pdf.Draw_Graticule (pdf.Layout_Get_Box(iBox), r, 15); pdf.Draw_Shape (pdf.Layout_Get_Box(iBox), pLine, PDF_STYLE_POLYGON_FILLSTROKE, SG_COLOR_GREEN, SG_COLOR_BLACK, 1, &r); iBox++; } } pdf.Save(Parameters("DOCUMENT")->asString()); } }
//--------------------------------------------------------- bool CGCS_Graticule::Get_Graticule(const CSG_Rect &Extent) { double x, y, Interval; CSG_Rect r; if( !Get_Extent(Extent, r) || (Interval = Get_Interval(r)) <= 0.0 ) { return( false ); } //----------------------------------------------------- r.m_rect.xMin = Interval * floor(r.Get_XMin() / Interval); r.m_rect.xMax = Interval * ceil (r.Get_XMax() / Interval); r.m_rect.yMin = Interval * floor(r.Get_YMin() / Interval); r.m_rect.yMax = Interval * ceil (r.Get_YMax() / Interval); r.Inflate(Interval, false); if( r.Get_XMin() < -180.0 ) r.m_rect.xMin = -180.0; if( r.Get_XMax() > 180.0 ) r.m_rect.xMax = 180.0; if( r.Get_YMin() < -90.0 ) r.m_rect.yMin = -90.0; if( r.Get_YMax() > 90.0 ) r.m_rect.yMax = 90.0; //----------------------------------------------------- double Resolution = Parameters("RESOLUTION")->asDouble(); if( Resolution <= 0.0 ) Resolution = Interval; if( Interval > Resolution ) { Resolution = Interval / ceil(Interval / Resolution); } //----------------------------------------------------- CSG_Shapes *pGraticule = Parameters("GRATICULE")->asShapes(); pGraticule->Create(SHAPE_TYPE_Line); pGraticule->Set_Name(_TL("Graticule")); pGraticule->Add_Field("TYPE" , SG_DATATYPE_String); pGraticule->Add_Field("LABEL" , SG_DATATYPE_String); pGraticule->Add_Field("DEGREE", SG_DATATYPE_Double); //----------------------------------------------------- CSG_Shapes *pCoordinates = Parameters("COORDS")->asShapes(); if( pCoordinates ) { pCoordinates->Create(SHAPE_TYPE_Point); pCoordinates->Set_Name(_TL("Coordinates")); pCoordinates->Add_Field("TYPE" , SG_DATATYPE_String); pCoordinates->Add_Field("LABEL", SG_DATATYPE_String); } //----------------------------------------------------- CSG_Shapes Clip(SHAPE_TYPE_Polygon); CSG_Shape *pClip = Clip.Add_Shape(); pClip->Add_Point(Extent.Get_XMin(), Extent.Get_YMin()); pClip->Add_Point(Extent.Get_XMin(), Extent.Get_YMax()); pClip->Add_Point(Extent.Get_XMax(), Extent.Get_YMax()); pClip->Add_Point(Extent.Get_XMax(), Extent.Get_YMin()); pClip->Add_Point(Extent.Get_XMin(), Extent.Get_YMin()); //----------------------------------------------------- for(y=r.Get_YMin(); y<=r.Get_YMax(); y+=Interval) { CSG_Shape *pLine = pGraticule->Add_Shape(); pLine->Set_Value(0, "LAT"); pLine->Set_Value(1, Get_Degree(y, DEG_PREC_DEG)); pLine->Set_Value(2, y); for(x=r.Get_XMin(); x<=r.Get_XMax(); x+=Interval) { CSG_Point p(x, y); m_Projector.Get_Projection(p); pLine->Add_Point(p); if( Resolution < Interval && x < r.Get_XMax() ) { for(double i=x+Resolution; i<x+Interval; i+=Resolution) { CSG_Point p(i, y); m_Projector.Get_Projection(p); pLine->Add_Point(p); } } } Get_Coordinate(Extent, pCoordinates, pLine, AXIS_LEFT); Get_Coordinate(Extent, pCoordinates, pLine, AXIS_RIGHT); if( !SG_Polygon_Intersection(pLine, pClip) ) { pGraticule->Del_Shape(pLine); } } //----------------------------------------------------- for(x=r.Get_XMin(); x<=r.Get_XMax(); x+=Interval) { CSG_Shape *pLine = pGraticule->Add_Shape(); pLine->Set_Value(0, "LON"); pLine->Set_Value(1, Get_Degree(x, DEG_PREC_DEG)); pLine->Set_Value(2, x); for(y=r.Get_YMin(); y<=r.Get_YMax(); y+=Interval) { CSG_Point p(x, y); m_Projector.Get_Projection(p); pLine->Add_Point(p); if( Resolution < Interval && y < r.Get_YMax() ) { for(double i=y+Resolution; i<y+Interval; i+=Resolution) { CSG_Point p(x, i); m_Projector.Get_Projection(p); pLine->Add_Point(p); } } } Get_Coordinate(Extent, pCoordinates, pLine, AXIS_BOTTOM); Get_Coordinate(Extent, pCoordinates, pLine, AXIS_TOP); if( !SG_Polygon_Intersection(pLine, pClip) ) { pGraticule->Del_Shape(pLine); } } //----------------------------------------------------- return( true ); }