void wxGISSimpleCircleSymbol::Draw(const wxGISGeometry &Geometry, int nLevel) { if (!Geometry.IsOk() || !m_pDisplay) return; OGRwkbGeometryType eGeomType = wkbFlatten(Geometry.GetType()); if (eGeomType != wkbMultiPoint) return; OGREnvelope Env; OGRGeometry *pGeom = Geometry; OGRMultiPoint* pMPT = (OGRMultiPoint*)pGeom; OGRPoint* pCenterPt = (OGRPoint*)pMPT->getGeometryRef(0); OGRPoint* pOriginPt = (OGRPoint*)pMPT->getGeometryRef(1); double dfRadius = sqrt((pCenterPt->getX() - pOriginPt->getX())*(pCenterPt->getX() - pOriginPt->getX()) + (pCenterPt->getY() - pOriginPt->getY())*(pCenterPt->getY() - pOriginPt->getY())); Env.MaxX = pCenterPt->getX() + dfRadius; Env.MinX = pCenterPt->getX() - dfRadius; Env.MaxY = pCenterPt->getY() + dfRadius; Env.MinY = pCenterPt->getY() - dfRadius; if (!m_pDisplay->CanDraw(Env)) return; wxCriticalSectionLocker lock(m_pDisplay->GetLock()); if (!m_pDisplay->CheckDrawAsPoint(Env, m_pLineSymbol->GetWidth())) { if (!m_pDisplay->DrawCircle(pCenterPt->getX(), pCenterPt->getY(), 0, 0, dfRadius)) { return; } if (m_Color.Alpha() > 0) { switch (m_eFillRule) { case enumGISFillRuleWinding: m_pDisplay->SetFillRule(CAIRO_FILL_RULE_WINDING); break; case enumGISFillRuleOdd: m_pDisplay->SetFillRule(CAIRO_FILL_RULE_EVEN_ODD); break; } m_pDisplay->SetColor(m_Color); m_pDisplay->FillPreserve(); } } m_pLineSymbol->SetStyleToDisplay(); m_pDisplay->Stroke(); }
void wxGISSimpleMarkerSymbol::Draw(const wxGISGeometry &Geometry, int nLevel) { if(!Geometry.IsOk() ||!m_pDisplay) return; OGRwkbGeometryType eGeomType = wkbFlatten(Geometry.GetType()); if(eGeomType != wkbPoint && eGeomType != wkbMultiPoint) return; OGREnvelope Env = Geometry.GetEnvelope(); if(!m_pDisplay->CanDraw(Env)) return; OGRGeometry *pGeom = Geometry; if(eGeomType == wkbMultiPoint) { OGRGeometryCollection* pOGRGeometryCollection = (OGRGeometryCollection*)pGeom; for(int i = 0; i < pOGRGeometryCollection->getNumGeometries(); ++i) Draw(wxGISGeometry(pOGRGeometryCollection->getGeometryRef(i), false)); return; } wxCriticalSectionLocker lock(m_pDisplay->GetLock()); OGRPoint* pPoint = (OGRPoint*)pGeom; if(m_dfOutlineSize) { if(!m_pDisplay->DrawPointFast(pPoint->getX(), pPoint->getY())) { return; } m_pDisplay->SetColor(m_OutlineColor); m_pDisplay->SetLineWidth( m_dfSize + m_dfOutlineSize + m_dfOutlineSize); m_pDisplay->Stroke(); } if(!m_pDisplay->DrawPointFast(pPoint->getX(), pPoint->getY())) { return; } m_pDisplay->SetColor(m_Color); m_pDisplay->SetLineWidth( m_dfSize ); m_pDisplay->SetLineCap(CAIRO_LINE_CAP_ROUND); m_pDisplay->Stroke(); }
void wxGISSimpleEllipseSymbol::Draw(const wxGISGeometry &Geometry, int nLevel) { if (!Geometry.IsOk() || !m_pDisplay) return; OGRwkbGeometryType eGeomType = wkbFlatten(Geometry.GetType()); if (eGeomType != wkbPolygon) return; OGREnvelope Env = Geometry.GetEnvelope(); if (!m_pDisplay->CanDraw(Env)) return; wxCriticalSectionLocker lock(m_pDisplay->GetLock()); if (!m_pDisplay->CheckDrawAsPoint(Env, m_pLineSymbol->GetWidth())) { if (!m_pDisplay->DrawEllipse(Env.MinX, Env.MinY, 0, 0, Env.MaxX - Env.MinX, Env.MaxY - Env.MinY)) { return; } if (m_Color.Alpha() > 0) { switch (m_eFillRule) { case enumGISFillRuleWinding: m_pDisplay->SetFillRule(CAIRO_FILL_RULE_WINDING); break; case enumGISFillRuleOdd: m_pDisplay->SetFillRule(CAIRO_FILL_RULE_EVEN_ODD); break; } m_pDisplay->SetColor(m_Color); m_pDisplay->FillPreserve(); } } m_pLineSymbol->SetStyleToDisplay(); m_pDisplay->Stroke(); }
void wxGISMapView::DrawGeometry(const wxGISGeometry &Geometry, WXGISRGBA stFillColour, WXGISRGBA stLineColour, double dfLineWidth) { wxCHECK_RET(Geometry.IsOk(), wxT("Input geometry is not valid")); OGRwkbGeometryType type = wkbFlatten(Geometry.GetType()); switch(type) { case wkbPoint: case wkbMultiPoint: m_pGISDisplay->SetColor(enumGISDrawStylePoint, stLineColour); m_pGISDisplay->SetColor(enumGISDrawStyleOutline, stLineColour); m_pGISDisplay->SetColor(enumGISDrawStyleFill, stFillColour); m_pGISDisplay->SetLineCap(CAIRO_LINE_CAP_ROUND); m_pGISDisplay->SetLineWidth(dfLineWidth); m_pGISDisplay->SetPointRadius(2.0); break; case wkbLineString: case wkbLinearRing: case wkbMultiLineString: m_pGISDisplay->SetColor(enumGISDrawStylePoint, stFillColour); m_pGISDisplay->SetColor(enumGISDrawStyleOutline, stFillColour); m_pGISDisplay->SetColor(enumGISDrawStyleFill, stFillColour); m_pGISDisplay->SetLineCap(CAIRO_LINE_CAP_BUTT); m_pGISDisplay->SetLineWidth(2.0); break; case wkbMultiPolygon: case wkbPolygon: m_pGISDisplay->SetColor(enumGISDrawStyleOutline, stLineColour); m_pGISDisplay->SetColor(enumGISDrawStyleFill, stFillColour); m_pGISDisplay->SetLineCap(CAIRO_LINE_CAP_BUTT); m_pGISDisplay->SetLineWidth(dfLineWidth); break; case wkbGeometryCollection: break; default: case wkbUnknown: case wkbNone: break; } m_pGISDisplay->DrawGeometry( Geometry ); }
void wxGISSimpleCollectionSymbol::Draw(const wxGISGeometry &Geometry, int nLevel) { if(!Geometry.IsOk() ||!m_pDisplay) return; if (!Geometry.IsOk()) return; switch (wkbFlatten(Geometry.GetType())) { case wkbMultiPoint: case wkbPoint: m_pMarkerSymbol->Draw(Geometry); break; case wkbMultiPolygon: case wkbPolygon: m_pFillSymbol->Draw(Geometry); break; case wkbMultiLineString: case wkbLineString: m_pLineSymbol->Draw(Geometry); break; case wkbGeometryCollection: { OGRGeometryCollection* pOGRGeometryCollection = (OGRGeometryCollection*)Geometry.operator OGRGeometry *(); for (int i = 0; i < pOGRGeometryCollection->getNumGeometries(); ++i) { wxGISGeometry CollectionGeom(pOGRGeometryCollection->getGeometryRef(i), false); Draw(CollectionGeom, nLevel); } } break; case wkbLinearRing: case wkbUnknown: case wkbNone: default: break; } }
void wxGISSimpleLineSymbol::Draw(const wxGISGeometry &Geometry, int nLevel) { if(!Geometry.IsOk() || !m_pDisplay) return; OGRwkbGeometryType eGeomType = wkbFlatten(Geometry.GetType()); if(eGeomType != wkbLineString && eGeomType != wkbLinearRing && eGeomType != wkbMultiLineString) return; OGREnvelope Env = Geometry.GetEnvelope(); if(!m_pDisplay->CanDraw(Env)) return; wxCriticalSectionLocker lock(m_pDisplay->GetLock()); OGRGeometry *pGeom = Geometry; if (eGeomType == wkbMultiLineString) { OGRGeometryCollection* pOGRGeometryCollection = (OGRGeometryCollection*)pGeom; for(int i = 0; i < pOGRGeometryCollection->getNumGeometries(); ++i) Draw(wxGISGeometry(pOGRGeometryCollection->getGeometryRef(i), false)); } else { OGRLineString* pLine = (OGRLineString*)pGeom; int nPointCount = pLine->getNumPoints(); if (!m_pDisplay->CheckDrawAsPoint(Env, m_dfWidth, false, 0, 0, false)) { if(!DrawPreserved(pLine)) return; SetStyleToDisplay(); } else { SetLimitStyleToDisplay(); } m_pDisplay->Stroke(); } }
void wxAxIdentifyView::Identify(wxGISMapView* pMapView, wxGISGeometry &GeometryBounds) { m_pMapView = pMapView; //if(!m_pMapView)//TODO: add/remove layer map events connection point //{ // wxWindow* pWnd = m_pApp->GetRegisteredWindowByType(wxCLASSINFO(wxGISMapView)); // m_pMapView = dynamic_cast<wxGISMapView*>(pWnd); //} if(!m_pMapView) return; wxBusyCursor wait; wxGISSpatialReference SpaRef = m_pMapView->GetSpatialReference(); double dfWidth(3), dfHeight(3); wxGISAppConfig oConfig = GetConfig(); if(oConfig.IsOk()) { dfWidth = oConfig.ReadDouble(enumGISHKCU, wxString(wxT("wxGISCommon/identify/search_width")), dfWidth); dfHeight = oConfig.ReadDouble(enumGISHKCU, wxString(wxT("wxGISCommon/identify/search_height")), dfHeight); } if(m_pMapView->GetDisplay()) { m_pMapView->GetDisplay()->DC2WorldDist(&dfWidth, &dfHeight); dfWidth = std::fabs(dfWidth); dfHeight = std::fabs(dfHeight); } OGREnvelope Env = GeometryBounds.GetEnvelope(); bool bChanged(false); //if we got a small envelope or it's a point if(Env.MaxX - Env.MinX < dfWidth) { Env.MinX -= dfWidth; Env.MaxX += dfWidth; bChanged = true; } if(Env.MaxY - Env.MinY < dfHeight) { Env.MinY -= dfHeight; Env.MaxY += dfHeight; bChanged = true; } if(bChanged) { GeometryBounds = EnvelopeToGeometry(Env, SpaRef); } OGRPoint *pt = GeometryBounds.GetCentroid(); int nSelection = m_LayerChoice->GetSelection(); wxVector<FILLTREEDATA> data; switch(nSelection) { case 0://get top layer //TODO: check group layer for (size_t i = m_pMapView->GetLayerCount() - 1; i >= 0; --i) { wxGISLayer* const pLayer = m_pMapView->GetLayerByIndex(i); if (NULL == pLayer) { continue; } else if (pLayer->GetType() == enumGISFeatureDataset || pLayer->GetType() == enumGISRasterDataset) { FILLTREEDATA stdata = { pLayer, wxNullSpatialTreeCursor }; data.push_back(stdata); break; } } break; case 1://get all layers //TODO: check group layer for(size_t i = 0; i < m_pMapView->GetLayerCount(); ++i) { wxGISLayer* const pLayer = m_pMapView->GetLayerByIndex(i); if (NULL == pLayer) { continue; } else if (pLayer->GetType() == enumGISFeatureDataset || pLayer->GetType() == enumGISRasterDataset) { FILLTREEDATA stdata = { pLayer, wxNullSpatialTreeCursor }; data.push_back(stdata); } } break; default: return; }; for(size_t i = 0; i < data.size(); ++i) { wxGISEnumDatasetType eType = data[i].pLayer->GetType(); switch(eType) { case enumGISFeatureDataset: { wxGISFeatureLayer* pFLayer = dynamic_cast<wxGISFeatureLayer*>(data[i].pLayer); if(!pFLayer) return; wxGISSpatialTreeCursor Cursor = pFLayer->Idetify(GeometryBounds); wxGISSpatialTreeCursor::const_iterator iter; for(iter = Cursor.begin(); iter != Cursor.end(); ++iter) { wxGISSpatialTreeData *current = *iter; if(current) { //flash on map wxGISGeometry Geom = current->GetGeometry(); if (Geom.IsOk()) { wxGISSymbol* pSymbol = GetDrawSymbol(Geom.GetType()); m_pMapView->AddFlashGeometry(Geom, pSymbol); } } } m_pMapView->StartFlashing(); data[i].Cursor = Cursor; } break; default: break; }; } //fill IdentifyDlg m_pFeatureDetailsPanel->Clear(true); m_pFeatureDetailsPanel->SetClickPositionText(pt); FillTree(data); OGRGeometryFactory::destroyGeometry(pt); }
bool wxGISDrawingLayer::AddShape(const wxGISGeometry &Geom, wxGISEnumShapeType eType) { if (!Geom.IsOk()) return false; wxGISSymbol* pSymbol = NULL; wxString sShapeName; switch (eType) { case enumGISShapeTypeRectangle: sShapeName = wxString::Format(_("Rectangle %ld"), m_aoShapes.size() + 1); pSymbol = wxStaticCast(m_pFillSymbol->Clone(), wxGISSymbol); break; case enumGISShapeTypePolygon: sShapeName = wxString::Format(_("Polygon %ld"), m_aoShapes.size() + 1); pSymbol = wxStaticCast(m_pFillSymbol->Clone(), wxGISSymbol); break; case enumGISShapeTypeCircle: sShapeName = wxString::Format(_("Circle %ld"), m_aoShapes.size() + 1); pSymbol = wxStaticCast(m_pCircleSymbol->Clone(), wxGISSymbol); break; case enumGISShapeTypeEllipse: sShapeName = wxString::Format(_("Ellipse %ld"), m_aoShapes.size() + 1); pSymbol = wxStaticCast(m_pEllipseSymbol->Clone(), wxGISSymbol); break; case enumGISShapeTypeLine: sShapeName = wxString::Format(_("Line %ld"), m_aoShapes.size() + 1); pSymbol = wxStaticCast(m_pLineSymbol->Clone(), wxGISSymbol); break; #ifdef wxGIS_USE_SPLINE case enumGISShapeTypeCurve: sShapeName = wxString::Format(_("Curve %ld"), m_aoShapes.size() + 1); pSymbol = wxStaticCast(m_pLineSymbol->Clone(), wxGISSymbol); break; #endif //wxGIS_USE_SPLINE case enumGISShapeTypeFreeHand: sShapeName = wxString::Format(_("FreeHand %ld"), m_aoShapes.size() + 1); pSymbol = wxStaticCast(m_pLineSymbol->Clone(), wxGISSymbol); break; case enumGISShapeTypeMarker: sShapeName = wxString::Format(_("Marker %ld"), m_aoShapes.size() + 1); pSymbol = wxStaticCast(m_pMarkerSymbol->Clone(), wxGISSymbol); break; default: sShapeName = wxString::Format(_("Shape %ld"), m_aoShapes.size() + 1); pSymbol = wxStaticCast(m_pFillSymbol->Clone(), wxGISSymbol); break; }; wxGISShape * pNewShape = new wxGISShape(sShapeName, Geom, eType, pSymbol); m_aoShapes.push_back(pNewShape); if (m_oLayerExtent.IsInit()) { m_oLayerExtent.Merge(pNewShape->GetBounds()); } else { m_oLayerExtent = pNewShape->GetBounds(); } pNewShape->Draw(m_pDisplay); wxMxMapViewEvent wxMxMapViewEvent_(wxMXMAP_LAYER_CHANGED, GetId()); AddEvent(wxMxMapViewEvent_); return true; }
void wxGISSimpleFillSymbol::Draw(const wxGISGeometry &Geometry, int nLevel) { if(!Geometry.IsOk() || !m_pDisplay) return; OGRwkbGeometryType eGeomType = wkbFlatten(Geometry.GetType()); if(eGeomType != wkbPolygon && eGeomType != wkbMultiPolygon) return; OGREnvelope Env = Geometry.GetEnvelope(); if(!m_pDisplay->CanDraw(Env)) return; wxCriticalSectionLocker lock(m_pDisplay->GetLock()); if(!m_pDisplay->CheckDrawAsPoint(Env, m_pLineSymbol->GetWidth())) { OGRGeometry *pGeom = Geometry; if(eGeomType == wkbMultiPolygon) { OGRGeometryCollection* pOGRGeometryCollection = (OGRGeometryCollection*)pGeom; for(int i = 0; i < pOGRGeometryCollection->getNumGeometries(); ++i) Draw(wxGISGeometry(pOGRGeometryCollection->getGeometryRef(i), false)); return; } OGRPolygon* pPolygon = (OGRPolygon*)pGeom; const OGRLinearRing *pRing = pPolygon->getExteriorRing(); if(!m_pLineSymbol->DrawPreserved((OGRLineString*)pRing, true)) { return; } int nNumInteriorRings = pPolygon->getNumInteriorRings(); for(int nPart = 0; nPart < nNumInteriorRings; ++nPart) { pRing = pPolygon->getInteriorRing(nPart); OGREnvelope IntEnv; pRing->getEnvelope(&IntEnv); if(!m_pDisplay->CheckDrawAsPoint(IntEnv, m_pLineSymbol->GetWidth())) { m_pLineSymbol->DrawPreserved((OGRLineString*)pRing, true); } } if(m_Color.Alpha() > 0) { switch(m_eFillRule) { case enumGISFillRuleWinding: m_pDisplay->SetFillRule( CAIRO_FILL_RULE_WINDING ); break; case enumGISFillRuleOdd: m_pDisplay->SetFillRule( CAIRO_FILL_RULE_EVEN_ODD ); break; } m_pDisplay->SetColor(m_Color); m_pDisplay->FillPreserve(); } m_pLineSymbol->SetStyleToDisplay(); } else { m_pLineSymbol->SetLimitStyleToDisplay(); } m_pDisplay->Stroke(); }