GNMGFID GNMGenericNetwork::FindNearestPoint(const OGRPoint* poPoint, const std::vector<OGRLayer*>& paPointLayers, double dfTolerance) { VALIDATE_POINTER1(poPoint, "GNMGenericNetwork::FindNearestPoint", -1); double dfMinX = poPoint->getX() - dfTolerance; double dfMinY = poPoint->getY() - dfTolerance; double dfMaxX = poPoint->getX() + dfTolerance; double dfMaxY = poPoint->getY() + dfTolerance; OGRFeature *poFeature; for(size_t i = 0; i < paPointLayers.size(); ++i) { OGRLayer *poLayer = paPointLayers[i]; poLayer->SetSpatialFilterRect(dfMinX, dfMinY, dfMaxX, dfMaxY); poLayer->ResetReading(); while((poFeature = poLayer->GetNextFeature()) != NULL) { GNMGFID nRetFID = poFeature->GetFieldAsGNMGFID(GNM_SYSFIELD_GFID); OGRFeature::DestroyFeature(poFeature); return nRetFID; } } return -1; }
bool VectorLayer::render(HDC hDC, double scale, double dWorldOriginX, double dWorldOriginY) { Timer * timer = new Timer(); timer->start(); OGRLayer *poLayer; poLayer = dataSource->GetLayer(0); poLayer->SetSpatialFilterRect(dWorldOriginX, dWorldOriginY - height / scale, dWorldOriginX + width / scale, dWorldOriginY); OGRFeature *poFeature; poLayer->ResetReading(); HGDIOBJ oldObject = SelectObject(hDC, GetStockObject(BLACK_BRUSH)); while( (poFeature = poLayer->GetNextFeature()) != NULL ) { OGRGeometry *poGeometry; poGeometry = poFeature->GetGeometryRef(); if( poGeometry != NULL) { //OGRwkbGeometryType type = wkbFlatten(poGeometry->getGeometryType()); OGRwkbGeometryType type = poGeometry->getGeometryType(); if (type == wkbPoint ) { OGRPoint *poPoint = static_cast<OGRPoint *>(poGeometry); } else if (type == wkbLineString) { OGRLineString *poLineString = static_cast<OGRLineString *>(poGeometry); int numPoints = poLineString->getNumPoints(); POINT * points = (POINT *)CPLMalloc(sizeof(POINT) * numPoints); if (points == NULL) return false; for (int i = 0; i < numPoints; ++i) { points[i].x = (LONG)((poLineString->getX(i) - dWorldOriginX) * scale + 0.5); points[i].y = (LONG)((dWorldOriginY - poLineString->getY(i)) * scale + 0.5); } Polyline(hDC, points, numPoints); free(points); } OGRFeature::DestroyFeature( poFeature ); } } // Select old object back into dc (one can not delete an object if it is in the dc) SelectObject(hDC, oldObject); timer->stop(); double timeTaken = timer->diffTime(); MessageBox(0,doubleToString(timeTaken).c_str(),L"Time to render",MB_OK); return true; }