std::unique_ptr<OGRLineString> create_linestring(const osmium::Way& way) { std::unique_ptr<OGRLineString> geom = m_factory.create_linestring(way); OGREnvelope env; geom->getEnvelope(&env); m_envelope.Merge(env); return geom; }
std::unique_ptr<OGRMultiPolygon> create_multipolygon(const osmium::Area& area) { std::unique_ptr<OGRMultiPolygon> geom = m_factory.create_multipolygon(area); OGREnvelope env; geom->getEnvelope(&env); m_envelope.Merge(env); return geom; }
std::unique_ptr<OGRPoint> create_point(const osmium::Node& node) { std::unique_ptr<OGRPoint> geom = m_factory.create_point(node); OGREnvelope env; geom->getEnvelope(&env); m_envelope.Merge(env); return geom; }
void CookieCutter::cut(OsmMapPtr cutterShapeMap, OsmMapPtr doughMap) { OGREnvelope env = cutterShapeMap->calculateBounds(); env.Merge(doughMap->calculateBounds()); // reproject the dough and cutter into the same planar projection. MapReprojector::reprojectToPlanar(doughMap, env); MapReprojector::reprojectToPlanar(cutterShapeMap, env); // create a complex geometry representing the alpha shape UnionPolygonsVisitor v; cutterShapeMap->visitRo(v); shared_ptr<Geometry> cutterShape = v.getUnion(); if (_outputBuffer != 0.0) { cutterShape.reset(cutterShape->buffer(_outputBuffer)); } if (cutterShape->getArea() == 0.0) { LOG_WARN("Cutter area is zero. Try increasing the buffer size or check the input."); } // free up a little RAM cutterShapeMap.reset(); // remove the cookie cutter portion from the "dough" // if crop is true, then the cookie cutter portion is kept and the "dough" is dropped. MapCropper::crop(doughMap, cutterShape, !_crop); // clean up any ugly bits left over SuperfluousWayRemover::removeWays(doughMap); SuperfluousNodeRemover::removeNodes(doughMap); }
OGREnvelope wxGISMap::GetFullExtent(void) { OGREnvelope res; for(size_t i = 0; i < m_Layers.size(); i++) //check if the spatial ref is same!!! res.Merge(*m_Layers[i]->GetEnvelope()); return res; }
void wxAxIdentifyView::OnMenu(wxCommandEvent& event) { wxTreeItemId TreeItemId = m_pTreeCtrl->GetSelection(); wxIdentifyTreeItemData* pData = (wxIdentifyTreeItemData*)m_pTreeCtrl->GetItemData(TreeItemId); if(pData == NULL) return; switch(event.GetId()) { case ID_WGMENU_FLASH: { if (pData->m_Geometry.IsOk()) { m_pMapView->AddFlashGeometry(pData->m_Geometry, GetDrawSymbol(pData->m_Geometry.GetType())); } else { wxTreeItemIdValue cookie; for ( wxTreeItemId item = m_pTreeCtrl->GetFirstChild(TreeItemId, cookie); item.IsOk(); item = m_pTreeCtrl->GetNextChild(TreeItemId, cookie) ) { pData = (wxIdentifyTreeItemData*)m_pTreeCtrl->GetItemData(item); if (pData) { m_pMapView->AddFlashGeometry(pData->m_Geometry, GetDrawSymbol(pData->m_Geometry.GetType())); } } } m_pMapView->StartFlashing(); } break; case ID_WGMENU_PAN: { wxGISGeometryArray Arr; if(pData->m_Geometry.IsOk()) { m_pMapView->AddFlashGeometry(pData->m_Geometry, GetDrawSymbol(pData->m_Geometry.GetType())); Arr.Add(pData->m_Geometry); } else { wxTreeItemIdValue cookie; for ( wxTreeItemId item = m_pTreeCtrl->GetFirstChild(TreeItemId, cookie); item.IsOk(); item = m_pTreeCtrl->GetNextChild(TreeItemId, cookie) ) { pData = (wxIdentifyTreeItemData*)m_pTreeCtrl->GetItemData(item); if(pData) { m_pMapView->AddFlashGeometry(pData->m_Geometry, GetDrawSymbol(pData->m_Geometry.GetType())); Arr.Add(pData->m_Geometry); } } } if(Arr.IsEmpty()) return; OGREnvelope Env; for(size_t i = 0; i < Arr.GetCount(); ++i) { OGREnvelope TempEnv = Arr[i].GetEnvelope(); Env.Merge(TempEnv); } OGREnvelope CurrentEnv = m_pMapView->GetCurrentExtent(); MoveEnvelope(CurrentEnv, Env); m_pMapView->Do(CurrentEnv); m_pMapView->StartFlashing(); } break; case ID_WGMENU_ZOOM: { wxGISGeometryArray Arr; if(pData->m_Geometry.IsOk()) { m_pMapView->AddFlashGeometry(pData->m_Geometry, GetDrawSymbol(pData->m_Geometry.GetType())); Arr.Add(pData->m_Geometry); } else { wxTreeItemIdValue cookie; for ( wxTreeItemId item = m_pTreeCtrl->GetFirstChild(TreeItemId, cookie); item.IsOk(); item = m_pTreeCtrl->GetNextChild(TreeItemId, cookie) ) { pData = (wxIdentifyTreeItemData*)m_pTreeCtrl->GetItemData(item); if(pData) { m_pMapView->AddFlashGeometry(pData->m_Geometry, GetDrawSymbol(pData->m_Geometry.GetType())); Arr.Add(pData->m_Geometry); } } } if(Arr.IsEmpty()) return; OGREnvelope Env; for(size_t i = 0; i < Arr.GetCount(); ++i) { OGREnvelope TempEnv = Arr[i].GetEnvelope(); Env.Merge(TempEnv); } m_pMapView->Do(Env); m_pMapView->StartFlashing(); } break; default: break; } }
OGRErr PDFWritableVectorDataset::SyncToDisk() { if (nLayers == 0 || !bModified) return OGRERR_NONE; bModified = FALSE; OGREnvelope sGlobalExtent; int bHasExtent = FALSE; for(int i=0;i<nLayers;i++) { OGREnvelope sExtent; if (papoLayers[i]->GetExtent(&sExtent) == OGRERR_NONE) { bHasExtent = TRUE; sGlobalExtent.Merge(sExtent); } } if (!bHasExtent || sGlobalExtent.MinX == sGlobalExtent.MaxX || sGlobalExtent.MinY == sGlobalExtent.MaxY) { CPLError(CE_Failure, CPLE_AppDefined, "Cannot compute spatial extent of features"); return OGRERR_FAILURE; } PDFCompressMethod eStreamCompressMethod = COMPRESS_DEFLATE; const char* pszStreamCompressMethod = CSLFetchNameValue(papszOptions, "STREAM_COMPRESS"); if (pszStreamCompressMethod) { if( EQUAL(pszStreamCompressMethod, "NONE") ) eStreamCompressMethod = COMPRESS_NONE; else if( EQUAL(pszStreamCompressMethod, "DEFLATE") ) eStreamCompressMethod = COMPRESS_DEFLATE; else { CPLError( CE_Warning, CPLE_NotSupported, "Unsupported value for STREAM_COMPRESS."); } } const char* pszGEO_ENCODING = CSLFetchNameValueDef(papszOptions, "GEO_ENCODING", "ISO32000"); double dfDPI = CPLAtof(CSLFetchNameValueDef(papszOptions, "DPI", "72")); if (dfDPI < 72.0) dfDPI = 72.0; const char* pszNEATLINE = CSLFetchNameValue(papszOptions, "NEATLINE"); int nMargin = atoi(CSLFetchNameValueDef(papszOptions, "MARGIN", "0")); PDFMargins sMargins; sMargins.nLeft = nMargin; sMargins.nRight = nMargin; sMargins.nTop = nMargin; sMargins.nBottom = nMargin; const char* pszLeftMargin = CSLFetchNameValue(papszOptions, "LEFT_MARGIN"); if (pszLeftMargin) sMargins.nLeft = atoi(pszLeftMargin); const char* pszRightMargin = CSLFetchNameValue(papszOptions, "RIGHT_MARGIN"); if (pszRightMargin) sMargins.nRight = atoi(pszRightMargin); const char* pszTopMargin = CSLFetchNameValue(papszOptions, "TOP_MARGIN"); if (pszTopMargin) sMargins.nTop = atoi(pszTopMargin); const char* pszBottomMargin = CSLFetchNameValue(papszOptions, "BOTTOM_MARGIN"); if (pszBottomMargin) sMargins.nBottom = atoi(pszBottomMargin); const char* pszExtraImages = CSLFetchNameValue(papszOptions, "EXTRA_IMAGES"); const char* pszExtraStream = CSLFetchNameValue(papszOptions, "EXTRA_STREAM"); const char* pszExtraLayerName = CSLFetchNameValue(papszOptions, "EXTRA_LAYER_NAME"); const char* pszOGRDisplayField = CSLFetchNameValue(papszOptions, "OGR_DISPLAY_FIELD"); const char* pszOGRDisplayLayerNames = CSLFetchNameValue(papszOptions, "OGR_DISPLAY_LAYER_NAMES"); int bWriteOGRAttributes = CSLFetchBoolean(papszOptions, "OGR_WRITE_ATTRIBUTES", TRUE); const char* pszOGRLinkField = CSLFetchNameValue(papszOptions, "OGR_LINK_FIELD"); const char* pszOffLayers = CSLFetchNameValue(papszOptions, "OFF_LAYERS"); const char* pszExclusiveLayers = CSLFetchNameValue(papszOptions, "EXCLUSIVE_LAYERS"); const char* pszJavascript = CSLFetchNameValue(papszOptions, "JAVASCRIPT"); const char* pszJavascriptFile = CSLFetchNameValue(papszOptions, "JAVASCRIPT_FILE"); /* -------------------------------------------------------------------- */ /* Create file. */ /* -------------------------------------------------------------------- */ VSILFILE* fp = VSIFOpenL(GetDescription(), "wb"); if( fp == NULL ) { CPLError( CE_Failure, CPLE_OpenFailed, "Unable to create PDF file %s.\n", GetDescription() ); return OGRERR_FAILURE; } GDALPDFWriter oWriter(fp); double dfRatio = (sGlobalExtent.MaxY - sGlobalExtent.MinY) / (sGlobalExtent.MaxX - sGlobalExtent.MinX); int nWidth, nHeight; if (dfRatio < 1) { nWidth = 1024; nHeight = nWidth * dfRatio; } else { nHeight = 1024; nWidth = nHeight / dfRatio; } GDALDataset* poSrcDS = MEMDataset::Create( "MEM:::", nWidth, nHeight, 0, GDT_Byte, NULL ); double adfGeoTransform[6]; adfGeoTransform[0] = sGlobalExtent.MinX; adfGeoTransform[1] = (sGlobalExtent.MaxX - sGlobalExtent.MinX) / nWidth; adfGeoTransform[2] = 0; adfGeoTransform[3] = sGlobalExtent.MaxY; adfGeoTransform[4] = 0; adfGeoTransform[5] = - (sGlobalExtent.MaxY - sGlobalExtent.MinY) / nHeight; poSrcDS->SetGeoTransform(adfGeoTransform); OGRSpatialReference* poSRS = papoLayers[0]->GetSpatialRef(); if (poSRS) { char* pszWKT = NULL; poSRS->exportToWkt(&pszWKT); poSrcDS->SetProjection(pszWKT); CPLFree(pszWKT); } oWriter.SetInfo(poSrcDS, papszOptions); oWriter.StartPage(poSrcDS, dfDPI, pszGEO_ENCODING, pszNEATLINE, &sMargins, eStreamCompressMethod, bWriteOGRAttributes); int iObj = 0; char** papszLayerNames = CSLTokenizeString2(pszOGRDisplayLayerNames,",",0); for(int i=0;i<nLayers;i++) { CPLString osLayerName; if (CSLCount(papszLayerNames) < nLayers) osLayerName = papoLayers[i]->GetName(); else osLayerName = papszLayerNames[i]; oWriter.WriteOGRLayer((OGRDataSourceH)this, i, pszOGRDisplayField, pszOGRLinkField, osLayerName, bWriteOGRAttributes, iObj); } CSLDestroy(papszLayerNames); oWriter.EndPage(pszExtraImages, pszExtraStream, pszExtraLayerName, pszOffLayers, pszExclusiveLayers); if (pszJavascript) oWriter.WriteJavascript(pszJavascript); else if (pszJavascriptFile) oWriter.WriteJavascriptFile(pszJavascriptFile); oWriter.Close(); delete poSrcDS; return OGRERR_NONE; }
void wxGISMapView::AddLayer(wxGISLayer* pLayer) { IDisplayTransformation* pDisplayTransformation = pGISScreenDisplay->GetDisplayTransformation(); if(pDisplayTransformation->GetSpatialReference() == NULL) { OGRSpatialReference* pSpaRef = pLayer->GetSpatialReference(); if(pSpaRef) pDisplayTransformation->SetSpatialReference(pSpaRef); else { OGREnvelope* pEnv = pLayer->GetEnvelope(); if(pEnv) { if(pEnv->MaxX <= 180 && pEnv->MaxY <= 90 && pEnv->MinX >= -180 && pEnv->MinY >= -90) { OGRSpatialReference* pSpaRef = new OGRSpatialReference(); pSpaRef->SetWellKnownGeogCS("WGS84"); pDisplayTransformation->SetSpatialReference(pSpaRef); } } } } OGREnvelope* pEnv = pLayer->GetEnvelope(); if(pEnv == NULL) return; OGRSpatialReference* pSpaRef = pLayer->GetSpatialReference(); if(pSpaRef && pDisplayTransformation->GetSpatialReference()) { if(!pDisplayTransformation->GetSpatialReference()->IsSame(pSpaRef)) { OGRCoordinateTransformation *poCT = OGRCreateCoordinateTransformation( pSpaRef, pDisplayTransformation->GetSpatialReference() ); poCT->Transform(1, &pEnv->MaxX, &pEnv->MaxY); poCT->Transform(1, &pEnv->MinX, &pEnv->MinY); } } if(!pDisplayTransformation->IsBoundsSet()) pDisplayTransformation->SetBounds(*pEnv); else { OGREnvelope Bounds = pDisplayTransformation->GetBounds(); Bounds.Merge(*pEnv); pDisplayTransformation->SetBounds(Bounds); } //caching if(pLayer->GetCached()) { pLayer->SetCacheID(pGISScreenDisplay->AddCache()); } else { if(m_Layers.size() > 0 && m_Layers[m_Layers.size() - 1]->GetCached()) pLayer->SetCacheID(pGISScreenDisplay->AddCache()); else pLayer->SetCacheID(pGISScreenDisplay->GetLastCacheID()); } wxGISMap::AddLayer(pLayer); }