//--------------------------------------------------------- CSG_Shape * CSG_PointCloud::Get_Shape(TSG_Point Point, double Epsilon) { CSG_Rect r(Point.x - Epsilon, Point.y - Epsilon, Point.x + Epsilon, Point.y + Epsilon); if( r.Intersects(Get_Extent()) != INTERSECTION_None ) { int iPoint = -1; double iDistance = -1.0; for(int iRecord=0; iRecord<Get_Count(); iRecord++) { Set_Cursor(iRecord); if( r.Contains(Get_X(), Get_Y()) ) { if( iPoint < 0 || iDistance > SG_Get_Distance(Point.x, Point.y, Get_X(), Get_Y()) ) { iPoint = iRecord; iDistance = SG_Get_Distance(Point.x, Point.y, Get_X(), Get_Y()); } } } if( iPoint >= 0 ) { return( CSG_Shapes::Get_Shape(iPoint) ); } } return( NULL ); }
//--------------------------------------------------------- void CVIEW_Map_Control::_Draw_Inverse(wxPoint ptA, wxPoint ptB_Old, wxPoint ptB_New) { if( m_Drag_Mode != TOOL_INTERACTIVE_DRAG_NONE ) { wxClientDC dc(this); dc.SetLogicalFunction(wxINVERT); switch( m_Drag_Mode ) { case TOOL_INTERACTIVE_DRAG_LINE: dc.DrawLine (ptA.x, ptA.y, ptB_Old.x, ptB_Old.y); dc.DrawLine (ptA.x, ptA.y, ptB_New.x, ptB_New.y); break; case TOOL_INTERACTIVE_DRAG_BOX: dc.DrawRectangle (ptA.x, ptA.y, ptB_Old.x - ptA.x, ptB_Old.y - ptA.y); dc.DrawRectangle (ptA.x, ptA.y, ptB_New.x - ptA.x, ptB_New.y - ptA.y); break; case TOOL_INTERACTIVE_DRAG_CIRCLE: dc.DrawCircle (ptA.x, ptA.y, (int)SG_Get_Distance(ptA.x, ptA.y, ptB_Old.x, ptB_Old.y)); dc.DrawCircle (ptA.x, ptA.y, (int)SG_Get_Distance(ptA.x, ptA.y, ptB_New.x, ptB_New.y)); break; } } }
//--------------------------------------------------------- bool CGW_Regression::Get_Model(int x, int y, CSG_Regression_Weighted &Model) { //----------------------------------------------------- TSG_Point Point = m_pIntercept->Get_System().Get_Grid_to_World(x, y); int nPoints = m_Search.Set_Location(Point); Model.Destroy(); for(int iPoint=0; iPoint<nPoints; iPoint++) { double ix, iy, iz; CSG_Shape *pPoint = m_Search.Do_Use_All() && m_Search.Get_Point(iPoint, ix, iy, iz) ? m_pPoints->Get_Shape((int)iz) : m_pPoints->Get_Shape(iPoint); if( !pPoint->is_NoData(m_iDependent) && !pPoint->is_NoData(m_iPredictor) ) { Model.Add_Sample( m_Weighting.Get_Weight(SG_Get_Distance(Point, pPoint->Get_Point(0))), pPoint->asDouble(m_iDependent), CSG_Vector(1, &(iz = pPoint->asDouble(m_iPredictor))) ); } } //----------------------------------------------------- return( Model.Calculate() ); }
//--------------------------------------------------------- int CGW_Multi_Regression_Grid::Get_Variables(int x, int y, CSG_Vector &z, CSG_Vector &w, CSG_Matrix &Y) { TSG_Point Point = m_dimModel.Get_Grid_to_World(x, y); int nPoints = m_Search.is_Okay() ? (int)m_Search.Select_Nearest_Points(Point.x, Point.y, m_nPoints_Max, m_Radius, m_Direction) : m_Points.Get_Count(); z.Create(nPoints); w.Create(nPoints); Y.Create(1 + m_nPredictors, nPoints); for(int iPoint=0; iPoint<nPoints; iPoint++) { double ix, iy, iz; CSG_Shape *pPoint = m_Search.is_Okay() && m_Search.Get_Selected_Point(iPoint, ix, iy, iz) ? m_Points.Get_Shape((int)iz) : m_Points.Get_Shape(iPoint); z[iPoint] = pPoint->asDouble(0); w[iPoint] = m_Weighting.Get_Weight(SG_Get_Distance(Point, pPoint->Get_Point(0))); Y[iPoint][0] = 1.0; for(int iPredictor=1; iPredictor<=m_nPredictors; iPredictor++) { Y[iPoint][iPredictor] = pPoint->asDouble(iPredictor); } } return( nPoints ); }
//--------------------------------------------------------- double CShape_Index::Get_Distance(CSG_Shape *pShape) { double d, dMax = 0.0; for(int iPart=0; iPart<pShape->Get_Part_Count(); iPart++) { if( pShape->Get_Point_Count(iPart) > 2 ) { TSG_Point A, B; A = pShape->Get_Point(pShape->Get_Point_Count(iPart) - 1, iPart); for(int iPoint=0; iPoint<pShape->Get_Point_Count(iPart); iPoint++) { B = A; A = pShape->Get_Point(iPoint, iPart); d = SG_Get_Distance(A, B); if( dMax < d ) { dMax = d; } } } } return( dMax ); }
//--------------------------------------------------------- bool CShape_Index::Get_Diameter_Gyros(CSG_Shape_Polygon *pPolygon, int Field) { double Dmax = 0.0; TSG_Point C = pPolygon->Get_Centroid(); for(int iPart=0; iPart<pPolygon->Get_Part_Count(); iPart++) { for(int iPoint=0; iPoint<pPolygon->Get_Point_Count(iPart); iPoint++) { double d = SG_Get_Distance(C, pPolygon->Get_Point(iPoint, iPart)); if( d > Dmax ) { Dmax = d; } } } if( Dmax > 0.0 ) { pPolygon->Set_Value(Field, 2 * Dmax); return( true ); } pPolygon->Set_NoData(Field); return( false ); }
//--------------------------------------------------------- double CSG_Variogram::Get_Lag_Distance(CSG_Shapes *pPoints, int Method, int nSkip) { if( Method == 0 ) { CSG_PRQuadTree QT(pPoints, 0); CSG_Simple_Statistics s; double x, y, z; if( nSkip < 1 ) { nSkip = 1; } for(int iPoint=0; iPoint<pPoints->Get_Count() && ::SG_UI_Process_Set_Progress(iPoint, pPoints->Get_Count()); iPoint+=nSkip) { TSG_Point p = pPoints->Get_Shape(iPoint)->Get_Point(0); if( QT.Select_Nearest_Points(p.x, p.y, 2) && QT.Get_Selected_Point(1, x, y, z) && (x != p.x || y != p.y) ) { s.Add_Value(SG_Get_Distance(x, y, p.x, p.y)); } } if( s.Get_Count() > 0 && s.Get_Mean() > 0.0 ) { return( s.Get_Mean() ); } } return( 0.25 * sqrt((pPoints->Get_Extent().Get_XRange() * pPoints->Get_Extent().Get_YRange()) / pPoints->Get_Count()) ); }
//--------------------------------------------------------- bool CGrid_Profile::Add_Point(CSG_Point Point) { int x, y, i; double z, Distance, Distance_2; CSG_Shape *pPoint, *pLast; if( Get_System()->Get_World_to_Grid(x, y, Point) && m_pDEM->is_InGrid(x, y) ) { z = m_pDEM->asDouble(x, y); if( m_pPoints->Get_Count() == 0 ) { Distance = 0.0; Distance_2 = 0.0; } else { pLast = m_pPoints->Get_Shape(m_pPoints->Get_Count() - 1); Distance = SG_Get_Distance(Point, pLast->Get_Point(0)); if( Distance == 0.0 ) { return( false ); } Distance_2 = pLast->asDouble(5) - z; Distance_2 = sqrt(Distance*Distance + Distance_2*Distance_2); Distance += pLast->asDouble(1); Distance_2 += pLast->asDouble(2); } pPoint = m_pPoints->Add_Shape(); pPoint->Add_Point(Point); pPoint->Set_Value(0, m_pPoints->Get_Count()); pPoint->Set_Value(1, Distance); pPoint->Set_Value(2, Distance_2); pPoint->Set_Value(3, Point.Get_X()); pPoint->Set_Value(4, Point.Get_Y()); pPoint->Set_Value(5, z); for(i=0; i<m_pValues->Get_Count(); i++) { pPoint->Set_Value(VALUE_OFFSET + i, m_pValues->asGrid(i)->asDouble(x, y, true)); } return( true ); } return( false ); }
//--------------------------------------------------------- CSG_PRQuadTree_Leaf * CSG_PRQuadTree::_Get_Nearest_Point(CSG_PRQuadTree_Item *pItem, double x, double y, double &Distance) const { CSG_PRQuadTree_Leaf *pLeaf, *pNearest = NULL; if( pItem ) { if( pItem->is_Leaf() ) { pLeaf = (CSG_PRQuadTree_Leaf *)pItem; double d = SG_Get_Distance(x, y, pLeaf->Get_X(), pLeaf->Get_Y(), m_bPolar); if( Distance < 0.0 || Distance > d ) { Distance = d; pNearest = pLeaf; } } else // if( pItem->is_Node() ) { int i; if( pItem->Contains(x, y) ) { for(i=0; i<4; i++) { CSG_PRQuadTree_Item *pChild = ((CSG_PRQuadTree_Node *)pItem)->Get_Child(i); if( pChild && pChild->Contains(x, y) && (pLeaf = _Get_Nearest_Point(pChild, x, y, Distance)) != NULL ) { pNearest = pLeaf; } } } for(i=0; i<4; i++) { CSG_PRQuadTree_Item *pChild = ((CSG_PRQuadTree_Node *)pItem)->Get_Child(i); if( pChild && pChild->Contains(x, y) == false && (Distance < 0.0 || ( Distance > (x < pChild->Get_xCenter() ? pChild->Get_xMin() - x : x - pChild->Get_xMax()) && Distance > (y < pChild->Get_yCenter() ? pChild->Get_yMin() - y : y - pChild->Get_yMax()) )) && (pLeaf = _Get_Nearest_Point(pChild, x, y, Distance)) != NULL ) { pNearest = pLeaf; } } } } return( pNearest ); }
//--------------------------------------------------------- bool CInterpolation_AngularDistance::Get_Value(double x, double y, double &z) { int i, j, n; if( (n = m_Search.Set_Location(x, y)) <= 0 ) { return( false ); } //----------------------------------------------------- CSG_Vector X(n), Y(n), D(n), W(n), Z(n); for(i=0; i<n; i++) { m_Search.Get_Point(i, X[i], Y[i], Z[i]); D[i] = SG_Get_Distance(x, y, X[i], Y[i]); W[i] = m_Weighting.Get_Weight(D[i]); if( D[i] <= 0.0 ) { z = Z[i]; return( true ); } } //----------------------------------------------------- CSG_Simple_Statistics s; for(i=0; i<n; i++) { double w = 0.0, t = 0.0; for(j=0; j<n; j++) { if( j != i ) { t += W[j] * (1.0 - ((x - X[i]) * (x - X[j]) + (y - Y[i]) * (y - Y[j])) / (D[i] * D[j])); w += W[j]; } } s.Add_Value(Z[i], W[i] * (1.0 + t / w)); } //----------------------------------------------------- z = s.Get_Mean(); return( true ); }
//--------------------------------------------------------- bool CGrid_Flow_Profile::Add_Point(int x, int y) { if( !m_pDEM->is_InGrid(x, y) ) { return( false ); } TSG_Point Point = Get_System()->Get_Grid_to_World(x, y); double d, dSurface; if( m_pPoints->Get_Count() == 0 ) { d = dSurface = 0.0; } else { CSG_Shape *pLast = m_pPoints->Get_Shape(m_pPoints->Get_Count() - 1); d = SG_Get_Distance(Point, pLast->Get_Point(0)); dSurface = pLast->asDouble(5) - m_pDEM->asDouble(x, y); dSurface = sqrt(d*d + dSurface*dSurface); d += pLast->asDouble(1); dSurface += pLast->asDouble(2); } CSG_Shape *pPoint = m_pPoints->Add_Shape(); pPoint->Add_Point(Point); pPoint->Set_Value(0, m_pPoints->Get_Count()); pPoint->Set_Value(1, d); pPoint->Set_Value(2, dSurface); pPoint->Set_Value(3, Point.x); pPoint->Set_Value(4, Point.y); pPoint->Set_Value(5, m_pDEM->asDouble(x, y)); for(int i=0; i<m_pValues->Get_Count(); i++) { pPoint->Set_Value(VALUE_OFFSET + i, m_pValues->asGrid(i)->asDouble(x, y)); } m_pLine->Add_Point(Point); return( true ); }
//--------------------------------------------------------- bool CGSPoints_Distances::On_Execute(void) { //----------------------------------------------------- CSG_Shapes *pPoints = Parameters("POINTS") ->asShapes(); CSG_Table *pTable = Parameters("TABLE") ->asTable(); //----------------------------------------------------- CSG_PRQuadTree QT(pPoints, 0); CSG_Simple_Statistics s; double x, y, z; for(int iPoint=0; iPoint<pPoints->Get_Count() && Set_Progress(iPoint, pPoints->Get_Count()); iPoint++) { TSG_Point p = pPoints->Get_Shape(iPoint)->Get_Point(0); if( QT.Select_Nearest_Points(p.x, p.y, 2) && QT.Get_Selected_Point(1, x, y, z) && (x != p.x || y != p.y) ) { s.Add_Value(SG_Get_Distance(x, y, p.x, p.y)); } } //----------------------------------------------------- if( s.Get_Count() > 0 ) { CSG_Table_Record *pRecord; pTable->Destroy(); pTable->Set_Name(CSG_String::Format(SG_T("%s [%s]"), _TL("Minimum Distance Analysis"), pPoints->Get_Name())); pTable->Add_Field(SG_T("NAME") , SG_DATATYPE_String); pTable->Add_Field(SG_T("VALUE") , SG_DATATYPE_Double); SET_VALUE(_TL("Mean Average") , s.Get_Mean()); SET_VALUE(_TL("Minimum") , s.Get_Minimum()); SET_VALUE(_TL("Maximum") , s.Get_Maximum()); SET_VALUE(_TL("Standard Deviation") , s.Get_StdDev()); SET_VALUE(_TL("Duplicates") , pPoints->Get_Count() - s.Get_Count()); DataObject_Update(pTable, SG_UI_DATAOBJECT_SHOW); return( true ); } Message_Dlg(_TL("not enough observations")); return( false ); }
//--------------------------------------------------------- void CVIEW_Map_Control::_Distance_Add(wxPoint Point) { int n = m_Distance_Pts.Get_Count(); m_Distance_Pts.Add(_Get_World(Point)); if( n > 0 ) { m_Distance += SG_Get_Distance(m_Distance_Pts[n], m_Distance_Pts[n - 1]); } m_Distance_Move = 0.0; wxClientDC dc(this); _Distance_Draw(dc); }
//--------------------------------------------------------- int CGW_Multi_Regression::Set_Variables(int x, int y) { int iPoint, jPoint, nPoints, iPredictor; TSG_Point Point; CSG_Shape *pPoint; Point = m_pIntercept->Get_System().Get_Grid_to_World(x, y); nPoints = m_Search.is_Okay() ? m_Search.Select_Nearest_Points(Point.x, Point.y, m_nPoints_Max, m_Radius, m_Mode == 0 ? -1 : 4) : m_pPoints->Get_Count(); for(iPoint=0, jPoint=0; iPoint<nPoints; iPoint++) { if( m_Search.is_Okay() ) { double ix, iy, iz; m_Search.Get_Selected_Point(iPoint, ix, iy, iz); pPoint = m_pPoints->Get_Shape((int)iz); } else { pPoint = m_pPoints->Get_Shape(iPoint); } m_z[iPoint] = pPoint->asDouble(m_iDependent); m_w[iPoint] = m_Weighting.Get_Weight(SG_Get_Distance(Point, pPoint->Get_Point(0))); for(iPredictor=0; iPredictor<m_nPredictors; iPredictor++) { if( !pPoint->is_NoData(m_iPredictor[iPredictor]) ) { m_y[jPoint][iPredictor] = pPoint->asDouble(m_iPredictor[iPredictor]); } else { iPredictor = m_nPredictors + 1; } } if( iPredictor == m_nPredictors ) { jPoint++; } } return( jPoint ); }
//--------------------------------------------------------- void CGrid_Values_AddTo_Shapes::Get_Data_Line(CSG_Simple_Statistics &Statistics, CSG_Shape *pShape, CSG_Grid *pGrid) { double dStep = pGrid->Get_Cellsize(); for(int iPart=0; iPart<pShape->Get_Part_Count(); iPart++) { if( pShape->Get_Point_Count(iPart) > 0 ) { double Value; TSG_Point B, A = pShape->Get_Point(0, iPart); if( pGrid->Get_Value(A, Value, m_Resampling) ) { Statistics += Value; } for(int iPoint=1; iPoint<pShape->Get_Point_Count(iPart); iPoint++) { B = A; A = pShape->Get_Point(iPoint, iPart); //----------------------------------------- double Distance = SG_Get_Distance(A, B); if( Distance > 0.0 ) { double dx = (B.x - A.x) * dStep / Distance; double dy = (B.y - A.y) * dStep / Distance; TSG_Point C = A; for(double d=0.0; d<Distance; d+=dStep, C.x+=dx, C.y+=dy) { if( pGrid->Get_Value(C, Value, m_Resampling) ) { Statistics += Value; } } } } } } }
//--------------------------------------------------------- bool CLeastCostPathProfile_Points::Add_Point(int x, int y, CSG_Shapes *pPoints, CSG_Shapes *pLine) { int i; double Distance; TSG_Point Point; CSG_Shape *pPoint, *pLast; if( m_pDEM->is_InGrid(x, y) ) { Point = Get_System()->Get_Grid_to_World(x, y); if( pPoints->Get_Count() == 0 ) { Distance = 0.0; } else { pLast = pPoints->Get_Shape(pPoints->Get_Count() - 1); Distance = SG_Get_Distance(Point, pLast->Get_Point(0)); Distance += pLast->asDouble(1); } pPoint = pPoints->Add_Shape(); pPoint->Add_Point(Point); pPoint->Set_Value(0, pPoints->Get_Count()); pPoint->Set_Value(1, Distance); pPoint->Set_Value(2, Point.x); pPoint->Set_Value(3, Point.y); pPoint->Set_Value(4, m_pDEM->asDouble(x, y)); for( i=0; i<m_pValues->Get_Count(); i++ ) { pPoint->Set_Value(VALUE_OFFSET + i, m_pValues->asGrid(i)->asDouble(x, y)); } pLine->Get_Shape(0)->Add_Point(Point); return( true ); } return( false ); }
//--------------------------------------------------------- double CSG_Shape_Line::Get_Length(int iPart) { int iPoint; double Length; TSG_Point *pA, *pB; if( iPart >= 0 && iPart < m_nParts && m_pParts[iPart]->Get_Count() > 1 ) { pB = m_pParts[iPart]->m_Points; pA = pB + 1; for(iPoint=1, Length=0.0; iPoint<m_pParts[iPart]->Get_Count(); iPoint++, pB=pA++) { Length += SG_Get_Distance(*pA, *pB); } return( Length ); } return( 0.0 ); }
//--------------------------------------------------------- double CSG_Shape_Points::Get_Distance(TSG_Point Point, TSG_Point &Next, int iPart) { int i; double d, Distance; TSG_Point *pA; Distance = -1.0; if( iPart >= 0 && iPart < m_nParts ) { for(i=0, pA=m_pParts[iPart]->m_Points; i<m_pParts[iPart]->Get_Count() && Distance!=0.0; i++, pA++) { if( (d = SG_Get_Distance(Point, *pA)) < Distance || Distance < 0.0 ) { Distance = d; Next = *pA; } } } return( Distance ); }
//--------------------------------------------------------- bool CGrid_Histogram_Surface::Get_Circle(void) { long i; int n; double r; CSG_Grid *pHist; r = sqrt(m_pGrid->Get_NCells() / M_PI); n = 1 + (int)(2.0 * r); //----------------------------------------------------- Parameters("HIST")->Set_Value(pHist = SG_Create_Grid(m_pGrid->Get_Type(), n, n, m_pGrid->Get_Cellsize(), -r * m_pGrid->Get_Cellsize(), -r * m_pGrid->Get_Cellsize())); pHist->Set_NoData_Value_Range( m_pGrid->Get_NoData_Value(), m_pGrid->Get_NoData_hiValue() ); //----------------------------------------------------- for(int y=0; y<n && Set_Progress(y, n); y++) { for(int x=0; x<n; x++) { double d = SG_Get_Distance(x, y, r, r); if( d < r && m_pGrid->Get_Sorted((long)(d*d*M_PI), i) ) { pHist->Set_Value(x, y, m_pGrid->asDouble(i)); } else { pHist->Set_NoData(x, y); } } } //----------------------------------------------------- return( true ); }
//--------------------------------------------------------- inline bool CShapes_Buffer::Get_Parallel(const TSG_Point &A, const TSG_Point &B, TSG_Point AB[2], double Distance) { double d; TSG_Point C; if( (d = SG_Get_Distance(A, B)) > 0.0 ) { d = Distance / d; C.x = d * (A.y - B.y); C.y = d * (B.x - A.x); AB[0].x = A.x + C.x; AB[0].y = A.y + C.y; AB[1].x = B.x + C.x; AB[1].y = B.y + C.y; return( true ); } return( false ); }
//--------------------------------------------------------- bool CShape_Index::Get_Diameter_Max(CSG_Shape_Polygon *pPolygon, double &Dmax, TSG_Point Pmax[2]) { Dmax = 0.0; for(int iPoint=0; iPoint<pPolygon->Get_Point_Count(); iPoint++) { TSG_Point P = pPolygon->Get_Point(iPoint); for(int jPoint=iPoint+1; jPoint<pPolygon->Get_Point_Count(); jPoint++) { double d = SG_Get_Distance(P, pPolygon->Get_Point(jPoint)); if( Dmax < d ) { Dmax = d; Pmax[0] = P; Pmax[1] = pPolygon->Get_Point(jPoint); } } } return( Dmax > 0.0 ); }
//--------------------------------------------------------- int CGW_Regression_Grid::Set_Variables(int x, int y) { int iPoint, jPoint, nPoints; double z; TSG_Point Point; CSG_Shape *pPoint; Point = Get_System()->Get_Grid_to_World(x, y); nPoints = m_Search.is_Okay() ? (int)m_Search.Select_Nearest_Points(Point.x, Point.y, m_nPoints_Max, m_Radius, m_Direction) : m_pPoints->Get_Count(); for(iPoint=0, jPoint=0; iPoint<nPoints; iPoint++) { if( m_Search.is_Okay() ) { double ix, iy, iz; m_Search.Get_Selected_Point(iPoint, ix, iy, iz); pPoint = m_pPoints->Get_Shape((int)iz); } else { pPoint = m_pPoints->Get_Shape(iPoint); } if( !pPoint->is_NoData(m_iDependent) && m_pPredictor->Get_Value(pPoint->Get_Point(0), z) ) { m_w[jPoint] = m_Weighting.Get_Weight(SG_Get_Distance(Point, pPoint->Get_Point(0))); m_z[jPoint] = pPoint->asDouble(m_iDependent); m_y[jPoint] = z; jPoint++; } } return( jPoint ); }
//--------------------------------------------------------- void CVIEW_Map_Control::_Draw_Inverse(const wxPoint &A, const wxPoint &B) { if( m_Drag_Mode != TOOL_INTERACTIVE_DRAG_NONE ) { wxClientDC dc(this); dc.SetLogicalFunction(wxINVERT); switch( m_Drag_Mode ) { case TOOL_INTERACTIVE_DRAG_LINE: dc.DrawLine (A.x, A.y, B.x, B.y); break; case TOOL_INTERACTIVE_DRAG_BOX: dc.DrawRectangle(A.x, A.y, B.x - A.x, B.y - A.y); break; case TOOL_INTERACTIVE_DRAG_CIRCLE: dc.DrawCircle (A.x, A.y, (int)SG_Get_Distance(A.x, A.y, B.x, B.y)); break; } } }
//--------------------------------------------------------- double SG_Get_Distance(double ax, double ay, double bx, double by, bool bPolar) { return( bPolar ? SG_Get_Distance_Polar(ax, ay, bx, by) : SG_Get_Distance(ax, ay, bx, by) ); }
//--------------------------------------------------------- bool CGSPoints_Semi_Variances::On_Execute(void) { int i, j, k, n, nDistances, nSkip, Attribute; double zi, zj, zMean, v, c, maxDistance, lagDistance; TSG_Point Pt_i, Pt_j; CSG_Vector Count, Variance, Covariance; CSG_Table_Record *pRecord; CSG_Table *pTable; CSG_Shape *pPoint; CSG_Shapes *pPoints; //----------------------------------------------------- pPoints = Parameters("POINTS") ->asShapes(); pTable = Parameters("RESULT") ->asTable(); Attribute = Parameters("FIELD") ->asInt(); nSkip = Parameters("NSKIP") ->asInt(); maxDistance = Parameters("DISTMAX") ->asDouble(); nDistances = Parameters("DISTCOUNT") ->asInt(); if( maxDistance <= 0.0 ) { maxDistance = SG_Get_Length(pPoints->Get_Extent().Get_XRange(), pPoints->Get_Extent().Get_YRange()); } lagDistance = maxDistance / nDistances; zMean = pPoints->Get_Mean(Attribute); Count .Create(nDistances); Variance .Create(nDistances); Covariance .Create(nDistances); //----------------------------------------------------- for(i=0, n=0; i<pPoints->Get_Count() && Set_Progress(n, SG_Get_Square(pPoints->Get_Count()/nSkip)/2); i+=nSkip) { pPoint = pPoints->Get_Shape(i); if( !pPoint->is_NoData(Attribute) ) { Pt_i = pPoint->Get_Point(0); zi = pPoint->asDouble(Attribute); for(j=i+nSkip; j<pPoints->Get_Count(); j+=nSkip, n++) { pPoint = pPoints->Get_Shape(j); if( !pPoint->is_NoData(Attribute) ) { Pt_j = pPoint->Get_Point(0); k = (int)(SG_Get_Distance(Pt_i, Pt_j) / lagDistance); if( k < nDistances ) { zj = pPoint->asDouble(Attribute); v = SG_Get_Square(zi - zj); c = (zi - zMean) * (zj - zMean); Count [k] ++; Variance [k] += v; Covariance[k] += c; } } } } } //----------------------------------------------------- pTable->Destroy(); pTable->Set_Name(CSG_String::Format(SG_T("%s [%s: %s]"), pPoints->Get_Name(), _TL("Variogram"), pPoints->Get_Field_Name(Attribute))); pTable->Add_Field(_TL("Class") , SG_DATATYPE_Int); // FIELD_CLASSNR pTable->Add_Field(_TL("Distance") , SG_DATATYPE_Double); // FIELD_DISTANCE pTable->Add_Field(_TL("Count") , SG_DATATYPE_Int); // FIELD_COUNT pTable->Add_Field(_TL("Variance") , SG_DATATYPE_Double); // FIELD_VARIANCE pTable->Add_Field(_TL("Cum.Var.") , SG_DATATYPE_Double); // FIELD_VARCUMUL pTable->Add_Field(_TL("Covariance") , SG_DATATYPE_Double); // FIELD_COVARIANCE pTable->Add_Field(_TL("Cum.Covar.") , SG_DATATYPE_Double); // FIELD_COVARCUMUL for(i=0, v=0.0, c=0.0, n=0; i<nDistances; i++) { if( Count[i] > 0 ) { n += (int)Count[i]; v += Variance [i]; c += Covariance[i]; pRecord = pTable->Add_Record(); pRecord->Set_Value(FIELD_CLASSNR , (i + 1)); pRecord->Set_Value(FIELD_DISTANCE , (i + 1) * lagDistance); pRecord->Set_Value(FIELD_COUNT , Count[i]); pRecord->Set_Value(FIELD_VARIANCE , 0.5 * Variance [i] / Count[i]); pRecord->Set_Value(FIELD_VARCUMUL , 0.5 * v / n); pRecord->Set_Value(FIELD_COVARIANCE , 1.0 * Covariance[i] / Count[i]); pRecord->Set_Value(FIELD_COVARCUMUL , 1.0 * c / n); } } return( true ); }
//--------------------------------------------------------- void CVIEW_Map_Control::On_Mouse_Motion(wxMouseEvent &event) { wxPoint Point = event.GetPosition(); switch( m_Mode ) { //----------------------------------------------------- case MAP_MODE_SELECT: if( g_pTool ) { TSG_Tool_Interactive_Mode iMode = event.LeftIsDown () ? TOOL_INTERACTIVE_MOVE_LDOWN : event.MiddleIsDown() ? TOOL_INTERACTIVE_MOVE_MDOWN : event.RightIsDown () ? TOOL_INTERACTIVE_MOVE_RDOWN : TOOL_INTERACTIVE_MOVE; g_pTool->Execute(_Get_Client2World(Point), iMode, GET_KEYS(event)); } else if( m_pMap->Find_Layer(Get_Active_Layer()) ) { Get_Active_Layer()->Edit_On_Mouse_Move( this, m_pMap->Get_World(GetClientSize()), Point, m_Mouse_Move, GET_KEYS(event) ); } break; //----------------------------------------------------- case MAP_MODE_DISTANCE: if( m_Distance_Pts.Get_Count() > 0 ) { int n = m_Distance_Pts.Get_Count(); wxClientDC dc(this); wxPoint Last(_Get_World2Client(m_Distance_Pts[n - 1])); dc.SetLogicalFunction(wxINVERT); dc.DrawLine(Last.x, Last.y, m_Mouse_Move.x, m_Mouse_Move.y); dc.DrawLine(Last.x, Last.y, Point.x, Point.y); m_Distance_Move = SG_Get_Distance(m_Distance_Pts[n - 1], _Get_Client2World(Point)); } break; //----------------------------------------------------- case MAP_MODE_ZOOM: break; //----------------------------------------------------- case MAP_MODE_PAN: break; //----------------------------------------------------- case MAP_MODE_PAN_DOWN: // _Move(m_Mouse_Down, Point); _Pan(m_Mouse_Down, Point); break; } //----------------------------------------------------- if( m_Mode != MAP_MODE_PAN_DOWN ) { m_pParent->Ruler_Set_Position(Point.x, Point.y); m_pMap->Set_Mouse_Position(_Get_Client2World(Point)); _Set_StatusBar(_Get_Client2World(Point)); } //----------------------------------------------------- _Draw_Inverse(m_Mouse_Down, m_Mouse_Move, Point); m_Mouse_Move = Point; }
//--------------------------------------------------------- void CSG_PRQuadTree::_Select_Nearest_Points(CSG_Array &Selection, CSG_PRQuadTree_Item *pItem, double x, double y, double &Distance, double Radius, size_t maxPoints, int iQuadrant) const { //----------------------------------------------------- if( pItem->is_Leaf() ) { CSG_PRQuadTree_Leaf *pLeaf = (CSG_PRQuadTree_Leaf *)pItem; if( _Quadrant_Contains(x, y, iQuadrant, pLeaf->Get_Point()) == false ) { return; } double d = SG_Get_Distance(x, y, pLeaf->Get_X(), pLeaf->Get_Y(), m_bPolar); if( Radius > 0.0 && Radius < d ) { return; } //------------------------------------------------- if( Selection.Get_Size() < maxPoints ) { if( Distance < d ) { Distance = d; } _Add_Selected(Selection, pLeaf, d); } else if( d < Distance ) { size_t i; for(i=0; i<Selection.Get_Size(); i++) { if( Distance <= _Get_Selected(Selection, i)->Distance ) { _Set_Selected(Selection, i, pLeaf, d); break; } } for(i=0, Distance=d; i<maxPoints; i++) { if( Distance < _Get_Selected(Selection, i)->Distance ) { Distance = _Get_Selected(Selection, i)->Distance; } } } } //----------------------------------------------------- else // if( pItem->is_Node() ) { int i; CSG_PRQuadTree_Item *pChild; for(i=0; i<4; i++) { if( (pChild = ((CSG_PRQuadTree_Node *)pItem)->Get_Child(i)) != NULL && pChild->Contains(x, y) == true ) { _Select_Nearest_Points(Selection, pChild, x, y, Distance, Radius, maxPoints, iQuadrant); } } for(i=0; i<4; i++) { if( (pChild = ((CSG_PRQuadTree_Node *)pItem)->Get_Child(i)) != NULL && pChild->Contains(x, y) == false ) { if( _Radius_Intersects(x, y, Radius, iQuadrant, pChild) ) { if( Get_Selected_Count() < maxPoints || ( Distance > (x < pChild->Get_xCenter() ? pChild->Get_xMin() - x : x - pChild->Get_xMax()) && Distance > (y < pChild->Get_yCenter() ? pChild->Get_yMin() - y : y - pChild->Get_yMax()) ) ) { _Select_Nearest_Points(Selection, pChild, x, y, Distance, Radius, maxPoints, iQuadrant); } } } } } }
//--------------------------------------------------------- double SG_Get_Distance(const TSG_Point &A, const TSG_Point &B, bool bPolar) { return( bPolar ? SG_Get_Distance_Polar(A, B) : SG_Get_Distance(A, B) ); }
//--------------------------------------------------------- bool CDirect_Georeferencing::On_Execute(void) { //----------------------------------------------------- if( !m_Georeferencer.Set_Transformation(Parameters, Get_NX(), Get_NY()) ) { return( false ); } //----------------------------------------------------- CSG_Grid *pDEM = Parameters("DEM" )->asGrid(); double zRef = Parameters("ZREF" )->asDouble(); bool bFlip = Parameters("ROW_ORDER")->asInt() == 1; //----------------------------------------------------- TSG_Grid_Resampling Resampling; switch( Parameters("RESAMPLING")->asInt() ) { default: Resampling = GRID_RESAMPLING_NearestNeighbour; break; case 1: Resampling = GRID_RESAMPLING_Bilinear; break; case 2: Resampling = GRID_RESAMPLING_BicubicSpline; break; case 3: Resampling = GRID_RESAMPLING_BSpline; break; } //----------------------------------------------------- TSG_Point p[4]; p[0] = m_Georeferencer.Image_to_World( 0, 0, zRef); p[1] = m_Georeferencer.Image_to_World(Get_NX(), 0, zRef); p[2] = m_Georeferencer.Image_to_World(Get_NX(), Get_NY(), zRef); p[3] = m_Georeferencer.Image_to_World( 0, Get_NY(), zRef); CSG_Rect r(p[0], p[1]); r.Union(p[2]); r.Union(p[3]); //----------------------------------------------------- CSG_Shapes *pShapes = Parameters("EXTENT")->asShapes(); if( pShapes ) { pShapes->Create(SHAPE_TYPE_Polygon, _TL("Extent")); pShapes->Add_Field(_TL("OID"), SG_DATATYPE_Int); CSG_Shape *pExtent = pShapes->Add_Shape(); pExtent->Add_Point(p[0]); pExtent->Add_Point(p[1]); pExtent->Add_Point(p[2]); pExtent->Add_Point(p[3]); } //----------------------------------------------------- double Cellsize = SG_Get_Distance(p[0], p[1]) / Get_NX(); CSG_Grid_System System(Cellsize, r); m_Grid_Target.Set_User_Defined(Get_Parameters("TARGET"), r, Get_NX()); if( !Dlg_Parameters("TARGET") ) { return( false ); } System = m_Grid_Target.Get_System(); if( !System.is_Valid() ) { return( false ); } //----------------------------------------------------- CSG_Parameter_Grid_List *pInput = Parameters("INPUT" )->asGridList(); CSG_Parameter_Grid_List *pOutput = Parameters("OUTPUT")->asGridList(); pOutput->Del_Items(); if( pInput->Get_Count() <= 0 ) { return( false ); } else { TSG_Data_Type Type; switch( Parameters("DATA_TYPE")->asInt() ) { case 0: Type = SG_DATATYPE_Byte; break; case 1: Type = SG_DATATYPE_Char; break; case 2: Type = SG_DATATYPE_Word; break; case 3: Type = SG_DATATYPE_Short; break; case 4: Type = SG_DATATYPE_DWord; break; case 5: Type = SG_DATATYPE_Int; break; case 6: Type = SG_DATATYPE_Float; break; case 7: Type = SG_DATATYPE_Double; break; default: Type = SG_DATATYPE_Undefined; break; } for(int i=0; i<pInput->Get_Count(); i++) { CSG_Grid *pGrid = SG_Create_Grid(System, Type != SG_DATATYPE_Undefined ? Type : pInput->asGrid(i)->Get_Type()); if( !pGrid || !pGrid->is_Valid() ) { if( pGrid ) { delete(pGrid); } return( false ); } pOutput->Add_Item(pGrid); pGrid->Set_Name(pInput->asGrid(i)->Get_Name()); } } //----------------------------------------------------- for(int y=0; y<System.Get_NY() && Set_Progress(y, System.Get_NY()); y++) { double py = System.Get_YMin() + y * System.Get_Cellsize(); #pragma omp parallel for for(int x=0; x<System.Get_NX(); x++) { double pz, px = System.Get_XMin() + x * System.Get_Cellsize(); if( !pDEM || !pDEM->Get_Value(px, py, pz) ) { pz = zRef; } TSG_Point p = m_Georeferencer.World_to_Image(px, py, pz); if( bFlip ) { p.y = (Get_NY() - 1) - p.y; } for(int i=0; i<pInput->Get_Count(); i++) { if( pInput->asGrid(i)->Get_Value(p.x, p.y, pz, Resampling) ) { pOutput->asGrid(i)->Set_Value(x, y, pz); } else { pOutput->asGrid(i)->Set_NoData(x, y); } } } } //----------------------------------------------------- return( true ); }
//--------------------------------------------------------- bool CSG_Network::_Add_Line(CSG_Shape *pLine, int ID) { int iEdge, iPoint, iCrossing; CSG_Shape *pEdge, *pCrossing; CSG_Shapes Crossings(SHAPE_TYPE_Point); //----------------------------------------------------- // 1. find crossings Crossings.Add_Field(SG_T("LINE_POINT") , SG_DATATYPE_Int); Crossings.Add_Field(SG_T("EDGE_ID") , SG_DATATYPE_Int); Crossings.Add_Field(SG_T("EDGE_POINT") , SG_DATATYPE_Int); Crossings.Add_Field(SG_T("EDGE_DIST") , SG_DATATYPE_Double); for(iEdge=0; iEdge<m_Edges.Get_Count(); iEdge++) { pEdge = m_Edges.Get_Shape(iEdge); if( pEdge->Intersects(pLine) ) { TSG_Point a = pEdge->Get_Point(0); for(int iEdge_Point=1; iEdge_Point<pEdge->Get_Point_Count(0); iEdge_Point++) { TSG_Point b = a; a = pEdge->Get_Point(iEdge_Point); TSG_Point A = pLine->Get_Point(0); for(iPoint=1; iPoint<pLine->Get_Point_Count(0); iPoint++) { TSG_Point C, B = A; A = pLine->Get_Point(iPoint); if( SG_Get_Crossing(C, A, B, a, b) ) { pCrossing = Crossings.Add_Shape(); pCrossing->Add_Point(C); pCrossing->Set_Value(0, iPoint); pCrossing->Set_Value(1, iEdge); pCrossing->Set_Value(2, iEdge_Point); pCrossing->Set_Value(3, SG_Get_Distance(C, b)); } } } } } //----------------------------------------------------- // 2. add new line's vertices Crossings.Set_Index(0, TABLE_INDEX_Ascending); pEdge = m_Edges.Add_Shape(); pEdge ->Set_Value(3, ID); for(iCrossing=0, iPoint=0; iCrossing<Crossings.Get_Count(); iCrossing++) { pCrossing = Crossings.Get_Shape_byIndex(iCrossing); while( iPoint < pCrossing->asInt(0) ) { pEdge->Add_Point(pLine->Get_Point(iPoint++)); } pEdge->Add_Point(pCrossing->Get_Point(0)); pEdge = m_Edges.Add_Shape(); pEdge ->Set_Value(3, ID); pEdge ->Add_Point(pCrossing->Get_Point(0)); } while( iPoint < pLine->Get_Point_Count(0) ) { pEdge->Add_Point(pLine->Get_Point(iPoint++)); } //----------------------------------------------------- // 3. split edges, if necessary Crossings.Set_Index(1, TABLE_INDEX_Descending, 2, TABLE_INDEX_Ascending, 3, TABLE_INDEX_Ascending); for(iCrossing=0; iCrossing<Crossings.Get_Count(); ) { pCrossing = Crossings.Get_Shape_byIndex(iCrossing); iEdge = pCrossing->asInt(1); pLine = m_Edges.Get_Shape(iEdge); ID = pLine->asInt(0); iPoint = 0; pEdge = m_Edges.Add_Shape(); pEdge ->Set_Value(3, pLine->asInt(3)); while( 1 ) { while( iPoint < pCrossing->asInt(2) ) { pEdge->Add_Point(pLine->Get_Point(iPoint++)); } pEdge->Add_Point(pCrossing->Get_Point(0)); if( ++iCrossing < Crossings.Get_Count() && iEdge == Crossings.Get_Shape_byIndex(iCrossing)->asInt(1) ) { pEdge = m_Edges.Add_Shape(); pEdge ->Set_Value(3, pLine->asInt(3)); pEdge->Add_Point(pCrossing->Get_Point(0)); pCrossing = Crossings.Get_Shape_byIndex(iCrossing); } else { if( iPoint < pLine->Get_Point_Count() ) { pEdge = m_Edges.Add_Shape(); pEdge ->Set_Value(3, pLine->asInt(3)); pEdge->Add_Point(pCrossing->Get_Point(0)); while( iPoint < pLine->Get_Point_Count() ) { pEdge->Add_Point(pLine->Get_Point(iPoint++)); } } break; } } m_Edges.Del_Shape(iEdge); } return( true ); }